Home   Help Search Login Register  

Author Topic: eventhandler fired  (Read 3969 times)

0 Members and 2 Guests are viewing this topic.

Offline sharkattack

  • Former Staff
  • ****
eventhandler fired
« 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




"HOLY SARDINE" - see Shark-Attack meet his match

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: eventhandler fired
« Reply #1 on: 16 Mar 2007, 11:28:57 »
That whole syntax 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"}}]
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline sharkattack

  • Former Staff
  • ****
Re: eventhandler fired
« Reply #2 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 .. 
« Last Edit: 16 Mar 2007, 12:28:41 by shark attack »
"HOLY SARDINE" - see Shark-Attack meet his match

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: eventhandler fired
« Reply #3 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..
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline sharkattack

  • Former Staff
  • ****
Re: eventhandler fired
« Reply #4 on: 16 Mar 2007, 13:13:30 »
awsome
 i now have screaming monkeys when shots are fired in forest/jungle ..
thanx a million h
« Last Edit: 16 Mar 2007, 22:22:26 by shark attack »
"HOLY SARDINE" - see Shark-Attack meet his match

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: eventhandler fired
« Reply #5 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:
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline sharkattack

  • Former Staff
  • ****
Re: eventhandler fired
« Reply #6 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:
"HOLY SARDINE" - see Shark-Attack meet his match

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: eventhandler fired
« Reply #7 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)..
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline myke13021

  • Contributing Member
  • **
  • Myke
Re: eventhandler fired
« Reply #8 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?

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: eventhandler fired
« Reply #9 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..
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline sharkattack

  • Former Staff
  • ****
Re: eventhandler fired
« Reply #10 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 ..
"HOLY SARDINE" - see Shark-Attack meet his match

Offline sharkattack

  • Former Staff
  • ****
Re: eventhandler fired
« Reply #11 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...
"HOLY SARDINE" - see Shark-Attack meet his match

Offline D_P_

  • Members
  • *
  • YAY! I'm a lama again! ...oh wait.
    • ArmaAddons
Re: eventhandler fired
« Reply #12 on: 16 Apr 2007, 00:20:59 »
could you post a demo mission of your screaming monkies?
just setpos & forgetpos!

Offline Cheetah

  • Former Staff
  • ****
Re: eventhandler fired
« Reply #13 on: 16 Apr 2007, 17:03:56 »
It's (probably) in his jungle mission, CO4 Especas Commando
Like missions? Help with Beta Testing! or take a look at the OFPEC Missions Depot for reviewed missions!

Offline sharkattack

  • Former Staff
  • ****
Re: eventhandler fired
« Reply #14 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...
« Last Edit: 16 Apr 2007, 23:16:56 by shark attack »
"HOLY SARDINE" - see Shark-Attack meet his match

Offline h-

  • OFPEC Site
  • Administrator
  • *****
  • Formerly HateR_Kint
    • OFPEC
Re: eventhandler fired
« Reply #15 on: 18 Apr 2007, 08:53:03 »
Should be..

Make an array of the silenced ammo or weapon names, you can find them here, 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
Project MCAR   ---   Northern Fronts   ---   Emitter 3Ditor
INFORMATIVE THREAD TITLES PLEASE. "PLEASE HELP" IS NOT ONE..
Chuck Norris can divide by zero.

Offline sharkattack

  • Former Staff
  • ****
Re: eventhandler fired
« Reply #16 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:
"HOLY SARDINE" - see Shark-Attack meet his match

Offline sharkattack

  • Former Staff
  • ****
Re: eventhandler fired
« Reply #17 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 ...
"HOLY SARDINE" - see Shark-Attack meet his match

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: eventhandler fired
« Reply #18 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 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)).
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline sharkattack

  • Former Staff
  • ****
Re: eventhandler fired
« Reply #19 on: 31 Dec 2007, 14:54:38 »
thanks very much spooner

PipeBombMuzzle  done the trick for the satchels   :)

all the best
« Last Edit: 31 Dec 2007, 14:58:19 by shark attack »
"HOLY SARDINE" - see Shark-Attack meet his match