Home   Help Search Login Register  

Author Topic: Using the "hit" eventhandler  (Read 1345 times)

0 Members and 2 Guests are viewing this topic.

Baphomet

  • Guest
Using the "hit" eventhandler
« on: 26 Oct 2003, 03:57:25 »
Could anyone tell me how I could execute vektorboson's tailrotor script using the hit eventhandler? I'm not too farmiliar with eventhandlers especially the syntax used for it to actually work.

I'm not looking for anything fancy. I know hit relies on the following criteria "Hit" object:causedBy,scalar:howMuch.

I'm more or less trying to get it to execute the script once a helo takes so much damage.

McFly

  • Guest
Re:Using the "hit" eventhandler
« Reply #1 on: 26 Oct 2003, 10:21:29 »
Use a trigger.  Make it cover the map and be of type Switch.

In condition:
? getdamage helo >= 0.5

In activation:
[helo, 0, 0] exec "tailrotor.sqs"

Using an addEventHandler would require a seperate script to continually check the helo's health, thus there's no reason not to do the same with a trigger.  The "hit" event handler doesn't return the object's health, only the amount of damage done, and by whom.

Baphomet

  • Guest
Re:Using the "hit" eventhandler
« Reply #2 on: 28 Oct 2003, 00:40:23 »
Crap! I wanted to somehow use an eventhandler to integrate it into a self-contained addon.

Unnamed

  • Guest
Re:Using the "hit" eventhandler
« Reply #3 on: 28 Oct 2003, 01:42:41 »
Put McFly's code in a script called HeloWatch.sqs or something:

Code: [Select]
_helo=This select 0

#Loop

~1

? getdamage _helo >= 0.5 : goto "Loop"

[_helo,0,0] exec "tailrotor.sqs"

Then just add this to the config.cpp of the Helicopter you want in your addon:

Code: [Select]
class EventHandlers
     {
          init="[_This Select 0] Exec HeloWatch.sqs";
       };

You might want to check things like engine on e.t.c aswell.

You could probably use the Hit event using McFly's script as it is, without the loop. Best search the forum for more info on the Hit event, I think there is more to it than meets the eye?

Offline Spinor

  • Members
  • *
  • I'm a llama!
    • The chain of command
Re:Using the "hit" eventhandler
« Reply #4 on: 28 Oct 2003, 18:25:59 »
I would strongly suggest to use an event handler instead of a trigger or a looping
script, as it uses much less CPU. If it is true what Suma said, it should even use
none, because it is strictly eventbased, i.e. once an object is hit, OFP looks
if there is a "Hit" handler and executes the respective code string. A loop script
or a trigger has to constantly the damage of the helo.

In script, the command should look as follows:
Code: [Select]
helo addEventHandler["Hit",{_obj=_this select 0; _by=_this select 1; _dam=_this select 2; [_obj,0,0] exec "tailrotor.sqs"}]Within the code string, _obj is the hitted helo, _by contains the unit that hit it and
_dam is the amount of damage caused. You may want to add a criteria like
_dam > 0.3 for actually executing the tailrotor script.

I

Baphomet

  • Guest
Re:Using the "hit" eventhandler
« Reply #5 on: 29 Oct 2003, 00:58:42 »
Thanks everyone for their help. This was sort of an uncommon subject so I wasn't sure how much feedback I'd get.

Anyhow. Yeah those looping scripts can be a real resource drainer, which is kinda why I wanted to use the hit eventhandler to begin with, I'm performance conscious. As far as adding damage criteria to the eventhandler. That might pose some difficulty, however I'm going to fiddle around with it and see what happens. I'm not too knowledgable with the syntax of these sorts of things.


-Edit-

Hm. 'a' encountered instead of '='   is there anywhere I can get a list of the proper syntax for the hit eventhandler. I cut and pasted yours spinor but again I don't even know how it's supposed to be written... I thought there was an eventhandler reference on ofpec but I searched and couldn't find it.

This hit eventhandler from that blood mod looks very different, and it doesn't even have any arguments from what I see... so I'm a bit confuzzled

hit="_this exec ""\OFPEC_Blood\blood_squirt.sqs""";


-Edit-

I've tested out this init for the eventhandler :
hit="_this exec  ""\altcargopack\effects\tailrotor.sqs""";
It works only it does complain about the _random argument in the script not being present in the initialization which is annoying and I hope I can eliminate.

the two other arguments in the rotor script (bool: random kills on impact, scalar: up to how many killed) which I think if I place in the init conflict with the other argument that normally accompany the hit eventhandler (scalar: how much)

for example : hit="[_this,1,3] exec  

""\altcargopack\effects\tailrotor.sqs""";

... just gives me an error and the script doesn't run. Maybe I can get rid of the random kill variable somehow. I was only just casually interested in getting this to work before. Now that I've gotten some help... and It partially works. I really want to see it through.
« Last Edit: 29 Oct 2003, 03:02:06 by Baphomet »

Baphomet

  • Guest
Re:Using the "hit" eventhandler
« Reply #6 on: 29 Oct 2003, 03:42:58 »
Ok. I think I'm getting somewhere with this, I commented out the other arguments from the tailrotor script and their related code and added  this into the script itself since I wasn't sure about doing something similar in effect in just the eventhandler... if it's even possible. I dunno. Heh.:

_health = getdammage _heli

and

?_health < 0.4: exit

So basically it doesn't run unless so much damage has been done. However I tried making something to prevent the script from running once the helo had hit the ground and wasn't flying anywhere. Since it's kind of pointless if it's not flying. I can't seem to figure that out though.

Unnamed

  • Guest
Re:Using the "hit" eventhandler
« Reply #7 on: 29 Oct 2003, 04:23:52 »
Quote
Yeah those looping scripts can be a real resource drainer

Perhaps in the days of the Spectrum 1k, but unless your looking at catering for a huge helicopter fleet then a one second loop to check damage will go unnoticed.

Saying that, if it was my script I would go for the hit event for the sake of elegance alone. Not that I have ever played around with it, like I have with the init event. So I avoided referring to it directly.

Quote
This hit eventhandler from that blood mod looks very different, and it doesn't even have any arguments from what I see... so I'm a bit confuzzled

hit="_this exec ""\OFPEC_Blood\blood_squirt.sqs""";

Again cant say much about the hit event, but if you see _This exec then it's probably safe to assume _This is an array.

Code: [Select]
_Params=[1,2,4]
_Params exec "Icantcount.sqs"

Is the same as:

Code: [Select]
[1,2,4] exec "Icantcount.sqs"
You have to watch out when using the init event from an addon. _This in an addon is an array, that's why in the example I gave I used (_This select 0) to pass an individual unit to the script. I think it's to cater for multiple units defined as a group?

Although I can only guess at that being the cause of the parameter problem you mentioned. But it caused me a few headaches.

Quote
However I tried making something to prevent the script from running once the helo had hit the ground and wasn't flying anywhere. Since it's kind of pointless if it's not flying. I can't seem to figure that out though.

You could try a combination of the event handle "Engine" bool:engineState and the height above ground using GetPos and possible speed (Assuming a busted tail rotor will mean you cant remain stationary while flying)?