Page 1 of 1
Timer of CP being hold
Posted: Thu Mar 17, 2011 2:44 pm
by TK432
Hey there again. I'm trying to set up a timer for a CP. Whenever the CP is hold by ATT the timer goes on, if not, it stops. So my problem is the timer doesn't start when team ATT controls the CP.
Heres my code:
I've also tryed adding the
and
somewhere functions without success.
I belive I've done something wrong with the "if"-part since I tried to leave out the timer and just trigger something simple if the CP is ATT.
I don't get any errors while munging or in the BFront2 file.
Re: Timer of CP being hold
Posted: Thu Mar 17, 2011 3:29 pm
by Fiodis
Try something more like:
Code: Select all
Team1= CreateTimer("Team1")
SetTimerValue(Team1, 60)
ShowTimer("Team1")
onesecond = CreateTimer("onesecond")
SetTimerValue(onesecond, 1)
StartTimer(onesecond)
check_cp_ownership = OnTimerElapse(
function(timer)
if GetTimerName(timer) == "onesecond" then
if GetCommandPostTeam("cp1") == ATT then
StartTimer(Team1)
else
StopTimer("Team1")
end
end
end
)
I may not have the syntax quite right, but you see the general idea - you need to check periodically whether or not CP 1 is held by ATT. Your code isn't working because the game is only checking once, at the start of the game.
Re: Timer of CP being hold
Posted: Thu Mar 17, 2011 3:54 pm
by TK432
I tried the code, but the timer still doesn't start
Here is it again:
Pretty much left it the same
Re: Timer of CP being hold
Posted: Thu Mar 17, 2011 4:14 pm
by DarthD.U.C.K.
what about that code as trigger:
Code: Select all
cp1.OnCapture = function(self)
if GetCommandPostTeam("cp1") == ATT then
StartTimer(Team1)
else
StopTimer(Team1)
end
end
im not sure if the function is set up corrrectly though.
while thinking about it...i guess i set that up completely wrong, well the class the class "CommandPost" has the function "OnCapture"...
Re: Timer of CP being hold
Posted: Thu Mar 17, 2011 4:55 pm
by TK432
Nope, the coutner still wouldn't start.
Maybe I'm doing something wrong generally.
Do I need to pay attention to something special extern that I could've done wrong (e.g. claiming variables or such) when setting up the timer?
Edit:
Here are some facts of what works, that may help:
-The overall game around
-I've set it up in a seperate lua script and calling it correctly in my ABC lua.
-The timer does also show correctly.
=> The timer (Team1) does exist
Everything below the the timer setup is not proven to be working.
Heres the code with DarthD.U.C.K.'s suggestion: