• Kick a player a in a delay of 3 seconds.
    16 replies, posted
I want to be able to kick a player in a delay of three seconds after I type my command. I want the command to work like this. A console command followed by two arguments. [code] gtfo Maxterchief "spawnkilling" [/code] Command to kick someone, who I want to kick, the reason. I have tried this and the delay is the only thing that doesn't work. It immediately kicks the player and then after 3 seconds, it says timer error. Here is my code: [lua] function gtfokick(caller, command, args) if caller:IsAdmin() then for k, v in pairs (player.GetAll()) do if v:Nick() == args[1] then timer.Create("kicktimer", 3, 1, v:Kick(args[2])) timer.Start("kicktimer") end end end end concommand.Add("gtfo", gtfokick) [/lua]
Replace line 9 and 10 with this: [lua]timer.Simple(3, v.Kick, v, args[2])[/lua] Untested.
I think it would be v:Kick()
No, you can't call v:Kick( ) like that directly in a timer, you'd need to wrap it inside a function. That's why it's better to call it the other way. Note here that [lua]v:Kick( )[/lua] is exactly the same as: [lua]v.Kick( v )[/lua]
NINJA'D ARGJHHHH :smile:
Same problem when I tried your way. :( [editline]10:11AM[/editline] I did this Overv: [lua] timer.Simple(3, v:Kick(args[2])) [/lua]
MakeR has already told you how to do it...
[QUOTE=maxterchief;16981502]Same problem when I tried your way. :( [editline]10:11AM[/editline] I did this Overv: [lua] timer.Simple(3, v:Kick(args[2])) [/lua][/QUOTE] [QUOTE=MakeR;16976266] [lua]timer.Simple(3, v.Kick, v, args[2])[/lua] [/QUOTE] .
Fine you win. XD Thanks... It worked.
Your'e welcome, but next time you ask for help make sure to try the suggestions before you knock them.
I don't see how v.Kick works. Why is it you can use a . and not a : ?
v:Nick() is the same as v.Nick(v). the [b]:[/b] passes the object it is called on as the first argument.
Ok. Thanks! :D [editline]10:40AM[/editline] Is there a way I can get a bunch more lines of code to run with the kick target defined after three seconds?
[code]timer.Simple(3 , function() for k , v in ipairs(player.GetAll() do if v:Nick() == "TargetName" then v:ChatPrint("You have been banned for x Bitch and moan at our forums - www.x.y") // Do more code here v:Ban(time , reason) end end end )[/code]
Also can I make it so that I only have to type part of the name?
Yes, by changing the equal expression to: [lua]if string.find( v:Nick( ), "TargetName" ) or v:Nick( ) == "TargetName" then[/lua] (Last time I checked string.find does [b]not[/b] return true when the two strings are equal.) If you want it to match case insensitive, make both strings lowercase with string.lower.
Thank you.
Sorry, you need to Log In to post a reply to this thread.