Jump to content

what's wrong with my timer


mores3

Recommended Posts

this ( mean nothing )  :(

 

 

local sX,sY = guiGetScreenSize() 
local counter = 15 
local r,g,b = 0,255,0 
  
function drawCounterSHI() 
    dxDrawText("Your vehicle will change in: "..counter,0,sY*0.8,sX,sY,tocolor

(r,g,b,255),2,"default","center","top",false,false,false) 
end 
  
function startEverything() 
addEventHandler("onClientRender",root,drawCounterSHI) 
setTimer(function() 
    counter = counter - 1 
    if counter < 1 then 
        counter = 15 
        r,g,b = 0,255,0 
    end  
end,1000,0) 
  
end 
addEvent("onCounterStart",true) 
addEventHandler("onCounterStart",getRootElement(),startEverything) 

it dont disappear when map is loading/changing 

and when new map is loaded it have start again 

Link to comment

ok here's an incomplete UNTESTED example of how i think it can be done*

I have no idea on how you want to manage onCounterStart... so i leave this to you unchanged

  • When you die the text disappear
  • When you spawn the text appear
  • When the race state changes, you can make the client text appear/disappear**

* I have wrote this in a hurry, i didn't check any syntax error, but i tried to be as clear as possible and i hope you understand the logic.

** ToDo: you must change the values of the table in makeClientKnowMapChange to make the triggers work. I have no idea of the correct values, experiment this yourself, since now i can't test.

 

 

--client
local sX,sY = guiGetScreenSize()
local counter = 15
local r,g,b = 0,255,0

local counterTimer
local isTextShowing --alternative to todo function "isEventHandled"

addEvent( "onServerStopTextRequest", true )
addEvent( "onServerStartTextRequest", true )

function drawCounterSHI() 
	dxDrawText( "Your vehicle will change in: "..counter, 0, sY*0.8, sX,sY, tocolor(r,g,b,255), 2, "default", "center", "top", false, false, false )
end

function startEverything()
	startText() --start the timer and make the text visible
end
addEvent( "onCounterStart", true)
addEventHandler( "onCounterStart", root, startEverything )

function stopText()
	--stop the timer, it's useless now
	if isTimer( counterTimer ) then
		killTimer(counterTimer)
	end
	--make the text not visible
	if isTextShowing then
		removeEventHandler( "onClientRender", root, drawCounterSHI )
		isTextShowing = false
	end
end
addEventHandler( "onClientPlayerWasted", localPlayer, stopText )
addEventHandler( "onServerStopTextRequest", resourceRoot, stopText )

function startText()
	if isTimer( counterTimer ) then
		killTimer( counterTimer )
	end
	--set the counter to 15s
	counter = 15
	--start the timer again
	counterTimer = setTimer(
		function()
			counter = counter - 1
			if counter < 1 then
					counter = 15
					r,g,b = 0,255,0
			end
		end,
	1000, 0 )
	--make the text visible
	if not isTextShowing then
		addEventHandler( "onClientRender", root, drawCounterSHI )
		isTextShowing = true
	end
end
addEventHandler( "onClientPlayerSpawn", localPlayer, startText )
addEventHandler( "onServerStartTextRequest", resourceRoot, startText )

--server
function makeClientKnowMapChange( newState, oldState )
	local states = {
		["undefined"] = nil,
		["NoMap"] = nil,
		["LoadingMap"] = nil,
		["PreGridCountdown"] = nil,
		["GridCountdown"] = nil,
		["Running"] = nil,
		["MidMapVote"] = nil,
		["SomeoneWon"] = nil,
		["TimesUp"] = nil,
		["EveryoneFinished"] = nil,
		["PostFinish"] = nil,
		["NextMapSelect"] = nil,
		["NextMapVote"] = nil,
		["ResourceStopping"] = nil,
	}
	if states[newState] == true then
		triggerClientEvent( root, "onServerStartTextRequest", resourceRoot )
	elseif states[newState] == false then
		triggerClientEvent( root, "onServerStopTextRequest", resourceRoot )
	end
	--ignore nil values
end
addEventHandler( "onRaceStateChanging", root, makeClientKnowMapChange )

 

Link to comment

Hello BIG THANK YOU LoPollo

LoPollo I've used your client script without any corrections and it work as I need 

**Only thing is to start it only after counting down ( it is cosmetic correction )  <-- I need help only with this

I don't know ( spawn player = spawn after counting down or when player is visible before counting down )

BTW watch my video I think it show what I mean (inscriptions) and Please watch to the end :) 

 

