Julemanden 0 Posted October 14, 2002 Ive saw this thing about evenhandlers and thought that some of them looks pretty interesting. Any chance that some1 could explain to me how they worked? I know the commandref will be out soon, but im an inpatient fellar Share this post Link to post Share on other sites
Doolittle 0 Posted October 14, 2002 Yes! Â I second that! Â What's .. addEventHandler removeEventHandler removeAllEventHandlers Events are .. Killed Hit Dammaged GetIn GetOut Init Engine Gear Fuel Fired IncomingMissile Maybe something like .. addEventHandler ["IncomingMissile", "this action [""eject""]"] ..probably nothing like that..hmmm, where would events be listed? Doolittle Share this post Link to post Share on other sites
dinger 1 Posted October 15, 2002 format appears to be analogous to AddACtion/RemoveAction either unit AddEventHandler ["Type", "instruction"] or variable = unit AddEventHandler ["Type", "Instruction"] then unit RemoveEventHandler index RemoveAllEVentHandlers unit example: spank = mysoldier addeventhandler ["Hit", "bang = ""LaserGuidedBomb"" camcreate getpos mysoldier"] removeeventhandler 1 removeeventhandler spank oh, and _this returns an array specific to the event. (but _this select 0 is always the unit to which the event was attached). now anyone know the format for putting an eventhandler in a config.cpp? Share this post Link to post Share on other sites
uiox 0 Posted October 15, 2002 If you write in init field of a unit this : this AddEventHandler ["hit", "player globalchat {touché}"]  When the unit is hit you have the message. So Dinger is right dans les grandes lignes. If you write : this AddEventHandler ["hit", "player globalchat {touché};this  RemoveEventHandler [{hit} ,0.2]"]  When the unit is hit you have the message too. Share this post Link to post Share on other sites
Doolittle 0 Posted October 15, 2002 _obj = _this select 0 _obj addeventhandler ["killed","hint {killed}"] exit It's great. Â Even on a script exit it still remembers the added event! Â So anyone figure out the specifics for each one?? killed - when damage goes to 1 or even back to 0 hit - when hit by area effect only? I couldn't get it to register if I shot a heli w/ just a gun, but damaging it a little with a LAW worked (hit ground near heli) dammaged (even tried damaged) - couldn't get to work getin - when anything gets in vehicle getout - when anything gets out of vehicle (boy it was hard to figure out these two) init - ? engine - ? dunno, tried on bike & hummer & tank & heli & nothing happened when driving these vehicles - maybe when vehicle can't move but you can still get in?? gear - ? dunno, tried on jeep & tank & heli & drove up hills & nothing fuel - ? fired - when you fire any weapon, even machinegun incomingmissile - works for homing missile only? Doolittle uiox, I like how you clean up the event when the event is called! Nice Share this post Link to post Share on other sites
Doolittle 0 Posted October 15, 2002 I just found this out...if you are in a script... _obj addeventhandler ["event", "[_obj] exec {something.sqs}"] ..this will NOT work. Â It's storing a local variable in a global table so when global table goes to find out what _obj is when "event" happens, it won't know. _obj addeventhandler ["event", "[_this select 0] exec {something.sqs}"] This is what I found works. Â Maybe it is obvious to you guys but it took me a while to get. Â So that answers the question of, when an event is called, what exactly is the this that is doing the calling. Now that I re-read what I just wrote, I dunno if I'm making sense. Doolittle Share this post Link to post Share on other sites
suma 8 Posted October 15, 2002 Check updated official command reference/Scripting topics/Event handlers. Share this post Link to post Share on other sites
walker 0 Posted October 15, 2002 It occurs to me that we may have a method to track who killed who here in mulitplayer. TKs about to get ot in the Ass? Share this post Link to post Share on other sites
dinger 1 Posted October 15, 2002 yup, I posted a very simple script to do just that over in ofpec. player AddEventhandler ["hit", {[_this] exec {killshooter.sqs}}] killshooter.sqs ;dinger@raf303.org _personhit = _this select 0 ;n.b., always local _shooter = _This select 1 _hurtapplied = _this select 2 ;exclude legitimate hits ?side _personhit != side _shooter:exit _personhit setdammage ((dammage _personhit) - _hurtapplied) _shooter setdammage ((dammage _shooter) + _hurtapplied) exit Now, the ComRef says eventhandlers can be added ina unit's config.cpp, but the syntax does not seem to be the same. So what is it? Is there an example we could see? Share this post Link to post Share on other sites
Doolittle 0 Posted October 15, 2002 Don't forget _personhit != _shooter Share this post Link to post Share on other sites
uiox 0 Posted October 15, 2002 GetIn and getOut not work for me player addEventHandler  ["getIn",{_this exec "EventManager\playerIn.sqs"}] player addEventHandler ["getOut",{_this exec "Eventmanager\playerOut.sqs"}] Share this post Link to post Share on other sites
dinger 1 Posted October 15, 2002 getin and getout work fine when applied to vehicles, not the people who get in them. so, make it MyM113 addeventhandler [{getin}, {_this exec {EventManager\someonein.sqs}}] but I can't get "Dammaged" to work, (or init for that matter); and I'm dying to figure out config.cpp (I'll shut up about it now ) Share this post Link to post Share on other sites
Doolittle 0 Posted October 15, 2002 I'm using an event handler here http://www.flashpoint1985.com/cgi-bin....t=21177 for "Killed" in case anyone's interested. Doolittle Share this post Link to post Share on other sites
Prospero 1 Posted October 16, 2002 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Dinger @ Oct. 15 2002,19:58)</td></tr><tr><td id="QUOTE">but I can't get "Dammaged" to work,<span id='postcolor'> Me neither. Hit and Killed are ok though. Prospero Share this post Link to post Share on other sites
The_Captain 0 Posted October 16, 2002 Hey dinger, I copied your script, adn I tried throwing everythign I could at it, but I can't get "_this select 1" to return the killer, it only returns the killed person with _this select 0. How do you get the killer value from the event handler? when I try to grab "this select 1", it gives me "scalar boor etc", but this select 0 gives me a wacky format for the in game unit name/pos. Whoa. Share this post Link to post Share on other sites
The_Captain 0 Posted October 16, 2002 Okay, played around more. The problem with the code is that _this is an array with BOTH the killer/killed values. You have to select from _playerhit instead of _this... This code should work (or maybe I'm crazy) </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE">player AddEventhandler ["hit", {[_this] exec {killshooter.sqs}}] killshooter.sqs ;dinger@raf303.org _personhit = _this select 0 ;n.b., always local _shooter = _personhit select 1 _hurtapplied = _personhit select 2 ;exclude legitimate hits ?side _personhit != side _shooter:exit _personhit setdammage ((dammage _personhit) - _hurtapplied) _shooter setdammage ((dammage _shooter) + _hurtapplied) exit<span id='postcolor'> Share this post Link to post Share on other sites
Doolittle 0 Posted October 16, 2002 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">player AddEventhandler ["hit", {[_this] exec {killshooter.sqs}}] <span id='postcolor'> When you do [_this] you are sending an array of an array. Â By the time you got to "killshooter.sqs", the _this would look like: [[player, causedBy, howMuch]]. Â It's a small thing to overlook. Â In the comref it has: </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote </td></tr><tr><td id="QUOTE">object addEventHandler handler Example: Â Â player addEventHandler ["killed",{_this exec "playerKilled.sqs"}] <span id='postcolor'> Notice he didn't put [] around _this in the example. Â I've been doing "_obj addEventHandler ["whatever", "hint format [""%1"", _this]"]" just to see what kinda stuff gets sent over and when exactly it's activated. Â It's fun with "IncomingMissile" even if you're firing away from the locked on target. Doolittle I wish comref would mention WHEN these events happen! Share this post Link to post Share on other sites
dinger 1 Posted October 16, 2002 captain's right. I screwed up. it should be {_this exec ...} not {[_this] exec ...} Share this post Link to post Share on other sites
Doolittle 0 Posted October 16, 2002 Semaphores! Â I can't believe I'm doing this with OFP! Â What'm I talking about? Â Say you do.. _obj addEventHandler ["getin", "_this exec ""getin.sqs"""] ..for some vehicle's Init. Â So every time you got in that vehicle this script would be executed. Â Well what if that script did not "return" right away? Â You could get in, get out, get in, get out, get in & have 3 "threads" running at the same time. Â You might want to do something like this: getin.sqs ? iamhere : goto "wait" #start iamhere = true ~10 ; a la do something that takes time hint "All done" iamhere = false exit #wait @!iamhere ~random 1 ; don't want a whole bunch to jump in at once ? !iamhere : goto "wait" goto "start" So my question is, Suma, WHY did you guys add in event handlers for us?! Â We can do so much wierd stuff now. Â You're not using this stuff in your scripts, right (a la within the game that shipped)? Â It's like a pretty big addition to the game! Â Thank you! Doolittle P.S. Â Thought of this last night: earthquake.sqs _obj = _this select 0 hint "Earthquake!!!" #shake ~random 0.05 _mag = random 1 ; magnitude _v = velocity _obj _obj setVelocity [(_v select 0) + random _mag, (_v select 1) + random _mag, (_v select 2) + random _mag] goto "shake" ; need to set up timer to break out of loop A cap should probably be done on the velocity to make sure things don't get too out of hand. Â I did this to a standing MG & the thing didn't move but it started squeaking around like it was a tank. Â Share this post Link to post Share on other sites
Julemanden 0 Posted October 16, 2002 Next question, how do we make it work in an addon. kegys hawk for example? The comref said it would work in both scripts and in addons, now how to we import it into an addon, (.cpp)? Share this post Link to post Share on other sites
marik 0 Posted October 27, 2002 I have not been able to get Dingers script to work at all. Has anyone? Share this post Link to post Share on other sites
kegetys 2 Posted October 27, 2002 </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Quote (Julemanden @ Oct. 16 2002,19:38)</td></tr><tr><td id="QUOTE">The comref said it would work in both scripts and in addons, now how to we import it into an addon, (.cpp)?<span id='postcolor'> Like this: </span><table border="0" align="center" width="95%" cellpadding="3" cellspacing="1"><tr><td>Code Sample </td></tr><tr><td id="CODE"> class EventHandlers { getIn= "hint ""Get out of there!"";"; getOut= "hint ""Good boy."";"; }; <span id='postcolor'> in the vehicles class. The dammaged event seems to work for me, at least for soldiers... When I shoot their legs off it gets triggered. Share this post Link to post Share on other sites