Jump to content
Sign in to follow this  
XxKAIMANxX

Get killer info

Recommended Posts

Hi, i'm learning some mission scripting and i would like to get the name of the killer of another player or AI and the weapon used and print that info in the chat. For example: "Player1 killed Player2 with MX 6,5mm"

The problem is that i have no idea where to start from, so if you guys could help me... Thanks.

Share this post


Link to post
Share on other sites

Method#1 (not so great)

init.sqf

{
   _id = _x addMPEventHandler ["MPKilled", {
	_victimName = name (_this select 0);
	_killerName = name (_this select 1);
	_weaponName = getText (configFile >> "cfgWeapons" >> currentWeapon (_this select 1) >> "displayname");
       hintSilent format ["%1 was killed by %2 with a %3", _victimName, _killerName, _weaponName];
   }];
} foreach allUnits; 

note: According to the wiki it's not good practice to run code directly from a MP eventHandler's code space, as the code space will be transferred over network, each time the EH fires. You'd be better off storing the code into a variable / function, and running the function from the EH instead == smaller data to transfer over the network.

Method#2 (proper)

init.sqf

KAI_fnc_killedInfo = {
_victimName = name (_this select 0);
_killerName = name (_this select 1);
_weaponName = getText (configFile >> "cfgWeapons" >> currentWeapon (_this select 1) >> "displayname");
hintSilent format ["%1 was killed by %2 with a %3", _victimName, _killerName, _weaponName];
};

{
   _id = _x addMPEventHandler ["MPKilled", {
	_nul = _this call KAI_fnc_killedInfo;
   }];
} foreach allUnits; 

Edited by Iceman77
  • Like 1

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  

×