Hello my dudes! I need help creating a kick script that works in chat,
For example:
kick hobo
Will kick hobo. I can't seem to figure this out for some reason. Help would be appreciated
GM:PlayerSay
string.find
Player Kick
hook.Add("PlayerSay", "admin_func_kick", function(ply, text)
if string.sub(string.lower(text), 1, 5) == "!kick" then
local target = string.sub(string.lower(text), 7, #text)
for _, v in ipairs(player.GetAll()) do
if target == string.lower(v:Name()) then
PrintMessage(HUD_PRINTTALK, ply:Name().." kicked "..v:Name())
v:Kick()
return
end
end
end
end)
This may or may not work.
Just a example.
Didn't work but I managed to fix it, thanks dude!
I forgot a ")".
Just saw it.
Yep
or you could refer to this thread Chat command?
I don't understand what you're talking about? He already used that at the top:
hook.Add("PlayerSay", "admin_func_kick", function(ply, text)
Line 3 is this:
local target = string.sub(string.lower(text), 7, #text)
Replacing that isn't going to help because you need to extract the target's name from the text.
Also, line 3 could be simplified slightly because string.sub doesn't need the last argument:
local target = string.sub( string.lower( text ), 7 )
Also, if you only want it to kick one player instead of all with the name then this will work:
hook.Add( "PlayerSay", "KickCommand", function( ply, txt )
if ply:IsAdmin() and string.sub( string.lower( txt ), 1, 5 ) == "!kick" then
local target
local args = string.sub( txt, 7 )
for _, v in ipairs( player.GetHumans() ) do
if v:Nick() == args then
target = v
end
end
if IsValid( target ) then
target:Kick()
end
return ""
end
end )
Sorry, you need to Log In to post a reply to this thread.