Home   Help Search Login Register  

Author Topic: Get up punk! - setdamage 0 won't work  (Read 878 times)

0 Members and 1 Guest are viewing this topic.

hermano

  • Guest
Get up punk! - setdamage 0 won't work
« on: 05 Jul 2005, 13:07:39 »
Hi!
I working on a script to spawn civilians to towns. To speed this up I decided to use the same units repeatedly and set their damage to 0 whenever a citytrigger is activated.

Snippet (moving civ's to a far away position when a town is left):
Code: [Select]
_counter = 1
_nrOfCivilians = 9
#loop
   (_test select _counter) setdamage 0
   call format["%1 setpos civilianHome;%1 setbehaviour {safe};%1 setcaptive true;%1 allowfleeing 0.9;%1 domove civilianHome",(civNames select _counter)]
   call format["%1 removeAllEventhandlers {killed}",(civNames select _counter)]
   _counter = _counter + 1
?(_counter<=_nrOfCivilians):goto "loop"

where:
_test = [0,civ1,civ2,civ3,civ4,civ5,civ6,civ7,civ8,civ9]
civNames = ["","civ1","civ2","civ3","civ4","civ5","civ6","civ7","civ8","civ9"]
civilianHome is a position2d

The problem is they won't get up again, still seem to be dead, however the setpos command works ??? . I tried call format["%1 setdamage 0",(civNames select _counter)] before, this didn't work either.
They are non player units (so no problems caused by respawn), they were created with createUnit, but I tried it with editor set units to no avail. I also created another small test mission where radioalpha would set a civilian damage to 0, that worked fine.
So what's wrong here?
h

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Get up punk! - setdamage 0 won't work
« Reply #1 on: 05 Jul 2005, 14:37:18 »
Interesting way of using format ;)

But try using this:
Code: [Select]
_counter = 1
_nrOfCivilians = 9
#loop
   (_test select _counter) setdamage 0
   call {format["%1 setpos civilianHome;%1 setbehaviour {safe};%1 setcaptive true;%1 allowfleeing 0.9;%1 domove civilianHome",(civNames select _counter)]}
   call {format["%1 removeAllEventhandlers {killed}",(civNames select _counter)]}
   _counter = _counter + 1
?(_counter<=_nrOfCivilians):goto "loop"
Or something similar..
If you call something it has to be inside the curly brackets... afaik...

EDIT:
But why not use forEach since it's meant for this kind of use??
Would save you the whole loop...

Oh, and you might wanna add a small ~delay in the loop because OFP is not very fond of short delayless goto loops...
« Last Edit: 05 Jul 2005, 14:44:27 by HateR_Kint »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

hermano

  • Guest
Re:Get up punk! - setdamage 0 won't work
« Reply #2 on: 05 Jul 2005, 16:00:29 »
I learned using call format from the sow scripts (and they learned it from coc afaik). Can be very useful.
However, I solved the problem. The problem was the _test array (and I used something similar somewhere else in the script). The value civ1 did not help to point to the vehicle civ1.
Using format["%1 setdamage 0",(civNames select _counter)] solved it.
Thanks, this thread may be closed.
h

Edit:
HateR: format creates a string, which may be called then, its just like:
_string = _civname + " setdamage 0";call _string
(where _civname is a string)
« Last Edit: 05 Jul 2005, 16:13:59 by hermano »

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Get up punk! - setdamage 0 won't work
« Reply #3 on: 05 Jul 2005, 18:26:44 »
Yes, I'm aware of what format does..
It just never occurred to me that it could used like that, that's all...
« Last Edit: 05 Jul 2005, 18:27:07 by HateR_Kint »
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:Get up punk! - setdamage 0 won't work
« Reply #4 on: 05 Jul 2005, 20:53:24 »
Quote
Thanks, this thread may be closed.

Hermano, we don't often close threads.
As you started the thread, if you feel it is solved, feel free to press the 'Solved' button.   ;D


Planck
I know a little about a lot, and a lot about a little.

hermano

  • Guest
Re:Get up punk! - setdamage 0 won't work
« Reply #5 on: 06 Jul 2005, 12:03:13 »
Thanks planck, hadn't seen that button :).
HateR, please don't get me wrong, I didn't want to imply that you don't know the scripting commands well, I just wanted to clarify it.

It's good that this thread wasn't closed, the problem wasn't solved with the above solution (I was using a random number of civilians in my script, so living civ's spawned although I had killed some before, I added some rebels now and had to accept that it just didn't work).

The real problem:
setdamage and (setdammage) will not revitalize a unit under certain circumstances:
a) Respawn is enabled
b) the unit was registered as dead (killed handler triggered, alive unit = false)

You may still revitalze a unit before it is registered as dead if you setdamage 0 immediatly when the damage reaches 1. I wrote an immortality script as solution, it may be useful for others too, the unit will be revitalized and fake death then.:

[unitname] exec immortal.sqs
Code: [Select]
private ["_unit","_dead","_isCiv","_deathAnim","_dyingAnims"]
_unit = _this select 0
_dead = false;
_isCiv = ((side _unit) == civilian)
_dyingAnims = ["","Ver2","Ver3"]
#loop
@(damage _unit >= 1) || (_dead && !citySpawned)
_unit setdamage 0
?!citySpawned:goto "getReady"
?!_dead &&_isCiv:[] exec "spawn\civilianKill.sqs"
?!_dead:support = support -1;publicVariable "support"
_dead = true
_unit setCaptive true
_deathAnim = random 3;_deathAnim = _deathAnim - ( _deathAnim % 1 )
call format["_unit playmove {CombatDying%1}",(_dyingAnims select _deathAnim)]
@unitready _unit
call format ["_unit switchMove {CombatDead%1}",(_dyingAnims select _deathAnim)]
goto "loop"

#getReady
_dead = false
_unit switchMove "fxnone"
?(!_isCiv):_unit setCaptive false
goto "loop"

citySpawned is a global variable that will be set false whenever a city is left, set true whenever a city is entered (here: city left -> unit will get up again). 'spawn\civilianKill.sqs' is a script that was executed by a killed eventhandler before.
You may ignore the 'support' thing, it's only important for my mission.

h

hermano

  • Guest
Re:Get up punk! - setdamage 0 won't work
« Reply #6 on: 11 Jul 2005, 12:51:15 »
There is still a problem in the script above, the unit may die while playing it's deathmove, this will happen often if there are a lot of explosions, @unitready should be replaced by a loop that runs until unitready==true, in that loop check for the units damage.
h