Timer of CP being hold

In this forum you will find and post information regarding the modding of Star Wars Battlefront 2. DO NOT POST MOD IDEAS/REQUESTS.

Moderator: Moderators

Post Reply
User avatar
TK432
2nd Lieutenant
2nd Lieutenant
Posts: 408
Joined: Tue May 26, 2009 4:18 pm
Location: Somewhere far away

Timer of CP being hold

Post 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:
Hidden/Spoiler:
Team1= CreateTimer("Team1")
SetTimerValue(Team1, (60))
ShowTimer("Team1")
OnTimerElapse(
function(timer)
KillObject("Dummy")
DestroyTimer(Team1)
end,
Team1
)

if GetCommandPostTeam("cp1") == ATT then

StartTimer(Team1)

else

StopTimer(Team1)


end
I've also tryed adding the

Code: Select all

FindTimer(Timer)
and

Code: Select all

GetTimerValue(Timer)
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.
User avatar
Fiodis
Master of the Force
Master of the Force
Posts: 4145
Joined: Wed Nov 12, 2008 9:27 pm
Projects :: Rannoch + Tientia + Tools Programming

Re: Timer of CP being hold

Post 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.
User avatar
TK432
2nd Lieutenant
2nd Lieutenant
Posts: 408
Joined: Tue May 26, 2009 4:18 pm
Location: Somewhere far away

Re: Timer of CP being hold

Post by TK432 »

I tried the code, but the timer still doesn't start

Here is it again:
Hidden/Spoiler:
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,
Team1
)
Pretty much left it the same
User avatar
DarthD.U.C.K.
Master of the Force
Master of the Force
Posts: 6027
Joined: Wed Sep 27, 2006 11:05 am
Location: Duckburg, Germany

Re: Timer of CP being hold

Post 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"...
User avatar
TK432
2nd Lieutenant
2nd Lieutenant
Posts: 408
Joined: Tue May 26, 2009 4:18 pm
Location: Somewhere far away

Re: Timer of CP being hold

Post 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:
Hidden/Spoiler:
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
cp1.OnCapture = function(self)
if GetCommandPostTeam("cp1") == ATT then
StartTimer(Team1)
else
StopTimer(Team1)
end
end
end
end,
Team1
)
Post Reply