OFPEC Forum

Editors Depot - Mission Editing and Scripting => ArmA - Editing/Scripting General => Topic started by: sharkattack on 16 Mar 2007, 10:42:48

Title: eventhandler fired
Post by: sharkattack on 16 Mar 2007, 10:42:48
hi guys .. 
im trying to set up an event handler  so that if a certain units fires his weapon (ak74) a script is called ..

failing desperatley ..
anyone any idea  what to put instead of the xxxxxxx in syntax


this addEventHandler ["fired", xxxxxxxx , xxxxxxxx  (xxxxxxxxxxx)]  exec "myScript.sqs"}]

any help  would be great            many thanx  shark-attack




Title: Re: eventhandler fired
Post by: h- on 16 Mar 2007, 11:28:57
That whole syntax (http://www.ofpec.com/COMREF/index.php?action=list&game=All&letter=a#addEventHandler) is all wrong...

If you simply want to have a script executed, you only need to use:
Code: [Select]
this addEventHandler ["fired",{_this exec "script.sqs"}]
However, if you want the script only to be executed when only the ak is fired, use something like this
Code: [Select]
this addEventHandler ["fired",{if (_this select 2 == "ak74") then {_this exec "script.sqs"}}]
Title: Re: eventhandler fired
Post by: sharkattack on 16 Mar 2007, 11:54:18
thanx�  h ..
ill give it a try ... thanx again  :)
*EDIT
=====
2nd edit 
mmm ..
how can i make it so that the eventhandler is only activated once  at the min everytime loon fires script is called .. so if he gives it a long burst  my script is called several times .. 
Title: Re: eventhandler fired
Post by: h- on 16 Mar 2007, 13:01:54
Ach, yes..
I never remember that when it comes to these things  :P

I guess the easiest way (might be the only way actually) is using a global variable.
First, in your mission init.sqs (or .sqf) set the variable myvar_akFired = false

then the EH
Code: [Select]
this addEventHandler ["fired",{if (_this select 2 == "ak74" && !myvar_akFired) then {myvar_akFired=true; _this exec "script.sqs"}}]Now the eventhandler checks whether the weapon is AK74 and if it has not been fired earlier, and if so the eventhandler sets the myvarib_akFired to true and executes the script..
Title: Re: eventhandler fired
Post by: sharkattack on 16 Mar 2007, 13:13:30
awsome
 i now have screaming monkeys when shots are fired in forest/jungle ..
thanx a million h
Title: Re: eventhandler fired
Post by: h- on 16 Mar 2007, 14:41:37
Quote
i now screaming monkeys when shots are fired in forest/jungle
Back you will be for more questions sense I.. 

We'll wait and see.....  :scratch:
Title: Re: eventhandler fired
Post by: sharkattack on 16 Mar 2007, 22:24:29
lol..
no doubt mate ..
as long as there are guys like youreself  willing to teach ..

long live ofpec ............. :good:
Title: Re: eventhandler fired
Post by: h- on 16 Mar 2007, 23:03:17
The thing is, that script most likely gets executed only once during the whole mission because of that global variable..

So if the script 'expires' at certain point the monkeys won't be screaming the next time..
At least they shouldn't unless ArmA somehow handles global variables differently (which I really really doubt)..
Title: Re: eventhandler fired
Post by: myke13021 on 16 Mar 2007, 23:59:01
sorry for spouting in....

wouldn't a removeEventHandler being easier instead of using variables? or is there something i don't know?
Title: Re: eventhandler fired
Post by: h- on 17 Mar 2007, 00:26:03
Yes, should be usable method in case similar to this..

But in this case I used variable in the example because I don't know how many units will be doing the firing..
Now the first to fire prevents any other from executing the script..
Title: Re: eventhandler fired
Post by: sharkattack on 17 Mar 2007, 09:07:07
works great with variable
monkey s  scream an alert one time at the sound of gunfire  then bugger off ..
Title: Re: eventhandler fired
Post by: sharkattack on 15 Apr 2007, 22:18:12
hi ...
have been using this code to get enemy to react to gunfire

this addEventHandler ["fired",{if (_this select 2 == "ak74" && !myvar_akFired) then {myvar_akFired=true; _this exec "script.sqs"}}]

works a treat with every weapon ... apart from M4A1GL ... i can get it to react to the flare or grenade
just not the main gun ..

