Jump to content

[HELP] Cancelling countdown


Skadoosh

Recommended Posts

Can you guys please tell me how i can make the existing timer  to be deleted when i do the /startdf command twice (you can see it toggles the event ON/OFF)  ? i want to delete the on-going timer when i do the /startdf command once the event is started so that when i start it again , it will start from 100. Here is my code   

Server Side

function EnableEvent(thePlayer)
  times = times + 1
  if times == 1 then
    addCommandHandler("dfrustler",EventWarp)
	  outputChatBox("Dog Fight Event Warps are now open",_,255,255,255,true)
	  outputChatBox("You Opened the Dog Fight Event Warps, You can cancel the event by typing this command again",thePlayer,255,255,255,true)
	  timer = setTimer(triggerClientEvent,1000,100,'startCountDown',root)
	else
	  times = 0
	  removeCommandHandler("dfrustler",EventWarp) -- COMMAND TO WARP TO THE EVENT 
	  outputChatBox("Dog Fight Event Warps are now Closed",_,255,255,255,true)
	  triggerEvent('eventOFF',root)
	end 
  addCommandHandler('startdf',root,EnableEvent)

Client Side

addEvent('startCountDown',true)
count = 0
function startCount()
if count == 0 then
  count = 100
end
 count = count-1
function startTheClock()			
	for k,player in ipairs(playerList) do
	   if getLocalPlayer() == player and count ~= 0 then
	     dxDrawText("EVENT STARTING IN",x-1200,y-1000,_,_,_,1.5,"bankgothic")
	     dxDrawText(tostring(count),x-1000,y-950,_,_,_,1.5,"bankgothic")		
		 end
	end
end
addEventHandler('onClientRender',root,startTheClock)
	
	if count == 0 then  -- WHAT HAPPENS WHEN COUNTDOWN REACHES 0 
      removeEventHandler('onClientRender',root,startTheClock)
	   if #playerList < 2 then  -- KILLS EVERYONE AND STOP EVENT IF PARTICIPANTS < 2
	     triggerServerEvent('eventON',root)
		 else
		   triggerServerEvent('eventOFF',root)						
		end
		
	end
end
addEventHandler('startCountDown',root,startCount)

the problem with this is when i do /startdf the event starts and hence the countdown too (from 100 - 0) but when i do the /startdf command again it is supposed to cancel the event and kill everybody inside the event but when i do that the timer will still go on and it bugs the entire script. I tried my best to explain my problem to you guys...

Link to comment
function EnableEvent(thePlayer)
	if ( isTimer ( timer ) ) then 
		removeCommandHandler("dfrustler",EventWarp) -- COMMAND TO WARP TO THE EVENT 
		outputChatBox("Dog Fight Event Warps are now Closed",_,255,255,255,true)
		triggerEvent('eventOFF',root)
		killTimer ( timer )
		return 
	end 
	addCommandHandler("dfrustler",EventWarp)
	outputChatBox("Dog Fight Event Warps are now open",_,255,255,255,true)
	outputChatBox("You Opened the Dog Fight Event Warps, You can cancel the event by typing this command again",thePlayer,255,255,255,true)
	timer = setTimer(triggerClientEvent,1000,100,'startCountDown',root)
end 
addCommandHandler('startdf',root,EnableEvent)

try this .

Edited by Infinity-War
Link to comment

So this checks if the timer is running and if it is , it's doesn't Enable the event ? I don't want this . I want it to delete the timer and enable the event if a timer is running.Also killTimer won't destroy the timer it only pauses it.

Edited by Skadoosh
Link to comment
55 minutes ago, Skadoosh said:

So this checks if the timer is running and if it is , it's doesn't Enable the event ? I don't want this . I want it to delete the timer and enable the event if a timer is running.Also killTimer won't destroy the timer it only pauses it.

killTimer is destroy the timer .

State = 'Off'

function EnableEvent(thePlayer)
  if State == 'Off' then
    addCommandHandler("dfrustler",EventWarp)
	  outputChatBox("Dog Fight Event Warps are now open",_,255,255,255,true)
	  outputChatBox("You Opened the Dog Fight Event Warps, You can cancel the event by typing this command again",thePlayer,255,255,255,true)
	  timer = setTimer(triggerClientEvent,1000,100,'startCountDown',root)
    	State = 'On'
	elseif ( State == 'On' ) then
	  State = 'Off'
	  removeCommandHandler("dfrustler",EventWarp) -- COMMAND TO WARP TO THE EVENT 
	  outputChatBox("Dog Fight Event Warps are now Closed",_,255,255,255,true)
	  triggerEvent('eventOFF',root)
    	killTimer ( timer )
    	timer = nil
	end 
  addCommandHandler('startdf',root,EnableEvent)

try this .

Link to comment

Thank you , i fixed my script ❤️ . Actually this was not the problem but the thing that " killTimer " will actually destroy the timer really helped me find the issue with my script (i thought killTimer pauses the timer) . Thank you once again mate ;)

Link to comment
5 minutes ago, Skadoosh said:

Thank you , i fixed my script ❤️ . Actually this was not the problem but the thing that " killTimer " will actually destroy the timer really helped me find the issue with my script (i thought killTimer pauses the timer) . Thank you once again mate ;)

Welcome every time :-)

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