Home   Help Search Login Register  

Author Topic: Geting info from an eventhandler  (Read 2361 times)

0 Members and 1 Guest are viewing this topic.

Offline F2kSel

  • Members
  • *
Geting info from an eventhandler
« on: 22 Jul 2009, 17:55:18 »
I'm trying to check if an object has been hit using and eventhandler, I can get it to Display a hit using a hint but I need  it to set a variable and get an actual result.

_rtarget addEventHandler ["hit", {hint "hit"}];
 
or something like is as far as I can get, I'm not at my right PC will display the hit but how can I use it to  register it in a variable.

I've also tried

eh =_rtarget addEventHandler ["hit", 0];

but that only returns -1 all the time hit or no hit.

Anyone Cheers.

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: Geting info from an eventhandler
« Reply #1 on: 22 Jul 2009, 19:38:43 »
Try digesting the Eventhandlers information from this page.

And the addEventhandler command from the comref.


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

Offline DMarkwick

  • Contributing Member
  • **
  • I'm a llama!
Re: Geting info from an eventhandler
« Reply #2 on: 22 Jul 2009, 20:49:07 »
You'll be better served to have the desired event result in this fashion (which you already used):

Code: [Select]
UnitName addEventHandler ["hit", {HitVariable = HitVariable + 1}];
Or you could farm the whole job out to a specially made script:

Code: [Select]
UnitName addEventHandler ["hit", {nul = this execVM "HitEventScriptname.sqf"}];
As you will see by reading this reference:
http://community.bistudio.com/wiki/ArmA:_Event_Handlers#Hit
the "this" variable contains these informational nuggets:
[unit, causedBy, damage]
so you can access these nuggets in your script by starting it like this (you probably already know this but I include it for completion):

HitEventScriptname.sqf
Code: [Select]
_thisUnit - _this select 0;
_thisShooterUnit - _this select 1;
_thisInjuryLevel = _this select 2;

...rest of code...

hope that starts you off :)
« Last Edit: 22 Jul 2009, 21:06:26 by DMarkwick »

Offline nominesine

  • Former Staff
  • ****
  • I'm NOT back!
    • The IKB Forum
Re: Geting info from an eventhandler
« Reply #3 on: 22 Jul 2009, 20:53:20 »
While we're on the subject: If I use a Detected by trigger, can I get it to return who was detected and who saw the culprit respectively? Somethng along these lines...

_detected = _this select 0
_detector = _this select 1

I have no testingopportunities right now. I read Igor Drukovs EventHandler tutorial from the Ed Depot but failed to come up with an answer. Does anybody know?

 :dunno:
OFPEC | Intel Depot
RETARDED Ooops... Retired!

Offline F2kSel

  • Members
  • *
Re: Geting info from an eventhandler
« Reply #4 on: 23 Jul 2009, 01:52:41 »
Thanks for the input guys, I don't have time today to fire up Arma2.

I'm still a bit puzzled though


Code: [Select]
UnitName addEventHandler ["hit", {HitVariable = HitVariable + 1}]; That's  what I tried first and the Hitvariable won't increment .
The only difference was it had the underscore at the front ie "_HitVariable" I'm also using it in an sqf script if that makes a difference. The "_HitVariable" worked perfectly outside the eventhandler so I know that part works.

I also tried my own version of calling a  second script without success but I didn't know how the array worked.
I'm also not sure how I would get the variable back into the first script where I need it.

Using the two script version all I would need  an  
Code: [Select]
_HitVariable = _HitVariable + 1 and then be  able to send the result back. But wouldn't this cause an error as _HitVariable isn't defined in the second scrip?
If I do define it _HitVariable=0 it's always going to 1 on exit as it's always getting reset, I think that's where I got stuck last time.  


Sorry if I don't make much sense.


« Last Edit: 23 Jul 2009, 02:08:23 by F2kSel »

Offline DeanosBeano

  • Addons Depot Staff
  • *****
  • SirDeanosbeano bstowed on me by sui ;)
    • Fraghaus
