Home   Help Search Login Register  

Author Topic: event handler woes ?  (Read 1537 times)

0 Members and 1 Guest are viewing this topic.

Offline sharkattack

  • Former Staff
  • ****
event handler woes ?
« on: 14 Jul 2009, 19:26:42 »
hi lads ..

i have a beta mission in the beta forums  in which im trying to add an event handler to detect unsupressed gunfire .  can get it to work  by itself  but if i add  another event handler based script ..  im buggered
had no problem with each EH  in seperate trials  but as soon as i mixed them  only one or the other would work ..
anyone tell me what im doing wrong ..

first EH thanks to (spooner)

gamelogic to count number of cranes destroyed at port

Code: [Select]
{ _x addEventHandler ["KILLED", { _this execVM "cranes.sqf" }] } forEach nearestObjects [this, ["Land_A_Crane_02b"], 500]  
cranes.sqf (thanks spooner) works a treat alone

Code: [Select]
if (isNil "ecraneCounter") then { ecraneCounter = 0 };
ecraneCounter = ecraneCounter + 1;

// <-- Do stuff every time.

if (ecraneCounter == 5) then
{
seven=true;
publicvariable "seven";
};

ecranecounter=false  in init sqf

#2
trigger to detect unsilenced gunfire ( from arma)  but works when tested alone

{_x addEventHandler ["fired",{if (!((_this select 2) in ["bizon_silenced","M4A1_HWS_GL_SD_Camo","M4A1_AIM_SD_camo","M9SD","G36_C_SD_eotech","PipeBombMuzzle"]) && !gunfire) then {gunfire=true; _this execVM "elekalert.sqf";}}];} forEach thislist;

elekalert.sqf

Code: [Select]
{_x setUnitPos "MIDDLE"} forEach list westport;{_x setBehaviour "AWARE"}  forEach list westport;
sleep 3;
hint "Contact  ... Enemy alerted to gunfire around the port of Elektrozavodsk ";

gunfire =false  in init sqf ..


hope you can make some sort of sense from my questions ..  :P

as always any help  would be real nice   :good:




« Last Edit: 14 Jul 2009, 19:30:39 by sharkattack »
"HOLY SARDINE" - see Shark-Attack meet his match

Offline Worldeater

  • Former Staff
  • ****
  • Suum cuique
Re: event handler woes ?
« Reply #1 on: 14 Jul 2009, 19:57:13 »
Code: [Select]
if (isNil "ecraneCounter") then { ecraneCounter = 0 };
...
ecranecounter=false  in init sqf

Hmm, I might be wrong but it looks like the line containing isNil "ecraneCounter" is never executed because you're assigning a value to ecraneCounter in the init.sqf (if a variable is set to _any_ value it's not nil anymore).

Correction: the line will be executed, but ecraneCounter won't be set to zero. So you end up adding one to "false".
« Last Edit: 14 Jul 2009, 20:10:27 by Worldeater »
try { return true; } finally { return false; }

Offline Spooner

  • Members
  • *
  • Mostly useless
    • Community Base Addons
Re: event handler woes ?
« Reply #2 on: 16 Jul 2009, 13:56:59 »
Yes, I gave him the original script but didn't tell him to set the value to false initially.
[Arma 2] CBA: Community Base Addons
[Arma 1] SPON Core (including links to my other scripts)

Offline sharkattack

  • Former Staff
  • ****
Re: event handler woes ?
« Reply #3 on: 18 Jul 2009, 13:44:44 »
sorry for for my incompitance ... wished id stuck in at school now ... mind you it was  all ceefax pages  and  defender ...  (those of a certain age will know what i mean) 

anyway  it works perfectly  now  :good:

many thanks  spooner  and  worldeater 

nice one  lads 
"HOLY SARDINE" - see Shark-Attack meet his match