Help With Timers (LuaSyntax) Again.

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
Ace_Azzameen_5
Jedi
Jedi
Posts: 1119
Joined: Sat Apr 23, 2005 8:52 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Help With Timers (LuaSyntax) Again.

Post by Ace_Azzameen_5 »

OnGunshipTime = OnFinishCapture(
function(post)
if GetObjectTeam("cp2") == 1 then
if GetObjectTeam("cp3") == 1 then
if GetObjectTeam("cp5") == 1 then
ReleaseFinishCapture(OnGunshipTime)
OnGunshipTime = nil
PlayAnimationFromTo("LAAT", 0, 210)
RespawnObject("cp1cam")
RespawnObject("cp1")
KillObject("cp2")
KillObject("cp3")
KillObject("cp5")
CreateTimer ("LAATJourney1")
SetTimerValue("LAATJourney1",210)
StartTimer("LAATJourney1")
end
end --every time you add a command post if statement you must add another end here
end
end
)
OnGetTimerValue ("LAATJourney1" , 210)
RespawnObject("cp2cam")
end
KillObject("cp1")-note this stuff happens before the above stuff
KillObject("cp4")
KillObject("cp6")
KillObject("cp7")
KillObject("cp8")
KillObject("cp1cam")
KillObject("cp2cam")
CreateTimer ("CISreinf1")
SetTimerValue("CISreinf1",3600)
StartTimer("CISreinf1")
OnGetTimerValue ("CISreinf1" , 3300)
AddReinforcements (2, 50)
This is the code I developed with help from Xwingguy, which originally designed to trigger an animation when 3 objects (cps) are owned by team on republic. I then modified it without success to then kill the captured commands posts, and respawn 2 more at the same moment the animation begins. This was successful. (cps 2,3,5 disappear, cp1 and cp1cam appear)

My next goal was to have another command post spawn when the animation reached 210 seconds, which is when an animated gunsip reaches it's destination. Since I could find no "Getanimationtime' function I attempted to have a a timer (LAATjourney1) begin simualtaneous with the animation and use gettimervalue function. My timers doen't work and end in munge errors.

At the bottom of this section of code is a timer that is supposed to add 50 reinforcments to the CIS every five minutes (my attemot at more realistic reinforcements coming in from a wide area, the republic most secure the area and gain local supeority as to stop incoming cis and move on to next objectives) but it doesn't work either.

If one of the code experts could rewrite it proparly (man that doc is hard to understand, but I'm learning. It shows an example of get object time with an arrow symbol that doesn't work in .lua. . .) or at least tell me my errors, well, thanks!
archer01

Post by archer01 »

A few of the errors I can see off the bat are as follows:

-- Timer create should be:
LAATJourney1 = CreateTimer ("tempName") <<< *Edit: Not true (see below)

-- Not an event:
OnGetTimerValue ("LAATJourney1" , 210)
-- GetTimerValue is not an event, and only events can be used with the "On" callback. The only event a timer has is "TimerElapsed".
-- Check some of the campaign scripts to see how the elapse functions are setup
Last edited by archer01 on Thu Aug 03, 2006 7:43 pm, edited 1 time in total.
Ace_Azzameen_5
Jedi
Jedi
Posts: 1119
Joined: Sat Apr 23, 2005 8:52 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Post by Ace_Azzameen_5 »

That Still doesn't help me. . .So, LAATJourney1 = CreateTimer ("TEMPName") will start a timer called LAATJOURNEY1? wow, those docs are horrible! I already know I did it wrong, I don't need the specifics, I need to know what is right.

Wait, so the timer hitting a certain value can't trigger anything, or is there just another way to trigger than the ON bit?

If I want something to occur every five minutes, should I set up the timer to trigger another timer after elapsing? That seems . . .well, it would take a lot of lines. . .maybe I could work it so the timer restarts itself etc. . .
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Post by [RDH]Zerted »

I may post later on your first problem, but for your last timer (you can name the timer whatever):
--creates the SupportTroops_CIS timer
CreateTimer("SupportTroops_CIS")

--sets the timer rate: now each timer value of 1 is 1 minute (1/60 = 0.0166...) instead of 1 second
SetTimerRate("SupportTroops_CIS", 0.01666)

