Home   Help Search Login Register  

Author Topic: How to execute script once player is hit?  (Read 1309 times)

0 Members and 1 Guest are viewing this topic.

Offline Krieg

  • Mission Maker
  • Members
  • *
  • Who dares wins.
How to execute script once player is hit?
« on: 02 Dec 2009, 08:45:50 »
I am working on a script that needs to be activated once player is hit.
I tried adding to script:
Code: [Select]
#Loop
?((damage player) > 0.3) : goto Script
goto Loop

#Script

And I tried adding a trigger:
Code: [Select]
0/0
Anybody
Once
Not Present
Condition: damage player > 0.3
On Activation: this exec "Script.sqs"

But none of that worked. Script got executed even if player had 0 damage.
Can anyone help with this?

Thank you,
Krieg

Edit: Never mind, I figured out what was wrong.
« Last Edit: 02 Dec 2009, 09:26:04 by Krieg »
If you see a light at the end of the tunnel, then it's probably an enemy tank.

Offline eegore

  • Members
  • *
Re: How to execute script once player is hit?
« Reply #1 on: 02 Dec 2009, 14:29:40 »

  Would you mind informing us of how you fixed your problem?

Walter_E_Kurtz

  • Guest
Re: How to execute script once player is hit?
« Reply #2 on: 02 Dec 2009, 15:52:00 »
The more elegant method is to use EventHandlers as these react much faster than triggers. Once you understand them, you can add much more interesting and complex effects to your missions. I suggest you look at the EventHandler Tutorial by Igor Drukov.

Basically you'd add a line to your init.sqs

player addEventHandler ["Hit", {_this exec "Script.sqs"}]

This would run Script.sqs on every occasion that the player is shot. It also provides more information, for instance who the shooter was, than could be gleaned using triggers.

Offline Krieg

  • Mission Maker
  • Members
  • *
  • Who dares wins.
Re: How to execute script once player is hit?
« Reply #3 on: 02 Dec 2009, 18:25:59 »
@eegore

I forgot to remove following from player's init:
Code: [Select]
this exec "script.sqs"
I previously tested it, to see if script works, and forgot to remove it. Pretty newbish error ;).
But still, adding those lines into script did not work, for some odd reason.

@Walter_E_Kurtz

I'll look into that, thanks!
Although, the script itself needs to be activated only once.
Because it is stylized death script, where you basically fall to the ground (using playMove command), hear you heart-beats, have a few black-outs and then (if you do not receive medical treatment meanwhile), die.
I am making it for a mission I am working on ("Hellfire").

I am still having a bit of a problem. Every time I get hit, I die, script gets triggered anyways, and I have BIS death scene mixed with my own. I tried adding "player setDammage 0" to the script, but apparently it does not work on already killed units.
If you see a light at the end of the tunnel, then it's probably an enemy tank.

Offline eegore

  • Members
  • *
Re: How to execute script once player is hit?
« Reply #4 on: 03 Dec 2009, 08:02:59 »

  Ahh the old forgot to pull the init: script mistake.  I've done tht myself.

  From what I understand you can't revive dead player units, but maybe activating the script if damage reaches above .5?  That way a kill shot drops you dead, but a shot that you could potentially recover from will play your script. 

Offline Krieg

  • Mission Maker
  • Members
  • *
  • Who dares wins.
Re: How to execute script once player is hit?
« Reply #5 on: 03 Dec 2009, 08:56:26 »
Thanks for the suggestion, eegore, I will look into that.
If you see a light at the end of the tunnel, then it's probably an enemy tank.

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: How to execute script once player is hit?
« Reply #6 on: 03 Dec 2009, 16:56:27 »
Quote
but maybe activating the script if damage reaches above .5?
That doesn't help because when you die the damage goes above 0.5, to 1, and the script gets executed..


You should make a check in the beginning of the script that will exit the script if the unit is dead (I'm basing this on the assumption that you would be using the dammaged or hit eventhandler which is the only reasonable way to do this).
Something like:
Code: [Select]
? ((damage player) < 0.3 || !(alive player)): exit That should make the script exit when the player is hit and has less than 0.3 of damage or is dead (non tested though)..
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline Krieg

  • Mission Maker
  • Members
  • *
  • Who dares wins.
Re: How to execute script once player is hit?
« Reply #7 on: 03 Dec 2009, 18:28:27 »
Thanks h-!
Edit: That solved my problem, thanks again h-!
« Last Edit: 03 Dec 2009, 18:41:50 by Krieg »
If you see a light at the end of the tunnel, then it's probably an enemy tank.