Jump to content

killTimer Problem


Recommended Posts

Timer not canceled after player dies. The player dies but does not appear to have left the area. That's why the rockets keep firing.
sorry my english bad :/

server

g_base_col = createColCuboid(-381.27297973633, 1517.2098388672, -5.718826293945, 1600, 1600, 200.25)


g_root = getRootElement ()


function hit ( pla, dim, hitElement )
	if getElementType ( pla ) == "player" then
	local vehicle = getPedOccupiedVehicle ( pla )
		if vehicle or vehicle then
			if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(pla)), aclGetGroup("roket")) then
				outputChatBox ( "Hoş Geldin Asker!, "..getPlayerName(pla).."!", pla, 0, 150, 0 )
			else
				setElementData ( pla, "inRestrictedArea", "true" )
				triggerClientEvent ( pla, "destroyTrepassor", g_root, pla )
				outputChatBox ( "Askeri Bölge Derhal Uzaklaş!", pla, 255, 0, 0 )
				outputChatBox ( "[Uyarı] Roket Saldırısı!", g_root, 255, 0, 0 )
			end
		end
	end
end
addEventHandler ( "onColShapeHit", g_base_col, hit )

function leave ( pla, dim )
	if getElementType ( pla ) == "player" then
	local vehicle = getPedOccupiedVehicle ( pla )
		if vehicle or vehicle then
			if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(pla)), aclGetGroup("roket")) then
				outputChatBox ( "İyi Devriyeler Asker!", pla, 0, 100, 0 )
			else
				setElementData ( pla, "inRestrictedArea", "false" )
				triggerClientEvent ( pla, "destroyTimers", g_root, pla )
				outputChatBox ( "[Uyarı] Roket Saldırısı Durdu!", g_root, 255, 0, 0 )
				outputDebugString ( "*"..getPlayerName(pla).." has left col shape" )
			end
		end
	end
end
addEventHandler ( "onColShapeLeave", g_base_col, leave )

client

g_loc_pla = getLocalPlayer ()
g_loc_root = getRootElement ()

addEvent ( "destroyTrepassor", true )
addEventHandler ( "destroyTrepassor", g_loc_root,
	function ()
		
		posX = -147.10989379883
		posY =  2001.6342773438
		posZ =  97.30118560791
		
		posX2 = -135.48461914062
		posY2 =  1652.8358154297
		posZ2 =  97.30118560791
		
		posX3 = 99.344902038574
		posY3 =  2233.484375
		posZ3 =  130.27871704102
		
		posX4 = 478.35934448242
		posY4 =  2160.7651367188
		posZ4 =  97.30118560791
		
		posX5 = 523.74835205078
		posY5 =  1976.8087158203
		posZ5 =  97.30118560791
		
		posX6 = 448.73950195312
		posY6 =  1715.9664306641
		posZ6 =  97.30118560791
		
		posX7 = 219.20726013184
		posY7 =  1836.5458984375
		posZ7 =  97.30118560791
		
		posX8 = 188.45198059082
		posY8 =  2081.4970703125
		posZ8 =  97.30118560791
		
		local isInResArea = getElementData ( g_loc_pla, "inRestrictedArea" )
		
		rotZ = getPedRotation ( g_loc_pla )
		
		if isInResArea == "true" then
			timer1 = setTimer ( createProjectile, 3000, 0, g_loc_pla, 20, posX, posY, posZ, 1.0, g_loc_pla, 0, 0, rotZ, 0.1, 0.1, 0.1 )
			timer2 = setTimer ( createProjectile, 3000, 0, g_loc_pla, 20, posX2, posY2, posZ2, 1.0, g_loc_pla, 0, 0, rotZ, 0.1, 0.1, 0.1 )
			timer3 = setTimer ( createProjectile, 3000, 0, g_loc_pla, 20, posX3, posY3, posZ3, 1.0, g_loc_pla, 0, 0, rotZ, 0.1, 0.1, 0.1 )
			timer4 = setTimer ( createProjectile, 3000, 0, g_loc_pla, 20, posX4, posY4, posZ4, 1.0, g_loc_pla, 0, 0, rotZ, 0.1, 0.1, 0.1 )
			timer5 = setTimer ( createProjectile, 3000, 0, g_loc_pla, 20, posX5, posY5, posZ5, 1.0, g_loc_pla, 0, 0, rotZ, 0.1, 0.1, 0.1 )
			timer6 = setTimer ( createProjectile, 3000, 0, g_loc_pla, 20, posX6, posY6, posZ6, 1.0, g_loc_pla, 0, 0, rotZ, 0.1, 0.1, 0.1 )
			timer7 = setTimer ( createProjectile, 3000, 0, g_loc_pla, 20, posX7, posY7, posZ7, 1.0, g_loc_pla, 0, 0, rotZ, 0.1, 0.1, 0.1 )
			timer8 = setTimer ( createProjectile, 3000, 0, g_loc_pla, 20, posX8, posY8, posZ8, 1.0, g_loc_pla, 0, 0, rotZ, 0.1, 0.1, 0.1 )
		end
		
	end
)

addEvent ( "destroyTimers", true )
addEventHandler ( "destroyTimers", g_loc_root,
	function ()
		
		local isInResArea = getElementData ( g_loc_pla, "inRestrictedArea" )
		if isInResArea == "false" then
			killTimer ( timer1 )
			killTimer ( timer2 )
			killTimer ( timer3 )
			killTimer ( timer4 )
			killTimer ( timer5 )
			killTimer ( timer6 )
			killTimer ( timer7 )
			killTimer ( timer8 )
		end
		
	end
)
Edited by #nofear
Link to comment
  • Moderators
6 hours ago, #nofear said:

 The player dies but does not appear to have left the area.

If these are the only lines of code that trigger 'destroyTimers'/'destroyTrepassor', then I don't think you have to check element data on clientside.

 

But if they are not, you could use triggerClientEvent arguments instead. But keep in mind that the clientside handler functions also has to do other things, else it doesn't make sense to have the condition isInResArea in the first place.

 

Server

triggerClientEvent ( 
	pla, -- receiver (player)
	"destroyTrepassor", 
	g_root, -- source
	true -- < isInResArea 
)

 

Clientside

addEvent ( "destroyTrepassor", true )
addEventHandler ( "destroyTrepassor", g_loc_root,
	function (isInResArea)
		-- ...
		if isInResArea == true then
      
		-- ...

 

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