Home   Help Search Login Register  

Author Topic: Event handlers.  (Read 803 times)

0 Members and 4 Guests are viewing this topic.

Red Ant

  • Guest
Event handlers.
« on: 06 Sep 2004, 17:55:59 »
Hi there,

I'm trying to write a script that makes destroying tanks a little more realistic. IMHO tanks shouldn't invariably blow up when they're destroyed, thereby killing anyone within 50 feet or so. As I see it, tanks blow up sometimes (ammo storage ignited, fuel explodes, etc) but not always. Anyway, after some thinking I have come to the conclusion that there are (at least) two possible ways to make this work (theoretically at least).

1) Poll the damage of the tank in very short intervals. When its damage == 1, immediately remove all fuel and ammo from the tank (I think that's what makes a tank explode in OFP ... empty tanks just die silently). You have to poll in VERY short intervals, because if you're not quick enough the tank may already be in the process of exploding by the time you go about removing any explosive stuff from it. That's why I'm unsure of whether this approach is feasible.

2) Event handlers. Register a function that gets called when the tank is killed.
Code: [Select]
_oSomeTank addEventHandler[ "killed", { // insert call to function here } ]

This event fires (hopefully) __AS__THE__TANK__IS__BEING__KILLED, calling the function that removes any fuel and ammo from the tank. However, I'm not at all sure that the event really fires before the tank starts to explode. If it doesn't then of course this is a no-go as well. Does anyone know about good reference material about event handlers? Because my experiments with the killed-event have fruitless so far. Also I find that some of the available event handlers (hit, dammaged) totally don't have the argument interface BIS says they do (obsolete reference material?). For example according to their scripting reference the "hit" eventhandler should return the amount of damage inflicted whereas in reality it returns an object reference to the shooter as well as one to the object having been hit IIRC.  ???
Right, I'm getting carried away ... I was really wanting to ask if anyone has some ideas on how to prevent tanks from exploding.

Regards,

ant

Offline dmakatra

  • Members
  • *
  • Better known as Armsty
Re:Event handlers.
« Reply #1 on: 06 Sep 2004, 19:45:22 »
There's a tutorial about EH in the ed depot. Check that out.

:beat: *Gets Shot* :beat:

Offline Mud_Spike

  • Contributing Member
  • **
Re:Event handlers.
« Reply #2 on: 06 Sep 2004, 20:05:13 »
I like the idea so I tried it out and it works good with the "hit" event.
The script, tankKill.sqs:
Code: [Select]
_tank = _this select 0
if (GetDammage _tank >= 0.95) then { removeAllWeapons _tank ; _tank SetFuel 0 }

Set up your EH like so:
Code: [Select]
myTank addEventHandler ["hit", {_this exec "tankKill.sqs"}]


(Syntax not g.)

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:Event handlers.
« Reply #3 on: 06 Sep 2004, 21:19:51 »
And, if you want to randomise the stuff a bit make this small alteration:
Code: [Select]
_tank = _this select 0
_rand = random 200
if (damage _tank >= .95 && _rand > 100) then { removeAllWeapons _tank ; _tank SetFuel 0 }

Oh, and damage is a command, not just a word in there.. :P
And, the random 200 is just a suggestion...

Or, you could try to insert all the stuff in the eventHandler line (this way is much reliable under lag..):
Code: [Select]
this addEventHandler ["hit",{_rand = 200; if (damage this >= .95 && _rand > 100) then {removeAllWeapons this; this setFuel 0}}] But this syntax is not guaranteed... :P
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Red Ant

  • Guest
Re:Event handlers.
« Reply #4 on: 08 Sep 2004, 17:19:24 »
There's a tutorial about EH in the ed depot. Check that out.

:beat: *Gets Shot* :beat:

Hmmm, I can't seem to expand the menus on the editor's depot page. I click on the thing and the page reloads, but the menus are still collapsed. :(


P.S. Thanks for the snippets. guys. I'll try that out.
« Last Edit: 08 Sep 2004, 17:20:47 by Red Ant »

Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:Event handlers.
« Reply #5 on: 08 Sep 2004, 17:48:33 »
The non-expanding menus are a brower/firewall issue.  It's come up a few times on the OFPEC comments board, though I can't remember if anybody discovered a fix.
Plenty of reviewed ArmA missions for you to play

olseric

  • Guest
Re:Event handlers.
« Reply #6 on: 10 Sep 2004, 13:32:46 »
The only fix I know of is to logout and then log back in when you're done. ;)