Jump to content
Sign in to follow this  
DarealAl

A3Wasteland addMPEventhandler

Recommended Posts

Hey there...

I am verry new to Arma-Scripting at all, i googled a lot and tested a lot but i cant find the answer...

Is there any1 able to tell me why this code shows target and killer as the same when the target is killed by KI ?


if (!isServer) exitwith{};

_target addMPEventHandler ["mpkilled", {_this call f_Kill}]; 

f_Kill = { 
	killer = _this select 1;
	killerName = name killer;
	publicVariable "killer";
	publicVariable "killerName";
   hint format ["Target was killed by %1",killerName];
};  

Share this post


Link to post
Share on other sites

It entirely depends on what _target is. Also, publicVariable "killer" could cause issues on other clients, what if two people are killed at the same time? You *could* potentially end up with multiple death messages for the same person.

Share this post


Link to post
Share on other sites

_target is a randomly selected Player from playableUnits.

i tried _killer b4 but had the same Problem

if (!isServer) exitwith {};

// Select random Player
_players = playableUnits;
_target = _players select (floor (random (count _players)));
_targetName = name _target;

// Add EventHandler to the selected Player
_target addMPEventHandler ["mpkilled", {_this call f_Kill}]; 

// Function to be executed when selected Player is killed
f_Kill = {
	_killer = _this select 1;
	_killerName = name _killer;
       	hint format ["Target was killed by %1",killerName];
};  

// Wait for selected Player to die
waitUntil { 
	sleep 10;
	! alive _target;
};

// Remove EventHandler
_target removeAllMPEventHandlers "mpkilled";

Edited by DarealAl

Share this post


Link to post
Share on other sites

I know functions are faster and all, but wouldn't it just be easier to do it all within the EH and then assign the EH to all the players:

{

if (isPlayer _x) then {

_x addMPEventHandler ["mpkilled", {hint format ["%1 was killed by %2",(_this select 0), (_this select 1)];}];

}foreach allunits;

Edited by JShock

Share this post


Link to post
Share on other sites

There is only 1 Player with that handler and always will be...

The Problem is, as in the Topic, i always get the target as killer

when the target is killed by KI.

In fact, later need to check if

killer == target // suicide

killer == KI // Bad luck

killer == other Player // Perfekt

but when the code always returns killer==target i can put my projekt to trash :(

Edited by DarealAl

Share this post


Link to post
Share on other sites

What or who is KI, I'm lost there...

But I don't see why this code couldn't work:

player addMPEventHandler ["mpkilled", {hint format ["%1 was killed by %2",(_this select 0), (_this select 1)];}];

Share this post


Link to post
Share on other sites

Maybe see if the normal Killed EH fixes it???

player addEventHandler ["Killed", {hint format ["%1 was killed by %2",(_this select 0), (_this select 1)];}];

But other than that, I would be lost as to why it's returning the wrong name.

Share this post


Link to post
Share on other sites

Is it suggested to use "killed" in multiplayer missions ? i always think the "mpkilled" is for MP missions.

Share this post


Link to post
Share on other sites
Is it suggested to use "killed" in multiplayer missions ? i always think the "mpkilled" is for MP missions.

The only difference between the two that I saw on the EH page was the the MP was executed on all machines, opposed from the normal Killed EH. But like I said, I'm now just speculating.

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  

×