OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting General => Topic started by: Clayborne 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:
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:
_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!
-
?!(alive radar) then goto "end"Just relocate that exclamation point.
-
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?
-
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.
-
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.
-
If that's all you want to do, you can add another section
?(_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).
-
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!