Home   Help Search Login Register  

Author Topic: A limit on EventHandlers?  (Read 654 times)

0 Members and 1 Guest are viewing this topic.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
A limit on EventHandlers?
« on: 16 Aug 2004, 22:02:39 »
As a result of a previous post I realised a unit could be made un-killable by putting the following in its initialisation field:

Code: [Select]
this addEventHandler ["killed",{this setdammage 0}];this addEventHandler ["Hit",{this setdammage 0}]  

I wanted to test the defences in a mission to distruction so I created several groups of enemy infantry, each of which had this in their initialisation field.  The result was a whole series of error messages of the type: 'setdammage 0; Boolean expected' and a whole load of infantry that was anything but un-killable.  If I kept it to one or two units it worked fine - but not for large numbers.  

Is there a known upper limit on the number of Event Handlers possible in a mission?


Offline macguba

  • Former Staff
  • ****
    • macguba's operation flashpoint page
Re:A limit on EventHandlers?
« Reply #1 on: 16 Aug 2004, 22:16:32 »
Isn't it

_this

rather than

this


I am not aware of an upper limit except that the lag will eventually kick in.

This eventhandler trick only works properly on AI:  on a human player it will bring you back to life, but sometimes only after the onplayerkilled script has started.    

You also sometimes get confusion when multiple hits occur in very close succession, particularly if some are from explosions rather than bullets.
« Last Edit: 16 Aug 2004, 22:20:28 by macguba »
Plenty of reviewed ArmA missions for you to play

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:A limit on EventHandlers?
« Reply #2 on: 16 Aug 2004, 22:26:22 »
I don't believe so.  This is in the init field of a unit so 'this' specifies that unit.  

My reading of the Comref is that '_this' for the event "killed" will return the unit that did the killing and '_this' for the event "Hit" will return the object that did the hitting and a measure of how much damaged was caused.  But I may be wrong.  Here is the extract I am referring to:

Quote
_this, argument types and meaning are defined below.
   
    "Killed" object:killer
    "Hit" object:causedBy,scalar:howMuch

Anyway the code in my post is a direct copy and paste from my test mission, and it works.

Yes I tried this code on the player - very disappointing, but on AI it works a treat, provided I keep it down to a few units.
« Last Edit: 16 Aug 2004, 22:27:56 by THobson »

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re:A limit on EventHandlers?
« Reply #3 on: 16 Aug 2004, 22:39:37 »
I think what macguba meant was:

Code: [Select]
this addEventHandler ["killed",{this setdammage 0}];this addEventHandler ["Hit",{this setdammage 0}]

should be changed to:

this addEventHandler ["killed",{_this setdammage 0}];this addEventHandler ["Hit",{_this setdammage 0}]


Command reference states:

Each handler receives arguments in _this.


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

Offline Mud_Spike

  • Contributing Member
  • **
Re:A limit on EventHandlers?
« Reply #4 on: 16 Aug 2004, 22:47:53 »
macguba is right, err, actually, you are both right. :)

'this' in the init-field scope is not necessarily the same as 'this' in the eventHandler callback, so using it in a code-string is usually a bad idea.

However, for the Fired and Hit events, 'this' refers to the unit being hit/killed,
and '_this' refers to the arguments you pasted from the ComRef.

Edit, to clarify:
Hit _this: [hitUnit, hitter, damage]
Killed _this: [hitUnit, hitter]
Hit this: hitUnit
Killed this: hitUnit
« Last Edit: 16 Aug 2004, 22:50:28 by Mud_Spike »

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:A limit on EventHandlers?
« Reply #5 on: 16 Aug 2004, 22:48:30 »
Planck:
I thought that is what he meant, but I am afraid that is not correct, it generates a syntax error for one thing.  _this is an argument returned by the event handler to the code that is executed by the event handler.  

In fact I just tried putting the following in the init field of a unit

Code: [Select]
this addEventHandler ["Hit",{_this select 1 setdammage 1}]  

And as soon as I shot him I promptly died!!!

Totally neat!!!

macguba:
Now look what you have started.

I am going to bed now.  Speak to all tomorrow
« Last Edit: 16 Aug 2004, 22:54:38 by THobson »

Offline LCD

  • Former Staff
  • ****
    • Everon Cartel
Re:A limit on EventHandlers?
« Reply #6 on: 16 Aug 2004, 22:53:13 »
the command referance tells u exactly what the eventhandler will give u wen it fired and it also tells u what type of variable it is, 4 example the hit event

Quote
"Hit" object:causedBy,scalar:howMuch

_this select 0 : gives u the object the eventhandler is attached 2 (this is true 4 all eventhandlers
_this select 1 : gives u the object that cused it : object - its written up there object:causedBy
_this select 2 : gives u how much u injured it : scalar - scalar:howMuch

LCD OUT
"guess being the community has downsides .." - cheetah
Help Perfecting Da Next Best Thing - O-Team Beta

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re:A limit on EventHandlers?
« Reply #7 on: 17 Aug 2004, 16:12:42 »
Now I'm a bit confused what is going on in here ;)

Quote
Each handler receives arguments in _this
Nope. EventHandlers do not receive anything.
They return those arguments... :P

So yes, when using the setDamage 0, use this.
When executing a script, use _this (if needed...)

And once again, this (in the units init field) = the unit
_this = array returned by the eventHandler...


And afaik there's no limits for the number of EHs...
Macguba is right though, OFP can get very confused sometimes when lotsa simultaneous things are happening...
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline THobson

  • OFPEC Patron
  • Former Staff
  • ****
Re:A limit on EventHandlers?
« Reply #8 on: 17 Aug 2004, 17:51:39 »
You are correct _this represents arguments that are passed out of the evenhandler to the code activated by that handler.  But (from memory - I am currently at work) the ComRef actually says somethign about the event handler recieving arguements in _this.  A bit confusing.  

I prefer to think of the called code receiving the arguments from the event handler in _this.

In other words I am 100% with you.