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

Posted

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)

 

 

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.

Posted (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 by HassoN
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.
 

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)

 

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.

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