• player search function
    2 replies, posted
Im making a admin mod so when i just etc. the kick function it searches for the player i entered, but heres a exemple of the problem i get. Lets say i have 5 people on the server. I type "/Kick John Dont like you" it will print in the chat 4 times, instead of dont print it at all. I tried to use table.HasValue but then the nick needs to be exacly. [PHP]function Kick(ply, text) local Array = string.Explode( " ", text ); if Array[1] == "/kick" && IsGamewebAdmin(ply) == true then for k , t in ipairs(player.GetAll()) do if string.find(string.lower(t:Nick()) , string.lower(Array[2])) then WriteToLog( ply:GetName() .." kicked: ".. t:GetName() ); table.remove( Array, 1) table.remove( Array, 2) t:Kick(string.Implode(" ", Array)) else ply:PrintMessage( HUD_PRINTTALK, "Player name wasnt valid!"); end end return false end end hook.Add( "PlayerSay", "Kick", Kick )[/PHP] what code should i use to fix this. Best Regards
Try this. With your script during the loop through the player list, every time that the player's name isn't the same as the one that you want to kick it prints to your chat. You want it to do that at the end of the loop so that it doesn't spam your chat. [lua] function Kick(ply, text) local Array = string.Explode( " ", text ); if Array[1] == "/kick" && IsGamewebAdmin(ply) == true then for k , t in ipairs(player.GetAll()) do if string.find(string.lower(t:Nick()) , string.lower(Array[2])) then WriteToLog( ply:GetName() .." kicked: ".. t:GetName() ); table.remove( Array, 1) table.remove( Array, 2) t:Kick(string.Implode(" ", Array)) local plykicked = true end end if not plykicked then ply:PrintMessage( HUD_PRINTTALK, "Player name wasnt valid!") plykicked = false end end return false end hook.Add( "PlayerSay", "Kick", Kick ) [/lua]
yeah i noticed that but i didnt now how to solve it. Thank you
Sorry, you need to Log In to post a reply to this thread.