How do you detect if a player has typed a certain player's Name?
1 replies, posted
Hello, I am putting my gLua Beginner skills to test and making a ULX Copy thing. I was wondering how would I detect if an Admin does something in chat?
Example:
!kick NAME
How would the Server know who to kick? How would it know the player? Or any string, really.
[lua]
hook.Add("PlayerSay", "name_detect", function(ply, text)
if not string.sub(text, 1, 5) == "!kick" then return end -- make sure first 5 letters are "!kick"
for k, v in pairs(player.GetAll()) do -- loop around players
if string.sub(text, 7) == v:Name() then -- check if the second argument is the players name
v:Kick("Fuck You") -- kick them
end
end
end)
[/lua]
have a look at the string library
[URL="http://wiki.garrysmod.com/page/Category:string"]http://wiki.garrysmod.com/page/Category:string[/URL]
Sorry, you need to Log In to post a reply to this thread.