• Kicking (Using a search)
    3 replies, posted
What is wrong with this code? [code]function SGNKick(ply,cmd,args) if ply:IsAdmin() then if args[1] != nil then local found = 0 local re = args[2] or "Kicked"; for _,v in pairs(player.GetAll()) do if string.match(string.lower(tostring(args[1])), string.lower(v:Nick())) != "" then found = found + 1 if found == 1 then game.ConsoleCommand("kickid "..v:UserID().." "..re.."\n") elseif found > 1 then ply:PrintMessage(3, "Error: Multiple targets.") elseif found < 1 then ply:PrintMessage(3, "Error: No specific user found.") end end end else ply:PrintMessage(3, "Error: Please enter a name") end else ply:PrintMessage(3, "Error: You are not an admin.") end end concommand.Add("sgn_kick", SGNKick) [/code] I didn't get any errors.
Did you get any errors? Or are we just going to wave a magic wand and it'll be fixed?
I have fixed it up as best as I could with the (very) limited description of the problem: [lua]function SGNKick(ply,cmd,args) if ply:IsAdmin() then if args[1] then local name = tostring(table.remove(args, 1)) local found = 0 local p; local re = string.Implode(" ", args) for _, v in ipairs(player.GetAll()) do if string.find(string.lower(name), string.lower(v:Nick())) then found = found + 1 p = v; end end if found == 1 then game.ConsoleCommand("kickid "..p:UserID().." "..re.."\n") elseif found > 1 then ply:PrintMessage(3, "Error: Multiple targets.") elseif found < 1 then ply:PrintMessage(3, "Error: No specific user found.") end else ply:PrintMessage(3, "Error: Please enter a name") end else ply:PrintMessage(3, "Error: You are not an admin.") end end concommand.Add("sgn_kick", SGNKick)[/lua] [highlight][b]UNTESTED[/b][/highlight]
I keep getting Error: No specific user found. When I use NullPoint's script. Maybe coz the script cant find a person :|, the found variable doesn't seem to work.
Sorry, you need to Log In to post a reply to this thread.