Home   Help Search Login Register  

Author Topic: dammage add  (Read 679 times)

0 Members and 1 Guest are viewing this topic.

Offline 456820

  • Contributing Member
  • **
dammage add
« on: 27 Jun 2005, 17:06:50 »
okay ive made a script wich will increase your dammage if you dont get to a medic fast enough for example regular ofp if you get shot you will stay the same dammage but now if you get shot in the torso it will kill you quicker then if youve been shot in the legs or hands also adding to realism
but im not sure it works i dont seem to die im using a dammaged event handler would this be the best one to use as i can detect where the player has been hit eg arms hands legs and head but head shot means you would be dead
so anyway here it is

Code: [Select]
_dammunit = _this select 0
_wichpart = _this select 1
_dammamount = getdammage _dammunit

#dammagecheck
? _dammamount <= 0.3: goto "exit"
? _dammamount >= 0.3 and _wichpart == "nohy" : goto "leghit"
? _dammamount >= 0.3 and _wichpart == "ruce" : goto "handhit"
? _dammamount >= 0.3 and _wichpart == "telo" : goto "torsohit"

#leghit
? _dammamount < _dammunit : goto "exit"
_dammunit setdammage (_dammamount + 0.04)
~2
leg = true
goto "leghit"
? leg : goto "leghit"
_dammunit groupchat "AHHH MY LEGS."
goto "leghit"

#handhit
? _dammamount < _dammunit : goto "exit"
_dammunit setdammage (_dammamount + 0.02)
~2
hand = true
goto "handhit"
? hand : goto "handhit"
_dammunit groupchat "AHHH MY HANDS, IM HIT."
goto "handhit"

#torsohit
? _dammamount < _dammunit : goto "exit"
_dammunit setdammage (_dammamount + 0.06)
~3
torso = true
goto "torsohit"
? torso : goto "torsohit"
_dammunit groupchat "AHHH IM HIT IN MY CHEST."
goto "torsohit"

#exit
EXIT

that should be right but im not sure if the event handler is correct i dont fully understand it but im pretty sure ive done it right
ive called the script from the init.sqs like this
Code: [Select]
player AddEventHandler ["dammaged",{_this exec "dammage.sqs"}]so when hes dammaged it should activate the script right ?
but it doesnt seem to

A tut on event handlers says this

Quote
_this select 0 : who's damaged ;
_this select 1 : what part of the body has been hit ("nohy" for the legs, "ruce" for the hands, "hlava" for the head, "telo" for the torso).
_this select 2 : scalar damage value ;
This EH does NOT return who has shot.

and General barron said this about it
Quote
From messing around with the 'dammaged' EH, I've noticed it works in the following way:

When a part of a unit's body is damaged enough (usually when it turns 'bloody', like when the arms or legs turn bloody), then the EH executes. If more than one part of the body is damaged in one hit (like from a grenade blast, which hits all body parts, or a bullet to the chest, which usually hits the chest and the arms), then the EH will execute once for each body part damaged.

Now, once a certain body part has been 'dammaged' and executes the EH, the EH will not execute again for that body part. Eg, if a unit's legs are hit and the EH executes for the legs, shooting the unit in the legs again will not execute the EH again, no matter how much damage is done. Only by using the 'setdammage' command (unit setdammage 0) on the unit can the EH fire again for that body part.

Unfortunately the above facts make the 'dammaged' EH much less useful than it could be, in my opinion.

does anyone know why it might not be working

Offline ACF

  • Members
  • *
  • Llama?? Ain't that French for tanks?
Re:dammage add
« Reply #1 on: 27 Jun 2005, 19:00:25 »
I'll use one sub-routine as the example as they're all the same:

Code: [Select]
#leghit
?(_dammamount < _dammunit): goto "exit"           << Problem 3
_dammunit setdammage (_dammamount + 0.04)      << Problem 1
~2
leg = true                                      << Problem 2
goto "leghit"
? leg : goto "leghit"                          << Problem 2
_dammunit groupchat "AHHH MY LEGS."
goto "leghit"

Problem 1 is that the loop is not increasing the unit's damage.  Every time it loops it sets the damage to a constant value of _dammamount + 0.04 but both of these values are constant.  What you want to do is add 0.04 to the unit's current damage each time so the line should be:
Code: [Select]
_dammunit setdammage (0.04 + getdammage _dammunit)
Problem 2 is more of an observation because there's no effect: the lines
leg = true and ? leg : goto "leghit" are redundant, the script will always goto "leghit"

Problem 3 is how to stop the loop.  Problem 3a is the line:
?(_dammamount < _dammunit): goto "exit"
You are comparing chalk and cheese, well, a unit to its damage or an object to a value.
Problem 3b is that you need to see a reduction in damage as the unit is healed, i.e:

If damagenow < damagewhenIlastincremented then stoptheloop

A fix would be:

Code: [Select]
#leghit
_dammunit groupchat "AHHH MY LEGS."
#leghitloop
~2
; check current damage against last increase to see if healing
? (Dammage _dammunit < _dammamount): goto "exit"
; increment unit's damage
_dammunit setdammage (0.04 + Dammage _dammunit)
; record current damage to check for healing
_dammamount = Dammage _dammunit
goto "leghitloop"

It could be reduced a bit more but the clarity might get lost.

Once you've got your head round that bit, you could reduce your script to one loop by using _wichpart to set a variable, say, _bloodloss to 0.02, 0.04 or 0.06 and use the line:
Code: [Select]
_dammunit setdammage ( _bloodloss + Dammage _dammunit)
Hope it helps!

Offline 456820

  • Contributing Member
  • **
Re:dammage add
« Reply #2 on: 27 Jun 2005, 19:13:37 »
ahh tnakyou i didnt relise that much was wrong with it.
The
leg = true and ? leg : goto "leghit"
that checks if its been there before and if so it wont ply the text underneath so if not having it it will repeat the text all the time and wont stop until the script does so that wasnt actually wrong
But thanks alot with the rest of it ill fix it now
hope it will work

Offline bedges

  • Administrator
  • *****
    • OFPEC The Editing Center
Re:dammage add
« Reply #3 on: 27 Jun 2005, 20:36:07 »
Quote
leg = true and ? leg : goto "leghit"
that checks if its been there before and if so it wont ply the text underneath so if not having it it will repeat the text all the time and wont stop until the script does so that wasnt actually wrong

actually, as acf pointed out, the lines above are never reached at all, because they're preceded by 'goto "leghit"', which will repeat the loop whether it's been there or not.

if you set the 'leg' variable after the text has been printed and then run the loop, then it will print only once...