Jump to content
SirBassi

addeventhandler "Fired" | MP | attach to "unknown" vehicles

Recommended Posts

Hi together,

 

I turn to you with a problem where I'm reaching the limit with my basic skills.

 

Initial situation:

I would like to use the addaventhandler Fired in a dedicated environment to trigger various environmental effects etc. when a bomb is dropped.

This "Bombeffectpart" works without problems.

 

But it only works if the event handler is tied directly to the vehicle, as described in the BI Wiki:

 

Quote

This EH will not trigger if a unit fires out of a vehicle. For those cases an EH has to be attached to that particular vehicle.

 

Otherwise I sometimes get wrong parameters send in my tests or get directly Schript Errors because of wrong Variables.

 

Problem:

However, I am currently only able to bind the eventhandler to vehicles if I assign a fixed variable to a vehicle init field in the editor and then bind the eventhandler to this in the script.

But the mission does not contain all vehicles at the beginning of the mission. There are some vehicles that are temporarily in the mission due to an RTO module and some other are only spawned / created by players.

 

And this is exactly where I'm looking for a solution: How I can search for all "Air" objects in a loop and bind the event handler directly to the vehicle object (not the unit). Theoretically, referring to airplanes or an array in which I write all the class names it relates to would be sufficient.

 

Do you have any ideas how I can solve this problem? I've been racking my brains about this for several days.

 

Here my actual Code Snippet which wouldn't work because Eventhandler is not attached to vehicle (exclusive).

 

Spoiler

//Skript is initialised with Serverstart

 

//Some Global Variables are defined at beginning

 

[] spawn

{

    while {true} do

    {

        {

            _x addEventHandler ["Fired",

            {

                params ["_unit", "_weapon", "_muzzle", "_mode", "_ammo", "_magazine", "_projectile", "_gunner"];

                if (_ammo in NapalmAmmo ) then

                {

                    // some Codework with variables from addEventHandler

                    // leave the loop with a spawn of an outside function

                    // change in a further step to fill complete code then here

                }

                else

                {

                    this removeEventHandler [_thisEvent, _thisEventHandler];

                };

            }];

        } foreach allMissionObjects "Air";

          sleep 2;

    };

};

 

//here follows then the first fnc which is called inside the if - Loop (I will rewrite this later).

 

Thank you so much for Input and Ideas. 🙂

Share this post


Link to post
Share on other sites

@SirBassi I recommend you use the recently added "ProjectileCreated" mission event handler instead. As the name suggests it will trigger whenever a projectile is created no matter which vehicle fires it. Just make sure to filter out unwanted projectiles as quickly as possible, if you got many possible types to handle use a HashMap, for few items use arrays or plain equality checks.

 

If you need the vehicle who fired the projectile use getShotParent.

 

For a practical example here's the init of my artillery terrain deformation example:

ARDM_mainEH = addMissionEventHandler [

 "ProjectileCreated", 

 { 

  private _projectile = _this;

  private _type = typeOf _projectile;

  private _ammoCfg = configFile >> "CfgAmmo" >> _type;  

  if(isClass _ammoCfg) then {

   if( _type in ARDM_ammoMap ) then {

    _projectile addEventHandler [

     "Explode", 

     {

      params ["_projectile", "_pos", "_velocity"];

      private _blastParams = ARDM_ammoMap get typeOf _projectile;

      _pos = ASLtoATL _pos;

      

      if(ASLtoATL _pos select 2 < 0.5) then {

       [_pos, _blastParams] call ARDM_fnc_doBlast;

      };

     }

    ];

   };

  };

 }

];

 

  • Like 1

Share this post


Link to post
Share on other sites

Hi @mrcurry,

 

thats an fantastic idea.

 

I tried this weekend to scrip around with Eventhandler Engine before Eventhandler Fired but Problem with attaching the eventhandler to a non knowing vehicle at Missionstart was the same. I also tried to fix this with setVehicleVarName or some CBA Eventhandlers but finally I give up.

 

But ProjectileCreated and Explode combination sounds very interesting. Thanks for the Input. I'll report and if okay asking some questions to this.

 

Thanks a lot.

Share this post


Link to post
Share on other sites

Just a basic question to MissionEventHandler:

Is it recommand do make also a while true - Loop around this EH to catch all needed projectile "Carriers" especially the after missionstart created ones?

Or do I have to expect "endless" EH calls beaucse of the Loop.

 

Because I struggle a lil with the decription / definition of mission eventhandler from Wiki: "Mission event handlers are specific EHs that are anchored to the running mission [...]"

Does this mean "JIP", respawned etc. projectile Carriers are included?

 

Thanks a lot 🙂

Share this post


Link to post
Share on other sites

A missionEventHandler (MEH) will fire (along with its function) during all the time of the mission. That's a little bit evident, and probably makes no difference with simple EH.

These MEH are local, so you need to run them on each needed PC. As you can see, there is no argument, on the contrary of EHs because they are generic for the scenario: you don't apply them to a unit of an object, they fire for events like "eachFrame" or "entityCreated"
So, you don't need any loop for catching or updating "carriers". Once in game, if an event like "projectileCreated" occurs, you can work with this projectile as an object (short alive).

 

Now, if you want to use an EH like "fired", you need to parameter it on a unit, and yes, if this unit is spawned, you need a loop.... or the use of the MEH "entityCreated" !
something like:
1st case:

[] spawn {
  while {TRUE} do {
    {
      _x addEventHandler ["fired" ,{<..parametrized EH code..>}];
      _x setVariable ["passedForMyEH",TRUE];
    } forEach (allUnits select { whatYouWant && !(_x getVariable ["passedForMyEH",FALSE]) });
    sleep 2;
  };
};

 

2nd case:

addMissionEventHandler ["entityCreated", {
  if (_this isKindOf "CAManBase") then {
    _this addEventHandler ["fired" ,{<..parametrized EH code..>}];
  };
}];


NOTE: entityCreated MEH fires very often for multiple creations (agents: rabbits, snakes... footprints, projectile impacts if I'm right,...and of course men and vehicles). So, first thing to do is to drastically filter that mess by an immediate condition.

About performance, I can't say which is the best code for catching created entities.

 

MEHs are fine for JIP or respawn players. No need to run it once more. Some EHs are persistent like "getInMan" or "getOutMan" or even "handleDamage". That means they also work after respawn. Usually, BIKI mention that.

If you write a while TRUE loop, like I did above, this loop is persistent also, of course.

  • Like 2

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

×