Home   Help Search Login Register  

Author Topic: How im suposed to handle unit handles when unit dies?  (Read 1398 times)

0 Members and 1 Guest are viewing this topic.

GeneralCoder

  • Guest
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

Offline toadlife

  • OFPEC Old Skool
  • Former Staff
  • ****
  • Official OFP Editing Center Toad
    • toadlife.net
Re:How im suposed to handle unit handles when unit dies?
« Reply #1 on: 04 Mar 2003, 22:01:13 »
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)


Quote
_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"
"Whenever you want information on the 'net, don't ask a question; just post a wrong answer." -- Cancer Omega.

GeneralCoder

  • Guest
Re:How im suposed to handle unit handles when unit dies?
« Reply #2 on: 05 Mar 2003, 13:34:35 »
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...

Offline sbsmac

  • Members
  • *
  • I'm a llama!
Re:How im suposed to handle unit handles when unit dies?
« Reply #3 on: 07 Sep 2003, 17:25:15 »
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 :-(


GeneralCoder

  • Guest
Re:How im suposed to handle unit handles when unit dies?
« Reply #4 on: 08 Sep 2003, 21:25:19 »
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)
« Last Edit: 09 Sep 2003, 12:57:05 by GeneralCoder »