--sets the time length of SupportTroops_CIS. 5 for 5 minutes (minutes because we changed the timer rate)
SetTimerValue("SupportTroops_CIS", 5)

--when a timer ends
OnTimerElapse(

--function that is called when the timer ends
function(timer)

--add 50 reinforcements to the CIS
AddReinforcements(2, 50)

--resets the length of timer SupportTroops_CIS
SetTimerValue("SupportTroops_CIS", 5)

--restart the SupportTroops_CIS timer
StartTimer("SupportTroops_CIS")

--displays the timer to all players. Note: this is not needed
ShowTimer("SupportTroops_CIS")

--end of the function. Note the comma.
end,

--the timer this OnTimerElapse() is 'connected' to
"SupportTroops_CIS"

--closes OnTimerElapse()
)

--start the SupportTroops_CIS timer
StartTimer("SupportTroops_CIS")

--displays the timer to all players. Note: this is not needed

ShowTimer("SupportTroops_CIS")
Ace_Azzameen_5
Jedi
Jedi
Posts: 1119
Joined: Sat Apr 23, 2005 8:52 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Post by Ace_Azzameen_5 »

Thanks a lot Zerted, I should be able get my other timer working too now.

After seeing it occur twice, I now see how the on command works. On Event function(functionname)]

I see some command's are not in the documentation. YOu have a list anywhere?
xwingguy

Post by xwingguy »

campaign scripts are the sources of the unlisted functions.
archer01

Post by archer01 »

Sorry I wasn't much help Ace_Azzameen_5, I'm terrible at explaining stuff.

I really wish there was better doc for the scripts...

Since winXP's "search for string" functionality is broken it makes finding the function call you need VERY difficult. Anyone know of any software out there that might be a good replacement for the windows search?


Also, is it really true that " CreateTimer("SupportTroops_CIS") " alone can create a timer? Wow, this LUA script language is really flexible.
Ace_Azzameen_5
Jedi
Jedi
Posts: 1119
Joined: Sat Apr 23, 2005 8:52 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Post by Ace_Azzameen_5 »

Np Archer. Zerted, where in the lua does this go, under what function? I tried a straight copy and paste into a fresh lua and I've got a crash at the end of load. And does it conflict with any gamemode rules? If I don't meet with success, i'LL edit this post and post my mission lua

Edit. The crash was probably cuased by something else. I was still getting munge errors presumnably from another bit of code, so I restored to a back up. THe back up didn't call some needed files.

Got it working. Thanks again.
Ace_Azzameen_5
Jedi
Jedi
Posts: 1119
Joined: Sat Apr 23, 2005 8:52 pm
Projects :: No Mod project currently.
Games I'm Playing :: I have not listed any games yet
xbox live or psn: No gamertag set

Post by Ace_Azzameen_5 »

Now, unfortuantely, I can't get any other code to work alongside the timer, should I stick my animation trigger before or after the timer and what ends or brackets do I need to add?

It turns out that I wasted a lot of troubleshooting on an uncapitalized 'k' in Killobject. . . I've got the basics of a primitive campaign now, just capturing areas, then moving on to others.
Last edited by Ace_Azzameen_5 on Fri Aug 04, 2006 11:31 am, edited 1 time in total.
User avatar
[RDH]Zerted
Gametoast Staff
Gametoast Staff
Posts: 2982
Joined: Sun Feb 26, 2006 7:36 am
Projects :: Bos Wars AI - a RTS game
Games I'm Playing :: SWBF2 and Bos Wars
xbox live or psn: No gamertag set
Location: USA
Contact:

Post by [RDH]Zerted »

I have a complete list. Just read through all the Luas.

CreateTimer() is a function call to some game code which creates the timer. Anything like XXX(XXX) or XXX() is a function call. Function calls sort of tell the computer to jump to another section of code, then come back and keep going when that code is finished.

I think the best place for the timer code would be in ScriptPostLoad() or in a function that is called from ScriptPostLoad().

1) Create a timer ( CreateTimer() ).
2) Set the timer's length ( SetTimerValue() ).
3) Set what happens when it ends ( OnTimerElapse() ).
4) Start the timer.

For every function you need an end
For every starting ( or need a closing )
Post Reply