this addEventHandler ["fired",{if (_this select 2 == "M4A1GL" && !myvar_akFired) then {myvar_akFired=true; _this exec "script.sqs"}}]   
dosnt fire the script !  any one know the answer  have tried all obvious solutions but to no avail ??
many thanx...
Title: Re: eventhandler fired
Post by: D_P_ on 16 Apr 2007, 00:20:59
could you post a demo mission of your screaming monkies?
Title: Re: eventhandler fired
Post by: Cheetah on 16 Apr 2007, 17:03:56
It's (probably) in his jungle mission, CO4 Especas Commando
Title: Re: eventhandler fired
Post by: sharkattack on 16 Apr 2007, 18:23:18
co4@especas commando ... (MP/SP)
when any gun other than supressed is fired
the jungle reacts birds fly  monkeys scream ... 

back to the issue
is it all possible to set up an event handler for every weapon other than supressed weapons
then that would cover all...
Title: Re: eventhandler fired
Post by: h- on 18 Apr 2007, 08:53:03
Should be..

Make an array of the silenced ammo or weapon names, you can find them here (http://www.ofpec.com/COMREF/armaweapons.php), and check whether the used ammo/weapon is in the array

Ammo (if ammo used is not SD ammo)
Code: [Select]
this addEventHandler ["fired",{if (!(_this select 4 in ["B_556x45_SD","B_556x45_SD"]) && !myvar_akFired) then {myvar_akFired=true; _this exec "script.sqs"}]Weapon (if weapon used not silenced)
Code: [Select]
this addEventHandler ["fired",{if (!(_this select 2 in ["M4A1SD","MP5SD"]) && !myvar_akFired) then {myvar_akFired=true; _this exec "script.sqs"}]
The ammo thing is not very usefull because in ArmA you can use SD and non-SD ammo in silenced weapons and they are still silenced so you can't tell whether the weapon used was silenced with just the ammo..
I just thought I'd post it as an example, it might very well fit some other situation.. :scratch:

Oh, and that myvar_akfired is just an example of a variable name  :D
Title: Re: eventhandler fired
Post by: sharkattack on 18 Apr 2007, 18:29:24
cheers h ... yeah i figured about variable name .. 
and youre right
Quote
Back you will be for more questions sense I.. 

thanx again mate  :good:
Title: Re: eventhandler fired
Post by: sharkattack on 31 Dec 2007, 13:16:59

i am using the following to detect gunfire from un suppressed weapons

this addEventHandler ["fired",{if (!(_this select 2 in["M4A1SD","MP5SD","M9SD","AKS74UN","Makarov
SD"]) && !myvar_akFired) then {myvar_akFired=true; _this exec "detected.sqs"}}]


it works fine  ... if the player  fires anything but a silcenced weapon the enemy will react ..
however if i manage to avoid detection and go to place a charge at the target .. as soon as i put the satchel down the event handler fires

have tried  adding  "Put"  (weapon class name)
and both PipeBomb and TimeBomb (magazine classname)
to weapons array  but still everytime i  set a charge  the handler is fired

can anyone help with this issue

many thanx  and best wishes for the new year to all ...
Title: Re: eventhandler fired
Post by: Spooner on 31 Dec 2007, 14:24:03
The satchel charge is called "PipeBomb" (AMMO) and is fired by "Put" (WEAPON) using the "PipeBombMuzzle" (MUZZLE). (_this select 1) is the WEAPON, (_this select 2) is the MUZZLE, and (_this select 4) is the AMMO (see the weapons COMREF (http://www.ofpec.com/COMREF/armaweapons.php) for all the possible muzzles for each weapon).

works a treat with every weapon ... apart from M4A1GL ... i can get it to react to the flare or grenade
just not the main gun ..

this addEventHandler ["fired",{if (_this select 2 == "M4A1GL" && !myvar_akFired) then {myvar_akFired=true; _this exec "script.sqs"}}]   
dosnt fire the script !  any one know the answer  have tried all obvious solutions but to no avail ??
many thanx...

In this event handler, (_this select 2) is the name of the muzzle used, not the weapon. In all weapons that only have one muzzle, the name of the muzzle is the same as the weapon though. For the M4A1GL, the muzzles are the "M4Muzzle" and the "M203Muzzle". If you just want to know which weapon has been fired, then you might as well use the weapon, rather than the muzzle (i.e. use _this select 1)).
Title: Re: eventhandler fired
Post by: sharkattack on 31 Dec 2007, 14:54:38
thanks very much spooner

PipeBombMuzzle  done the trick for the satchels   :)

all the best