Again big THANK YOU, You are very nice and helpful person :D:D 

Huge positive for LoPollo

Edited by mores3
small mistake
Link to comment

That's because players get spawned before the match starts i guess...

So if there's a state that define when the match is ongoing and when not i should use it, so i must pass the states on the client.

 

Again, this is untested. I made state handling clientside, so client now knows what state is currently active.

To fix the issue you said i made the startText return and not perform any further action if the current state is not true. So when you spawn but the match is not ongoing the text won't be drawn.

Again, all the states table is filled with nils*, cause i have no exact idea of when each state becomes active ( i do not play race ), so edit it if it's needed.

When that state becomes the current state:

  • nil -> no action
  • true -> the text will be shown (call startText)
  • false -> the text will be hidden (call stopText)

* i set Running as true because this is the state i think means the match is ongoing

--client
local sX,sY = guiGetScreenSize()
local counter = 15
local r,g,b = 0,255,0

local counterTimer
local isTextShowing --alternative to todo function "isEventHandled"

--set the states to nil to not perform any action when that state becomes the current state, true to show text, false to hide text
local states = {
	["undefined"] = nil,
	["NoMap"] = nil,
	["LoadingMap"] = nil,
	["PreGridCountdown"] = nil,
	["GridCountdown"] = nil,
	["Running"] = true,
	["MidMapVote"] = nil,
	["SomeoneWon"] = nil,
	["TimesUp"] = nil,
	["EveryoneFinished"] = nil,
	["PostFinish"] = nil,
	["NextMapSelect"] = nil,
	["NextMapVote"] = nil,
	["ResourceStopping"] = nil,
}

addEvent( "onServerRaceStateChangingNotice", true )

function drawCounterSHI() 
	dxDrawText( "Your vehicle will change in: "..counter, 0, sY*0.8, sX,sY, tocolor(r,g,b,255), 2, "default", "center", "top", false, false, false )
end

function startEverything()
	startText() --start the timer and make the text visible
end
addEvent( "onCounterStart", true)
addEventHandler( "onCounterStart", root, startEverything )

function stopText()
	--stop the timer, it's useless now
	if isTimer( counterTimer ) then
		killTimer(counterTimer)
	end
	--make the text not visible
	if isTextShowing then
		removeEventHandler( "onClientRender", root, drawCounterSHI )
		isTextShowing = false
	end
end
addEventHandler( "onClientPlayerWasted", localPlayer, stopText )

function startText()
	if states.currentState ~= "Running" then return end --i guess that is the state that means the match is ongoing
	if isTimer( counterTimer ) then
		killTimer( counterTimer )
	end
	--set the counter to 15s
	counter = 15
	--start the timer again
	counterTimer = setTimer(
		function()
			counter = counter - 1
			if counter < 1 then
					counter = 15
					r,g,b = 0,255,0
			end
		end,
	1000, 0 )
	--make the text visible
	if not isTextShowing then
		addEventHandler( "onClientRender", root, drawCounterSHI )
		isTextShowing = true
	end
end
addEventHandler( "onClientPlayerSpawn", localPlayer, startText )

function raceStateChangeHandler( newState, oldState )
	states.currentState = newState
	if states[newState] == true then
		startText()
	elseif states[newState] == false then
		stopText()
	end
end
addEventHandler( "onServerRaceStateChangingNotice", resourceRoot, raceStateChangeHandler )


--server
function makeClientKnowMapChange( newState, oldState )
	triggerClientEvent( root, "onServerRaceStateChangingNotice", resourceRoot, newState, oldState )
end
addEventHandler( "onRaceStateChanging", root, makeClientKnowMapChange )

 

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