Jump to content
Sign in to follow this  
Fusion_Marduc

Adding EventHandler after bis_fnc_spawnvehicle

Recommended Posts

Hi,

I'm spawning a BMP3 with crew using BIS function 'bis_fnc_spawnvehicle'. The code looks like this.

_spawnLocation = [armorCreationDistance] call fcSetSpawnLocation;

_armorArray = [_spawnLocation,1,"BMP3",east] call bis_fnc_spawnvehicle;

(_armorArray select 0) addEventHandler ["Dammaged",{(_armorArray select 0) execVM "armor_dammaged.sqf"}];

_crew = _armorArray select 1;

{
_x execVM "init_unit.sqf";
}
forEach _crew;

Everything works except for the EventHandler I want to add to the created vehicle (which according to biki is the first value in the return array). The "init_unit.sqf" adds eventhandlers for the crew and that works.

Any ideas.

Greetz Marduc.

Share this post


Link to post
Share on other sites

When the eventhandler actually runs, it will not have any knowledge or access to variable _armorArray?

Share this post


Link to post
Share on other sites

I don't need _armorArray when the Eh runs. I just want to link the Dammaged-Eh to the created BMP3. It works for the BMP3 crew. In script "init_unit.sqf" I link a Killed-Eh to a crew member.

Share this post


Link to post
Share on other sites
(_armorArray select 0) addEventHandler ["Dammaged",{([size=4][color=DarkRed][b]_this[/b][/color][/size] select 0) execVM "armor_dammaged.sqf"}];

Xeno

Share this post


Link to post
Share on other sites

Ok, I tried the advise.

Script part that creates the armor with crew

_spawnLocation = [armorCreationDistance, getpos player] call fcSetSpawnLocation;

_armorArray = [_spawnLocation,1,"BMP3",east] call bis_fnc_spawnvehicle;

(_armorArray select 0) execVM "init_armor.sqf";

_crew = _armorArray select 1;

{
_x execVM "init_unit.sqf";
}
forEach _crew;

sleep armorCreationDelay;

The init_armor.sqf holds:

private ["_EhIdx"];

_EhIdx = _this addEventHandler ["Dammaged",{_this execVM "armor_dammaged.sqf"}];

//--------------------------------------------------------------------------------- E O D --
hint format["Init %1 (Eh %2)",_this,_EhIdx];

The hint command shows : Init 0 1-1-A:3 (Eh 0)

The armor_dammaged.sqf

hint "Armor Dammaged";

This hint doesn't show up.

Any more ideas. Eh index 0 should be correct because its the first Eh for the object.

Grtz Marduc.

Share this post


Link to post
Share on other sites

Try this:

_pos = [(getMarkerPos "s1" select 0), (getMarkerPos "s1" select 1), 0];

_grpv = createGroup east;

[_pos, random 360, "BMP3", _grpv] call BIS_fnc_spawnVehicle;

vehicle leader _grpv addEventHandler ["Dammaged",{_this execVM "dammaged.sqf"}];

Share this post


Link to post
Share on other sites

It seems that the "Dammaged" EH is only triggered twice per damaged part of an object / vehicle. First time when damage reaches 50% (0.5) and second time at 70% (0.7).

Share this post


Link to post
Share on other sites
Ok, I tried the advise.

Xeno: (_this select 0) execVM "armor_dammaged.sqf"

Your: _this execVM "armor_dammaged.sqf"

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
Sign in to follow this  

×