I have a chat command in which the player has to supply another as an argument and I want to be able to take the argument and compare it to a table/list of current players on the server, so that I can make sure the player is "valid". Any ideas? I was going to do the following but I know [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/player/GetHumans]player.GetHumans[/url] returns a table like this: 1 = [Player][1][Drakehawke]. I didn't know how to only retrieve the player's nick.
[CODE]
function ValidPly( ply )
local tbl = player.GetHumans()
if tbl[string.match( ply, "^.*$" )] then
return true
else
return false
end
end
[/CODE]
[QUOTE=MexicanR;50164985]I didn't know how to only retrieve the player's nick.[/QUOTE]
[CODE]
local function GetNickNames()
local tab = {}
for k,v in pairs( player.GetHumans() ) do
tab[v:Nick()] = true
end
return tab
end
local function ValidPly( ply )
local tbl = GetNickNames()
if tbl[tostring( ply )] then -- I guess you could try looping through the table doing string.find if you're intending to check all the keys of the table
return true
else
return false
end
end
[/CODE]
[QUOTE=MPan1;50165055]stuff[/QUOTE]
Man, you've been the first one to answer [B]ALL[/B] of my posts tonight.
[QUOTE=MexicanR;50165075]Man, you've been the first one to answer [B]ALL[/B] of my posts tonight.[/QUOTE]
Mostly with bad answers that probably won't work though :v:
Sorry, you need to Log In to post a reply to this thread.