Hugos Posted July 25, 2019 Posted July 25, 2019 Hello. I have a question: there is a function with a timer (when a player connects to the server)... --Client local Timer = setTimer(function() if isTransferBoxActive() then else triggerServerEvent("PlayerKick", getLocalPlayer()) end end, 300000, 0) --Server addEvent("PlayerKick", true) function PlayerKick() kickPlayer(source, "Server", "AFK!") end addEventHandler("PlayerKick", root, PlayerKick) How do i kill this timer when a player spawn Говорю на русском. Sorry for bad english.
HassoN Posted July 25, 2019 Posted July 25, 2019 You may add killTimer(Timer) after your line 5. * There is No God but Allah discord: HassoN#2709 Visit my wiki profile: https://wiki.multitheftauto.com/wiki/User:Hassan_saad
Hugos Posted July 25, 2019 Author Posted July 25, 2019 7 minutes ago, HassoN said: You may add killTimer(Timer) after your line 5. as? Говорю на русском. Sorry for bad english.
HassoN Posted July 25, 2019 Posted July 25, 2019 Excuse me I thought your server side code was spawnPlayer not kickPlayer. Ignore what I said before. Add this to your client side: function onSpawn() killTimer(Timer) end addEventHandler("onClientPlayerSpawn", localPlayer, onSpawn) * There is No God but Allah discord: HassoN#2709 Visit my wiki profile: https://wiki.multitheftauto.com/wiki/User:Hassan_saad
Hugos Posted July 25, 2019 Author Posted July 25, 2019 14 minutes ago, HassoN said: Excuse me I thought your server side code was spawnPlayer not kickPlayer. Ignore what I said before. Add this to your client side: function onSpawn() killTimer(Timer) end addEventHandler("onClientPlayerSpawn", localPlayer, onSpawn) black screen. Говорю на русском. Sorry for bad english.
HassoN Posted July 25, 2019 Posted July 25, 2019 (edited) 7 minutes ago, Hugos said: black screen. Black screen? The code is supposed to kill the timer not to spawn you. EDIT: use /debugscript 3 and tell me if your resource is even working. Edited July 25, 2019 by HassoN * There is No God but Allah discord: HassoN#2709 Visit my wiki profile: https://wiki.multitheftauto.com/wiki/User:Hassan_saad
Hugos Posted July 25, 2019 Author Posted July 25, 2019 17 minutes ago, HassoN said: Black screen? The code is supposed to kill the timer not to spawn you. If you add this code after 5 lines, then there is no black screen, but the player does not kick. Говорю на русском. Sorry for bad english.
HassoN Posted July 25, 2019 Posted July 25, 2019 3 minutes ago, Hugos said: If you add this code after 5 lines, then there is no black screen, but the player does not kick. --Client local Timer = setTimer(function() if isTransferBoxActive() then else triggerServerEvent("PlayerKick", getLocalPlayer()) end end, 300000, 0) function onSpawn() killTimer(Timer) end addEventHandler("onClientPlayerSpawn", localPlayer, onSpawn) --Server addEvent("PlayerKick", true) function PlayerKick() kickPlayer(source, "Server", "AFK!") end addEventHandler("PlayerKick", root, PlayerKick) * There is No God but Allah discord: HassoN#2709 Visit my wiki profile: https://wiki.multitheftauto.com/wiki/User:Hassan_saad
JeViCo Posted July 26, 2019 Posted July 26, 2019 (edited) @Hugos, your problem was at the last argument of setTimer: I replaced 0 with 1 timesToExecute: The number of times you want the timer to execute, or 0 for infinite repetitions (wiki) --Client local Timer = setTimer(function() if not isTransferBoxActive() then triggerServerEvent("PlayerKick", localPlayer) -- getLocalPlayer() and localPlayer returns player end end, 300000, 1) Edited July 26, 2019 by JeViCo
Moderators IIYAMA Posted July 26, 2019 Moderators Posted July 26, 2019 And don't forget this as well: (meta.xml) <download_priority_group>100</download_priority_group> else the timer will probably start too late. Do you want to improve your Lua programming skills and make less mistakes? Start with Lua Language Server! Useful functions 3x Spoiler checkPassiveTimer getScreenStartPositionFromBox getPedGender Tutorials 4x Spoiler Scaling DX Events Attach an addEventHandler on a group of elements Debugging
JeViCo Posted July 26, 2019 Posted July 26, 2019 Oops, missread a little bit. afk system is a bit more complex than you think. You should track player's movement to make sure that he is just standing and doing nothing. You should also use onPlayerLogin event to optimise your script (I'm 100% sure that your login-panel appears at the end of downloading & loading)
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now