OFPEC Forum
Editors Depot - Mission Editing and Scripting => OFP - Editing/Scripting Multiplayer => Topic started by: GeneralCoder on 04 Mar 2003, 20:48:51
-
Please look this code:
; _this would be some soldier
_man = _this
Now I have 'handle' to the unit but if unit dies _man begomes invalid so how im suposed handle that? Im wery confused, are you? :o ??? :-X
-
if you have resistance you can use the call command to access a unit even after he respawns. THe old method before the call command was to use two triggers - one with the condition @!alive soldier, to detect when he died and one with the condition @alive soldier to access him after he respawned. The call comamnd alieviates the need to use a triggers, and can make things more effecient and easier.
Here is a very very simple respawn script, which is based on the one in the ed depot here: http://www.ofpec.com/editors/resource_view.php?id=301
If the soldier were named east1, you would init this script like so:
"east1" exec "script.sqs" <--notice the quotes around the name (they are required)
_name = _this
_unit = call format["%1",_name]
#loop
@!alive _unit
@alive call format["%1",_name]
_unit = call format["%1",_name]
_c = 0
while "_c < 4" do {_unit addmagazine {ak74}}
goto "loop"
-
if you have resistance you can use the call command to access a unit even after he respawns. THe old method before the call command was to use two triggers - one with the condition @!alive soldier, to detect when he died and one with the condition @alive soldier to access him after he respawned. The call comamnd alieviates the need to use a triggers, and can make things more effecient and easier.
Here is a very very simple respawn script, which is based on the one in the ed depot here: http://www.ofpec.com/editors/resource_view.php?id=301
If the soldier were named east1, you would init this script like so:
"east1" exec "script.sqs" <--notice the quotes around the name (they are required)
Thank you, I see what can I make from these...
-
Maybe I'm missing something but this seems overly complex :-) Since _name is a string in the first place, the format operation serves only to return its value. You should be able to just write...
_name = _this
_unit = call _name
#loop
@!alive _unit
@alive call _name
_unit = call _name
_c = 0
while "_c < 4" do {_unit addmagazine {ak74}}
goto "loop"
Of course, it would also be nice to be able to automatically obtain _name from the object itself but the 'name' function returns something completely different :-(
-
Maybe I'm missing something but this seems overly complex :-) Since _name is a string in the first place, the format operation serves only to return its value. You should be able to just write...
_name = _this
_unit = call _name
#loop
@!alive _unit
@alive call _name
_unit = call _name
_c = 0
while "_c < 4" do {_unit addmagazine {ak74}}
goto "loop"
Of course, it would also be nice to be able to automatically obtain _name from the object itself but the 'name' function returns something completely different :-(
Onother good way is to have group in the script like this:
_group = _this
then check when unit is dead when looping thru units
_man = units _group select _i
?(alive _man ): deads = deads +
and then we can now when he respawns!
?(alive _man && _man in deads): deads = deads - [_i]; _man exec"respawn.sqs"
obiviously there's not all of the code but you got the idea.
EDIT:
Changed damage to alive becose damage isn't always 1 even soldiers is actualy dead? (my damage was 0.7 and I we're dead)