Forum

> > CS2D > Scripts > table.remove giving error?
Forums overviewCS2D overview Scripts overviewLog in to reply

English table.remove giving error?

2 replies
To the start Previous 1 Next To the start

old table.remove giving error?

Louie
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
OWNER = {140639}
ADMIN = {}
MOD = {}
MEMBER = {}
VIP = {}

function ismember(id,member)
     for none, usgn in pairs(_G[member]) do
          if (usgn == player(id, "usgn")) then
               return true
          end
     end
     
     return false
end

addhook("say","saycmds")
function saycmds(id,txt)
  if txt:sub(1,1) == "!" then
-- >>Set Player Ranks<<
-- Make/Remove VIP
      if txt:sub(2,7) == "vipadd" and (ismember(id,"OWNER") or ismember(id,"ADMIN") or ismember(id,"MOD")) then
         local vipid = txt:sub(9,#txt)
         table.insert(VIP,"..player(vipid,'usgn')..")
         msg2(id,"©000255000You have made "..player(vipid,'name').." a VIP!")
         return 1
   elseif txt:sub(2,6) == "revip" and (ismember(id,"OWNER") or ismember(id,"ADMIN") or ismember(id,"MOD")) then
         local rvipid = txt:sub(8,#txt)
         table.remove(VIP,"..player(rvipid,'usgn')..")
         msg2(id,"©000255000You removed "..player(vipid,'name').." as VIP!")
         return 1
   
      end
  end
end
So the !vipadd is working but the !revip isn't working its giving an error:bad argument #2 to 'remove' (number expected, got string) why is it giving an error like that i didn't get any errors in the table.insert thing ,help please

old Re: table.remove giving error?

The Gajos
BANNED Off Offline

Quote
> NOTE: If you want to know, VIPs that you add using this command will no longer have this rank after restarting the server.
I still don't know why you declared (VIP,"..player(vipid,'usgn')..") in string. The output will be ..player(vipid,'usgn')... I have changed it.
This CODE should work, btw. isn't tested >


The table.remove function removes (and returns) an element from a given position in an array, moving down other elements to close space and decrementing the size of the array. When called without a position, it removes the last element of the array.
So to your script I prepared a special function that will handle your script.
edited 1×, last 25.02.15 04:11:13 pm

old Re: table.remove giving error?

Louie
User Off Offline

Quote
@user The Gajos: Thx i will test it
EDIT: but i have another simple question how do i display a table and its values,like when a player says !tablevip then a table containing all the USGN ids of VIP rank will be shown to that player? i tried msg2(id,"VIP") it ended up showing VIP i tried print(VIP) but i get an error something like:expected a string got table.
edited 1×, last 26.02.15 12:32:56 am
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview