Home   Help Search Login Register  

Author Topic: Cancel script if condition is met  (Read 1378 times)

0 Members and 1 Guest are viewing this topic.

Offline Clayborne

  • Members
  • *
Cancel script if condition is met
« on: 09 May 2009, 19:28:15 »
Hey, searched for this but came up with some unanswered topics.

I am using an artillery script and I want it to be cancelled if a particular unit is destroyed.

Basically what I have is the artillery script dropping single shells around the target, but not guaranteed to hit. If the first shell destroys it, I would like the script to stop there rather than dropping the remaining shells.

I found another thread with a kind of similar problem where someone suggested adding the following lines to a script:

Code: [Select]
if (!alive radar) then goto "end"

#end
exit

I tried this but I'm not sure where to add the lines. The commands are either ignored completely or end up cancelling the script before it even begins.

Here is the main body of the script I am using:

Code: [Select]
_counter=0
~5
#beg


~_delay

_cx = _Explosion select 0
_cy = _Explosion select 1
_cz = _Explosion select 2

_cx = _cx + random _spread
_cy = _cy + random _spread2
;this bit lifts the bomb to a high altitude so you can see it falling
_cz = _cz + 200

_tempObj = _AmmoType camCreate[_cx, _cy, _cz]
~0.01
_tempObj = objNull

_counter = _counter + 1

?(_counter == _Shells):exit

goto "beg"

Any suggestions appreciated!

Offline savedbygrace

  • Intel Depot
  • Administrator
  • *****
  • Be swift to hear...slow to speak...slow to wrath.
Re: Cancel script if condition is met
« Reply #1 on: 09 May 2009, 23:32:42 »
Code: [Select]
?!(alive radar) then goto "end"Just relocate that exclamation point.

Offline Clayborne

  • Members
  • *
Re: Cancel script if condition is met
« Reply #2 on: 09 May 2009, 23:59:37 »
Well ok, but now where do I put that line?

I did this:

_counter=0
~5
#beg

?!(alive radar):exit

~_delay

_cx = _Explosion select 0
_cy = _Explosion select 1
_cz = _Explosion select 2

_cx = _cx + random _spread
_cy = _cy + random _spread2
;this bit lifts the bomb to a high altitude so you can see it falling
_cz = _cz + 200

_tempObj = _AmmoType camCreate[_cx, _cy, _cz]
~0.01
_tempObj = objNull

_counter = _counter + 1

?(_counter == _Shells):exit

goto "beg"


but the script ignores it, like it doesn't know what 'radar' is. Do I need to set the unit as a variable or something?

Walter_E_Kurtz

  • Guest
Re: Cancel script if condition is met
« Reply #3 on: 10 May 2009, 01:02:51 »
That's the right place to put it (though personally I'd have it after the delay) - every time the script loops to #beg it will check if radar is still alive and discontinue if it is not.

What have you got named "radar" in the mission editor? When you place a unit / vehicle / building, there is a box to fill in next to Name: (no quotations needed)

Another possibility is that the game doesn't like the name "radar" - it might be used for something specific within the game-engine. Try alternatives such as "radar1" in the mission editor and script.

Offline Clayborne

  • Members
  • *
Re: Cancel script if condition is met
« Reply #4 on: 10 May 2009, 01:59:06 »
Huh. You were right. I changed the name of the unit from 'radar' to 'radar1a' and now it works fine.

I swear this game just likes to be annoying sometimes.

Thanks for the help fellas.

EDIT

Actually I have another question. Can you have a section of the script that does not run unless you tell it to?

In the script there is there line

?(_counter == _Shells):exit


meaning "if the maximum number of shells has been fired, then exit the script".

But now I would like that to be "if the maximum number of shells has been fired, but the target has not been hit, then set a counter such as targetmissed = 1, and exit.
« Last Edit: 10 May 2009, 22:03:48 by Clayborne »

Walter_E_Kurtz

  • Guest
Re: Cancel script if condition is met
« Reply #5 on: 11 May 2009, 00:42:58 »
If that's all you want to do, you can add another section
Code: [Select]
?(_counter == _Shells): goto "end"

goto "beg"

#end
if (alive radar1a) then {targetmissed = 1}
exit

NB. in the above if line it is not possible to replace 'if' with '?' and 'then' with ':' - (I think it's because of the curly brackets).

Offline Clayborne

  • Members
  • *
Re: Cancel script if condition is met
« Reply #6 on: 11 May 2009, 23:12:58 »
Aaah, right. I did actually try that line if (alive radar1a) then {targetmissed = 1}, but I guess I didn't have the syntax right.

Thanks alot, that is a big help!