Home   Help Search Login Register  

Author Topic: EVENTHANDLERS!!! HELP!!!  (Read 1045 times)

0 Members and 3 Guests are viewing this topic.

foolscap

  • Guest
EVENTHANDLERS!!! HELP!!!
« on: 21 Oct 2003, 22:28:18 »
how would i use an event handler in a units init field:

player addEventHandler ["incomingMissile",{_this exec "blahblah.sqs"}

i want to create a script that launches a flare when a missile is fired at the unit, i know how to launch flares but how to get them to launch when a missile is fired at the unit is tricky.

please help

Offline The_Mark

  • Members
  • *
Re:EVENTHANDLERS!!! HELP!!!
« Reply #1 on: 21 Oct 2003, 22:44:56 »
You want the player to lauch a flare or the unit which has the code in his init to launch it?

Besides that exactly doesn't give the unit very much time to lauch the flare....
Silent enim leges inter arma.

foolscap

  • Guest
Re:EVENTHANDLERS!!! HELP!!!
« Reply #2 on: 21 Oct 2003, 22:56:04 »
its a ECM script but instead of the eventhandler being put in the config file of an addon its put in the init file of a unit. This allows any unit in the game to have a ECM function.

what i want to know is how to use the eventhandler "missileIncoming" to activate a script, but also what information the eventhandler produces like

who fired the missile
what kinda missile

stuff like that

and also how i would use this in a script

Offline The_Mark

  • Members
  • *
Re:EVENTHANDLERS!!! HELP!!!
« Reply #3 on: 21 Oct 2003, 23:42:24 »
In the script:
Code: [Select]
_target=_this select 0
_ammo=_this select 1
_dude_who_fired_the_missile=_this select 2

That should do it. It's all in the Comref. But if you want the missile to steer to the flare you need a homing script.

By the way, I made a flare launching script waay back  ;D

Here's the script:
Code: [Select]
_obj = _this select 0

_xpos = getpos _obj select 0
_ypos = getpos _obj select 1
_zpos = getpos _obj select 2

_xvel = velocity _obj select 0
_yvel = velocity _obj select 1
_zvel = velocity _obj select 2

_flare1 = "Flare" camcreate [_xpos,_ypos,_zpos+10]
_flare1 setvelocity [_xvel/1.5,_yvel/1.5,zvel+10]
exit
Place it to the onmissilefired handler and you should have the flare.
It has some still some problems, like if you place the flare to the same position as the unit, the flare "explodes", damaging the unit. Practicly, you would be shooting the unit with flares. (You can kill soldiers with a flare, believe me, I have tried ;D)
And the same thing with the unit colliding with the flare.

The biggest problem is that that the flare will lit up after a period of time, just like when shot from a flaregun.
Silent enim leges inter arma.

foolscap

  • Guest
Re:EVENTHANDLERS!!! HELP!!!
« Reply #4 on: 22 Oct 2003, 21:13:20 »
Thanks! ;D

i've managed to call the script using the eventhandler in the units init, but my script is having some teething problems. here it is:

_plane = _this select 0

?(not alive (_plane select 0) ): goto "Exit"
?(not isengineon (_plane select 0) ): goto "Exit"

_enemy = _plane select 2
_ammo = _plane select 1

_missile = nearestobject [_enemy, _ammo]

@ _missile distance (_plane select 0) < 300

_directionchange = 5 -random 10

_count =0

#repeat

(_plane) say "Incoming"

_newdirection = (direction _missile) + _directionchange

? (_newdirection > 360) : _newdirection = _newdir -360
? (_newdirection < 0) : _newdirection = _newdir +360

_missile setdirection _newdirection

drop["kouleSvetlo","","Billboard",0.05,6,[-.2,-3,1.1],[-6-random 6,- random 2,0],0,1.8,1,0,[1],[[1,1,0.3,1]],[0,1],0,0,"smoke.sqs","",(_plane)]
drop["kouleSvetlo","","Billboard",0.05,6,[.2,-3,1.1],[6+random 6,- random 2,0],0,1.8,1,0,[1],[[1,1,0.3,1]],[0,1],0,0,"smoke.sqs","",(_plane)]

(_plane) say "FlareLaunch"

~0.05

? (_count < 6) : goto repeat

#Exit
exit

so far ive identified problem with 2 lines first is the one that gives the _missile

second is the line that checks wether its within 300m

Offline Igor Drukov

  • Contributing Member
  • **
  • Conscientious Subjector
Re:EVENTHANDLERS!!! HELP!!!
« Reply #5 on: 23 Oct 2003, 00:35:43 »
Hey !

instead of :

Quote
_enemy = _plane select 2
_ammo = _plane select 1

try :

Code: [Select]
_enemy = _this select 2
_ammo = _this select 1

I didn't look too much into the details, but this misprint struck me.

Hope it'll help.

Ig.

foolscap

  • Guest
Re:EVENTHANDLERS!!! HELP!!!
« Reply #6 on: 23 Oct 2003, 20:02:31 »
cheers!! ;D

thanks for that i found some other errors as well, but now its working great and i plan to release it nxt week somewhen

thanks for ur help:

Igor Grukov
The_Mark

foolscap