Jump to content
Dominicus1165

EventHandler Increment Internal Variable or Local Variable

Recommended Posts

This is on a multiplayer server. It must work there.
I want to breach a door via Slug Ammo. I placed a wooden plank the size of the door in front of it.

After two hits the plank gets destroyed and the door opens.

 

I want to use this script multiple times during my mission.

Therefore, I don't want n variables counterPlank0 - counterPlankN

I want to save the counter locally.

 

Called in init of plank:

[this] execVM "scripts\eh_slugBreach.sqf"

File:

Working with global variable:

Spoiler

params ["_object"];

counterPlank = 0;

_object addMPEventHandler ["MPHit", { 
    params ["_unit", "_causedBy", "_damage", "_instigator"]; 
 
    if (currentMagazine _instigator isEqualTo "rhsusf_5Rnd_Slug") then { 
        counterPlank = counterPlank + 1; 
    };
 
    if (counterPlank > 1) then { 
        deleteVehicle _unit;
        myBuilding animateSource ["Door_1_sound_source", 1]; 
    }; 
}];

 

 

Not working with setVariable:

params ["_object"];

_counterplank = 0;
_object setVariable ["counterPlank", _counterPlank];								DIFFERENCE

_object addMPEventHandler ["MPHit", { 
    params ["_unit", "_causedBy", "_damage", "_instigator"]; 
 
    if (currentMagazine _instigator isEqualTo "rhsusf_5Rnd_Slug") then { 
        _unit setVariable ["counterPlank", _counterPlank + 1]; 							DIFFERENCE
    };
 
    if (_unit getVariable "counterPlank" > 1) then { 								DIFFERENCE
        deleteVehicle _unit;
        myBuilding animateSource ["Door_1_sound_source", 1]; 
    }; 
}];

 

Share this post


Link to post
Share on other sites

First of all, welcome on forum.

 

params ["_object"];
_object setVariable ["counterPlank", 0];
_object addMPEventHandler ["MPHit", {
  params ["_unit", "_causedBy", "_damage", "_instigator"];
  if (currentMagazine _instigator isEqualTo "rhsusf_5Rnd_Slug") then {
    _unit setVariable ["counterPlank", (_unit getVariable ["counterPlank,0]) + 1];
    if (_unit getVariable ["counterPlank",0] > 1) then {
      deleteVehicle _unit;
      myBuilding animateSource ["Door_1_sound_source", 1,TRUE];
    };
  };
}];

 

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×