Re: Geting info from an eventhandler
« Reply #5 on: 23 Jul 2009, 13:02:02 »
 If i understand you want to obtain information about something thats been hit,
 Maybe try this

 
Code: [Select]
This addeventhandler ["Hit",{ whos = _this select 0; who = this select 1; hint format [" %1has been hit  and was hit by    %2",whos,who]}];
 untested syntax but should return who was hit and who hit them or you can try with a damage it will return who was hit and where ;

Code: [Select]
This addeventhandler ["Dammaged",{ whos = _this select 0; where = this select 1; hint format [" %1 has been hit  and was hit in the    %2",whos,where]}];
 not at my arma pc at mo but any probs i will try to support later. it maybe Damaged not Dammaged can never remeber if it changed in arma1

Edit totatlly misnderstood your post , bu  i will leave this here for future reference anyw. seems a combination of DMarkwick and worldeaters solutions are what you need. good luck
« Last Edit: 23 Jul 2009, 18:29:19 by DeanosBeano »
I love ofp

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: Geting info from an eventhandler
« Reply #6 on: 23 Jul 2009, 14:01:13 »
Code: [Select]
UnitName addEventHandler ["hit", {HitVariable = HitVariable + 1}]; That's  what I tried first and the Hitvariable won't increment .

The problem is most probably that you did not initialize HitVariable. So it defaults to nil and no matter what you add to nil the result is always nil.

The solution is simple. Set HitVariable to zero in the init.sqf:

Code: (init.sqf) [Select]
HitVariable = 0;
try { return true; } finally { return false; }

Offline F2kSel

  • Members
  • *
Re: Geting info from an eventhandler
« Reply #7 on: 23 Jul 2009, 15:17:38 »
Ok, thanks all.

 I'll have another bash tonight and have a few things to tryout.

Offline DMarkwick

  • Contributing Member
  • **
  • I'm a llama!
Re: Geting info from an eventhandler
« Reply #8 on: 23 Jul 2009, 19:21:47 »
Ah yeah sorry, when I wrote "HitVariable" I meant any variable that you have earmarked for the task :) like when I write "UnitName" etc it just means any variable/name that you have decided to use.

Offline F2kSel

  • Members
  • *
Re: Geting info from an eventhandler
« Reply #9 on: 23 Jul 2009, 23:49:59 »

Thanks for the help hitvar = hitvar+1 did work, when I tried it previously I used _hitvar = _hitvar+1.

Using the underscore keeps the variable from outputting the info.

Cheers.






Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: Geting info from an eventhandler
« Reply #10 on: 23 Jul 2009, 23:59:40 »
hitvar would be a global variable and will work fine in init fields of triggers and waypoints ... etc.

_hitvar is a local variable and is limited in scope to the script it is used in, it won't work in init fields of triggers and waypoints ... etc.


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

Offline F2kSel

  • Members
  • *
Re: Geting info from an eventhandler
« Reply #11 on: 24 Jul 2009, 11:47:19 »


If I can ask one more question, at the start of some eventhandlers  I see something like this

Code: [Select]
_eh = _unit   addeventhandler ["hit", {Hits= Hits+ 1;}];
I don't know what the "_eh" does, does anyone else?

Offline Planck

  • Honoured
  • Former Staff
  • ****
  • I'm never wrong ....I'm just not always right !
Re: Geting info from an eventhandler
« Reply #12 on: 24 Jul 2009, 14:50:28 »
_eh will contain the returned value from the command, in this case it is the index number of the added eventhandler which you can use to remove the eventhandler later in the script, should you wish to do so.

For example:

Code: [Select]
_unit removeEventhandler ["hit", _eh];

Planck
« Last Edit: 24 Jul 2009, 14:55:56 by Planck »
I know a little about a lot, and a lot about a little.

Offline F2kSel

  • Members
  • *
Re: Geting info from an eventhandler
« Reply #13 on: 24 Jul 2009, 18:43:19 »
Cheers that makes sense.