Jump to content
Smart Games

MpEventHandler "mpkilled" trouble

Recommended Posts

I added the following code to the init of an unit:

this addMPEventHandler ["mpkilled",{[(_this select 0), (_this select 1)] call fnc_unitkill}];

 

I made a money and kill system and i dont want the player to get a reward for teamkilling, thats why i had the following idea:

fnc_unitkill =
{
	params ["_victime","_killer"];


	if (side _victime == side _killer) then {} else
	{
	_money = _killer getVariable "money";
	_kills = _killer getVariable "kills";
	_exp = _killer getVariable "exp";

	_killer setVariable ["money",_money + 100];
	_killer setVariable ["kills",_kills + 1];
	_killer setVariable ["exp", _exp + 100];

	_lgk = _killer getVariable "longestkill";
    _dst = _killer distance _victime;

    if (_dst > _lgk) then {_killer setVariable ["longestkill",_dst]};
    };
};

 

But it dont work...

I tried to call the function with

this addMPEventHandler ["mpkilled",{[_this] call fnc_unitkill}];

 

and then..

fnc_unitkill =
{
	_victime = _this select 0;
	_killer = _this select 1;


	if (side _victime == side _killer) then {} else
	{
	_money = _killer getVariable "money";
	_kills = _killer getVariable "kills";
	_exp = _killer getVariable "exp";

	_killer setVariable ["money",_money + 100];
	_killer setVariable ["kills",_kills + 1];
	_killer setVariable ["exp", _exp + 100];

	_lgk = _killer getVariable "longestkill";
    _dst = _killer distance _victime;

    if (_dst > _lgk) then {_killer setVariable ["longestkill",_dst]};
    };
};

doesnt work, too.

 

 

 

If i only call it with

this addMPEventHandler ["mpkilled",{[_this select 1] call fnc_unitkill}];

 

then...

	params ["_killer"];

	_money = _killer getVariable "money";
	_kills = _killer getVariable "kills";
	_exp = _killer getVariable "exp";

	_killer setVariable ["money",_money + 100];
	_killer setVariable ["kills",_kills + 1];
	_killer setVariable ["exp", _exp + 100];

	_lgk = _killer getVariable "longestkill";
    _dst = _killer distance _victime;

    if (_dst > _lgk) then {_killer setVariable ["longestkill",_dst]};

it works, but now you get a reward for killing your friends.

 

I really need your help, thanks.

  • Like 2

Share this post


Link to post
Share on other sites
3 hours ago, Smart Games said:

if (side _victime == side _killer)

 

Hello there Smart Games !

 

Did you think of using the addMissionEventHandler ?

https://community.bistudio.com/wiki/Arma_3:_Event_Handlers/addMissionEventHandler#EntityKilled

 

PS : you could use an exitwith{} there.

  • Thanks 1

Share this post


Link to post
Share on other sites

dead player side is civilian, use 
if (side group _victime != side group _killer) then {,,,,,,,,,}

  • Like 2

Share this post


Link to post
Share on other sites

There's a function that can return better data, can't remember them right now, am afk. fnc_sideid or fnc_sidetype I think

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

×