Jump to content

KillTimer


Hugos

Recommended Posts

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

Link to comment

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)

 

 

Link to comment
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.

Link to comment
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)

 

Link to comment

@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
Link to comment

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)

Link to comment

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