How could I target players with chat commands? similar to how ulx does it with teleporting, kicking and etc.
something like this for grabbing a player by their name:
[lua]
local function by_name( str )
if not str or str == "" then return false end
str = string.lower( tostring(str) )
local t = {}
for k,v in pairs(player.GetAll()) do
if string.find( string.lower( v:Nick() ), str ) then
t[ #t + 1 ] = v
end
end
return #t > 0 and t or false
end[/lua]
Use [url=http://wiki.garrysmod.com/page/GM/PlayerSay]PlayerSay[/url] for doing stuff based on chat.
Can I do something where it has to be /target then the players name for the function to target the player?
clearify pls
[QUOTE=DeadShotKillz;46671792]Can I do something where it has to be /target then the players name for the function to target the player?[/QUOTE]
Yes, you can.
Make to check if first string is /target and then get the 2 string and and try .//Shadow} example finding players by name.
[url=https://github.com/meharryp/gm-ezcommand]Shameless self promotion[/url]
I wrote this a while back to help with chat commands.
I made this for a project I was working on. You could shrink it down to one function pretty easily.
[url]https://gist.github.com/fghdx/a67dcdd70e0418ce3d4f[/url]
Sorry, you need to Log In to post a reply to this thread.