Jump to content

Timer C-side


Recommended Posts

Hi, I noticed my client-side timer was getting killed when another player kills a ped too. so I decided to add a getLocalPlayer() to the killer variable, but will this work?, will this not kill my timer if another player kills a ped, since I added a getLocalPlayer() now? I don't have anyone to test with rn but I just wanna ask, if this doesn't work, do I need to add a timer table like serverside-timers(player-based) instead? I tried adding a local before the removetimer but doing that, the timer can't be recognized by the event onClientPedWasted, but removing the local caused the timer to be killed by other players as well that's why I added a getLocalPlayer() on the killer variable, but im not sure if it will work.

 

function drawxp(xpfromserver)
xptogive = xpfromserver
removetimer = setTimer(function()
xptogive = false
end, 3*1000, 1)
end

addEvent("drawxp", true)
addEventHandler("drawxp", localPlayer, drawxp)

function onWasted(killer, weapon, bodypart)
    if ( killer and getElementType(killer) == "player" and getElementType(source) == "ped" ) then
        if killer == getLocalPlayer() then 
        if getElementData(source, "zombie") == true then
         if isTimer(removetimer) then killTimer(removetimer) outputChatBox("killed timer") end
    end
end
end
end
addEventHandler("onClientPedWasted", getRootElement(), onWasted)

 

 

Edited by Bean666
Link to post

Hello,

All you need to do is to replace the getRootElement() in the addEventHandler with localPlayer .

Also instead of getLocalPlayer() use the predefined variable localPlayer .

Uhh I just noticed it is used when a zombie is being killed. Isn't this better to be in the server side ?

Edited by SpecT
Link to post
1 minute ago, SpecT said:

Hello,

All you need to do is to replace the getRootElement() in the addEventHandler with localPlayer .

Also instead of getLocalPlayer() use the predefined variable localPlayer .

function drawxp(xpfromserver)
xptogive = xpfromserver
removetimer = setTimer(function()
xptogive = false
end, 3*1000, 1)
end

addEvent("drawxp", true)
addEventHandler("drawxp", localPlayer, drawxp)

function onWasted(killer, weapon, bodypart)
    if ( killer and getElementType(killer) == "player" and getElementType(source) == "ped" ) then
        if killer == localPlayer then 
        if getElementData(source, "zombie") == true then
         if isTimer(removetimer) then killTimer(removetimer) outputChatBox("killed timer") end
    end
end
end
end
addEventHandler("onClientPedWasted", getLocalPlayer(), onWasted)

basically, like this?

Link to post

Oh sorry I got it wrong the idea you have.

The "if killer == localPlayer then" will be enough to limit it so your timer won't be killed when somebody else kills the ped.

function drawxp(xpfromserver)
	xptogive = xpfromserver
	removetimer = setTimer(function()
		xptogive = false
	end, 3*1000, 1)
end
addEvent("drawxp", true)
addEventHandler("drawxp", localPlayer, drawxp)

function onWasted(killer, weapon, bodypart)
	if ( killer and getElementType(killer) == "player" and getElementType(source) == "ped" ) then
		if killer == localPlayer and getElementData(source, "zombie") == true then 
			if isTimer(removetimer) then
				killTimer(removetimer)
				outputChatBox("killed timer")
			end
		end
	end
end
addEventHandler("onClientPedWasted", root, onWasted)

 

Edited by SpecT
Link to post
3 minutes ago, SpecT said:

Oh sorry I got it wrong the idea you have.

The "if killer == localPlayer then" will be enough to limit it so your timer won't be killed when somebody else kills the ped.


function drawxp(xpfromserver)
	xptogive = xpfromserver
	removetimer = setTimer(function()
		xptogive = false
	end, 3*1000, 1)
end
addEvent("drawxp", true)
addEventHandler("drawxp", localPlayer, drawxp)

function onWasted(killer, weapon, bodypart)
	if ( killer and getElementType(killer) == "player" and getElementType(source) == "ped" ) then
		if killer == localPlayer and getElementData(source, "zombie") == true then 
			if isTimer(removetimer) then
				killTimer(removetimer)
				outputChatBox("killed timer")
			end
		end
	end
end
addEventHandler("onClientPedWasted", root, onWasted)

 

oh thanks, and anyway, the "drawxp" event hanlder, i can change the localPlayer, to root right? since it doesnt really matter as long as you trigger the clientevent for a certain variable, and it wont trigger to others, and root is faster right?

Link to post
15 minutes ago, Bean666 said:

oh thanks, and anyway, the "drawxp" event hanlder, i can change the localPlayer, to root right? since it doesnt really matter as long as you trigger the clientevent for a certain variable, and it wont trigger to others, and root is faster right?

Yes, you can change it to root. It won't trigger for everyone as long as you specify to which players to be triggered.

  • Like 1
Link to post

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