Jump to content
Sign in to follow this  
ELITEeNergizer

How to get killed event handler working?

Recommended Posts

This is my init.sqf

trigTP = false;
pos1=0;
pos2=0;

_xhandle = this addEventHandler ["killed", _this execvm "addActionAgain.sqf"];
tx_myaction = _this addaction ["Teleport somewhere random","activateTP.sqf"];
spawnViktor = _this addaction ["Spawn Lil' Hummy","spawnViktor.sqf"];
spawnSeaFox = _this addaction ["Spawn Foxxy","spawnSeaFox.sqf"];


removeAllWeapons _this;
removeAllItems _this;
_this addWeapon "ACE_Map_Tools";
_this addWeapon "ace_dagr";
_this addWeapon "Binocular";
_this addWeapon "M16A4_GL";
_this addWeapon "ItemCompass";
_this addWeapon "ItemMap";
_this addWeapon "ItemRadio";
_this addWeapon "ACE_HuntIR_monitor";
_this addBackpack "CZ_Backpack_EP1";
for [{_i=0}, {_i<8}, {_i = _i + 1}] do
{
   _this addMagazine ["ACE_HuntIR_M203",1];
};
[_this, "ACE_HuntIR_M203", 60] call ACE_fnc_PackMagazine;
_this addMagazine ["30Rnd_556x45_Stanag",5];

addActionAgain.sqf:

_unit = _this select 0;
_unit removeaction tx_myaction;
_unit removeaction spawnViktor;
_unit removeaction spawnSeaFox;
_unit removeAllEventHandlers "killed";


waituntil {alive _unit};
_unit addEventHandler ["killed", {_unit execVM "addActionAgain.sqf"}];
tx_myaction = _unit addaction ["Teleport somewhere random","activateTP.sqf"];
spawnViktor = _unit addaction ["Spawn Lil' Hummy","spawnViktor.sqf"];
spawnSeaFox = _unit addaction ["Spawn Foxxy","spawnSeaFox.sqf"];

removeAllWeapons _unit;
removeAllItems _unit;
_unit addWeapon "ACE_Map_Tools";
_unit addWeapon "ace_dagr";
_unit addWeapon "Binocular";
_unit addWeapon "M16A4_GL";
_unit addWeapon "ItemCompass";
_unit addWeapon "ItemMap";
_unit addWeapon "ItemRadio";
_unit addWeapon "ACE_HuntIR_monitor";
_unit addBackpack "CZ_Backpack_EP1";
for [{_i=0}, {_i<8}, {_i = _i + 1}] do
{
   _unit addMagazine ["ACE_HuntIR_M203",1];
};
[_unit, "ACE_HuntIR_M203", 60] call ACE_fnc_PackMagazine;
_unit addMagazine ["30Rnd_556x45_Stanag",5];

The main problem is that I'm unsure if I should use the Player variable for init.sqf.

Another problem I have is that the re-spawned player doesn't get the re-added actions or gear. And he still has the default gear.

Edited by ELITEeNergizer

Share this post


Link to post
Share on other sites

player addEventHandler ["killed", {[_this select 0] execVM "addActionAgain.sqf";}];

Share this post


Link to post
Share on other sites

So here's an update of my script:

addAction.sqf:

player removeaction tx_myaction;
player removeaction spawnViktor;
player removeaction spawnBoat;


waituntil {alive player};
tx_myaction = player addaction ["Teleport somewhere random","activateTP.sqf"];
spawnViktor = player addaction ["Spawn Lil' Hummy","spawnViktor.sqf"];
spawnBoat = player addaction ["Spawn Mr.Floaty","spawnBoat.sqf"];

removeAllWeapons player;
removeAllItems player;
player addWeapon "ACE_Map_Tools";
player addWeapon "ace_dagr";
player addWeapon "Binocular";
player addWeapon "M16A4_GL";
player addWeapon "ItemCompass";
player addWeapon "ItemMap";
player addWeapon "ItemRadio";
player addWeapon "ACE_HuntIR_monitor";
player addBackpack "CZ_Backpack_EP1";
for [{_i=0}, {_i<8}, {_i = _i + 1}] do
{
   player addMagazine ["ACE_HuntIR_M203",1];
};
[player, "ACE_HuntIR_M203", 60] call ACE_fnc_PackMagazine;
player addMagazine ["30Rnd_556x45_Stanag",5];

init.sqf

trigTP = false;
pos1=0;
pos2=0;

_xhandle = player addEventHandler ["killed", {_this execvm "addActionAgain.sqf"}];
tx_myaction = player addaction ["Teleport somewhere random","activateTP.sqf"];
spawnViktor = player addaction ["Spawn Lil' Hummy","spawnViktor.sqf"];
spawnBoat = player addaction ["Spawn Mr.Floaty","spawnBoat.sqf"];


removeAllWeapons player;
removeAllItems player;
player addWeapon "ACE_Map_Tools";
player addWeapon "ace_dagr";
player addWeapon "Binocular";
player addWeapon "M16A4_GL";
player addWeapon "ItemCompass";
player addWeapon "ItemMap";
player addWeapon "ItemRadio";
player addWeapon "ACE_HuntIR_monitor";
player addBackpack "CZ_Backpack_EP1";
for [{_i=0}, {_i<8}, {_i = _i + 1}] do
{
   player addMagazine ["ACE_HuntIR_M203",1];
};
[player, "ACE_HuntIR_M203", 60] call ACE_fnc_PackMagazine;
player addMagazine ["30Rnd_556x45_Stanag",5];

But both the scripts only work for one person. How can I get it working for all players?

Share this post


Link to post
Share on other sites

player addEventHandler ["killed", {[_this select 0] execVM "addActionAgain.sqf";}];

Passed array: [unit, killer]

unit: Object - Object the event handler is assigned to

killer: Object - Object that killed the unit

'_this select 0' equates to the player this is attached to. - _this is the array made up of unit and killer.

As for all the players - using this in the init.sqf should work as the its create on the player -

what you need to do is pass the variable defined as '_this select 0', to the addatcion script

in the addaction script - have _unit = _this select 0;

Then replace player with _unit. This should ensure the correct player has his addactions removed and reinstated

Share this post


Link to post
Share on other sites

What I don't get is that there's 2 '_this select 0'

Shouldn't "unit: Object - Object the event handler is assigned to " be already passed to addAction.sqf if I followed your advice? Why would I need to use '_this select 0' again if the object is passed via variable and not as an array?

Share this post


Link to post
Share on other sites

Because the eh is setup that way and u r accessing a remote script that does not know who this specific player is. Player in mp is not the same as player in single player.

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  

×