Jump to content

KillTimer


Hugos

Recommended Posts

Posted

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.
 

Posted
7 minutes ago, HassoN said:

You may add killTimer(Timer) after your line 5.

as?

Говорю на русском. Sorry for bad english.
 

Posted
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.
 

Posted
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.
 

Posted
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

13319665721.gif

Posted (edited)

@Hugos, your problem was at the last argument of setTimerI 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 by JeViCo
  • Moderators
Posted

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 

  Tutorials  4x 

 

Posted

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)

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...