Jump to content
GaryTheNoTrashCougar

Help - Kill Message show to only the player who gets the kill

Recommended Posts

I have a kill notification script that displays kill type HUD messages (Enemy Killed, Headshot, Long Range Kill, Point Blank Kill, Explosive Kill, Friendly Kill & Suicide), score values & adjusts player rating based on the kill types. The script works but is showing the messages to all players when someone gets a kill. Obviously I want it to just show the message to the player that gets the kill.

 

If anyone could please help me fix this, I will gladly send you a Dora the Explorer sticker book.

 

Thanks

 

init.sqf

[] execVM "Kill_Reward\Kill_Reward.sqf";

Kill_Reward.sqf

player addEventHandler ["Handlescore", {false}];

sleep 0.5;

KillMsg = {
_messages = _this;
_ratingScore = 0;
_messageContent = "<t align='right' size='1.25'>";
{
	_scoreName = _x select 0;
	_ratingScore = _ratingScore + 200;
	_messageContent = _messageContent + format ["<t font='PuristaSemibold'>%1</t>%2<br/>", _scoreName];
} 
forEach _messages;
_messageContent = _messageContent + "</t>";
if (_ratingScore >= 0) then
{
	_messageContent = _messageContent + (format ["<t align='right' color='#ffff00' font='PuristaBold' size='1.4'>+%1</t>", _ratingScore]);
};
[
	parseText _messageContent, 
	[safezoneX, safezoneY + safeZoneH * 0.55, safezoneW * 0.62, safeZoneH * 0.57], 
	nil, 
	1, 
	0.7,
	0 
]
spawn BIS_fnc_textTiles;};

HSKill = {
_messages = _this;
_ratingScore = 0;
_messageContent = "<t align='right' size='1.25'>";
{
	_scoreName = _x select 0;
	_ratingScore = _ratingScore + 250;
	_messageContent = _messageContent + format ["<t font='PuristaSemibold'>%1</t>%2<br/>", _scoreName];
} 
forEach _messages;
_messageContent = _messageContent + "</t>";
if (_ratingScore >= 0) then
{
	_messageContent = _messageContent + (format ["<t align='right' color='#ffff00' font='PuristaBold' size='1.4'>+%1</t>", _ratingScore]);
};
[
	parseText _messageContent, 
	[safezoneX, safezoneY + safeZoneH * 0.55, safezoneW * 0.62, safeZoneH * 0.57], 
	nil, 
	1, 
	0.7,
	0 
]
spawn BIS_fnc_textTiles;};

LRHSKill = {
_messages = _this;
_ratingScore = 0;
_messageContent = "<t align='right' size='1.25'>";
{
	_scoreName = _x select 0;
	_ratingScore = _ratingScore + 300;
	_messageContent = _messageContent + format ["<t font='PuristaSemibold'>%1</t>%2<br/>", _scoreName];
} 
forEach _messages;
_messageContent = _messageContent + "</t>";
if (_ratingScore >= 0) then
{
	_messageContent = _messageContent + (format ["<t align='right' color='#ffff00' font='PuristaBold' size='1.4'>+%1</t>", _ratingScore]);
};
[
	parseText _messageContent, 
	[safezoneX, safezoneY + safeZoneH * 0.55, safezoneW * 0.62, safeZoneH * 0.57], 
	nil, 
	1, 
	0.7,
	0 
]
spawn BIS_fnc_textTiles;};

CQBHSKill = {
_messages = _this;
_ratingScore = 0;
_messageContent = "<t align='right' size='1.25'>";
{
	_scoreName = _x select 0;
	_ratingScore = _ratingScore + 275;
	_messageContent = _messageContent + format ["<t font='PuristaSemibold'>%1</t>%2<br/>", _scoreName];
} 
forEach _messages;
_messageContent = _messageContent + "</t>";
if (_ratingScore >= 0) then
{
	_messageContent = _messageContent + (format ["<t align='right' color='#ffff00' font='PuristaBold' size='1.4'>+%1</t>", _ratingScore]);
};
[
	parseText _messageContent, 
	[safezoneX, safezoneY + safeZoneH * 0.55, safezoneW * 0.62, safeZoneH * 0.57], 
	nil, 
	1, 
	0.7,
	0 
]
spawn BIS_fnc_textTiles;};

LRKill = {
_messages = _this;
_ratingScore = 0;
_messageContent = "<t align='right' size='1.25'>";
{
	_scoreName = _x select 0;
	_ratingScore = _ratingScore + 250;
	_messageContent = _messageContent + format ["<t font='PuristaSemibold'>%1</t>%2<br/>", _scoreName];
} 
forEach _messages;
_messageContent = _messageContent + "</t>";
if (_ratingScore >= 0) then
{
	_messageContent = _messageContent + (format ["<t align='right' color='#ffff00' font='PuristaBold' size='1.4'>+%1</t>", _ratingScore]);
};
[
	parseText _messageContent, 
	[safezoneX, safezoneY + safeZoneH * 0.55, safezoneW * 0.62, safeZoneH * 0.57], 
	nil, 
	1, 
	0.7,
	0 
]
spawn BIS_fnc_textTiles;};

CQBKill = {
_messages = _this;
_ratingScore = 0;
_messageContent = "<t align='right' size='1.25'>";
{
	_scoreName = _x select 0;
	_ratingScore = _ratingScore + 225;
	_messageContent = _messageContent + format ["<t font='PuristaSemibold'>%1</t>%2<br/>", _scoreName];
} 
forEach _messages;
_messageContent = _messageContent + "</t>";
if (_ratingScore >= 0) then
{
	_messageContent = _messageContent + (format ["<t align='right' color='#ffff00' font='PuristaBold' size='1.4'>+%1</t>", _ratingScore]);
};
[
	parseText _messageContent, 
	[safezoneX, safezoneY + safeZoneH * 0.55, safezoneW * 0.62, safeZoneH * 0.57], 
	nil, 
	1, 
	0.7,
	0 
]
spawn BIS_fnc_textTiles;};

FriendlyKill = {
_messages = _this;
_ratingScore = 0;
_messageContent = "<t align='right' size='1.25'>";
{
	_scoreName = _x select 0;
	_ratingScore = _ratingScore + 1000;
	_messageContent = _messageContent + format ["<t font='PuristaSemibold'>%1</t>%2<br/>", toUpper _scoreName];
} 
forEach _messages;
_messageContent = _messageContent + "</t>";
if (_ratingScore >= 0) then 
{
	_messageContent = _messageContent + (format ["<t align='right' color='#ea0000' font='PuristaBold' size='1.4'>-%1</t>", _ratingScore]);
};
[
	parseText _messageContent, 
	[safezoneX, safezoneY + safeZoneH * 0.55, safezoneW * 0.62, safeZoneH * 0.57], 
	nil, 
	1, 
	0.7,
	0 
]
spawn BIS_fnc_textTiles;};

Suicide = {
_messages = _this;
_ratingScore = 0;
_messageContent = "<t align='right' size='1.25'>";
{
	_scoreName = _x select 0;
	_ratingScore = _ratingScore - 200;
	_messageContent = _messageContent + format ["<t font='PuristaSemibold'>%1</t>%2<br/>", toUpper _scoreName];
} 
forEach _messages;
_messageContent = _messageContent + "</t>";
if (_ratingScore >= 0) then
{
	_messageContent = _messageContent + (format ["<t align='right' color='#ffff00' font='PuristaBold' size='1.4'>+%1</t>", _ratingScore]);
};
[
	parseText _messageContent, 
	[safezoneX, safezoneY + safeZoneH * 0.55, safezoneW * 0.62, safeZoneH * 0.57], 
	nil, 
	1, 
	0.7,
	0 
]
spawn BIS_fnc_textTiles;};

if (hasInterface)

then
{
	execVM "Kill_Reward\Kill_Type.sqf";
	
	addMissionEventHandler ["EntityKilled", 
	{
		params ["_killed", "_killer"];
		
		_headDamage = _killed getHitPointDamage "HitHead";
		_distance = _killer distance _killed;
		_minDistance = 100;
		_cqbDistance = 2;
		
		if (isNull _instigator)
		
		then
		{
		
			_instigator = _killer
		
		};
		
		if (isPlayer _killer)
		
		then
		{
			
			if (_killed isKindOf "CAManBase" && {((side group _killed) != playerSide)})
			
			then
			{
			
				if (_distance >= _minDistance && ({_headDamage >= 1;}))
				
				then
				{
					
					player addPlayerScores [1, 0, 0, 0, 0];
					player addRating 100;

					[[killType, _ratingScore]] call LRHSKill;
					
				}
				else
				{
					
					if (_distance <= _cqbDistance && ({_headDamage >= 1;}))
					
					then
					{
						
						player addPlayerScores [1, 0, 0, 0, 0];
						player addRating 75;

						[[killType, _ratingScore]] call CQBHSKill;
						
					}
					else
					{
					
						if (_distance > _cqbDistance && ({_headDamage >= 1;}))
						
						then
						{
						
							player addPlayerScores [1, 0, 0, 0, 0];
							player addRating 50;

							[[killType, _ratingScore]] call HSKill;
							
						};
						
					};
					
					if (_distance >= _minDistance && ({_headDamage < 1;}))
					
					then
					{
					
						player addPlayerScores [1, 0, 0, 0, 0];
						player addRating 50;
						
						[["LONG RANGE KILL ", _ratingScore]] call LRKill;
						
					}
					else
					{
					
						if (_distance <= _cqbDistance && ({_headDamage < 1;}))
						
						then
						{
						
							player addPlayerScores [1, 0, 0, 0, 0];
							player addRating 25;
							
							[["POINT BLANK KILL ", _ratingScore]] call CQBKill;
							
						}
						else
						{
						
							if ((_distance > _cqbDistance && {_distance < _minDistance}) && ({_headDamage < 1;}))
							
							then
							{
							
								player addPlayerScores [1, 0, 0, 0, 0];
								
								[["ENEMY KILLED ", _ratingScore]] call KillMsg;
								
							};
							
						};
						
					};
					
				};
				
			};
			
			if (_killed isKindOf "CAManBase" && {((side group _killed) == playerSide)})
			
			then
			{
				if (_killer != _killed)
				
				then
				{
				
					player addPlayerScores [0, 0, 0, 0, 0];
					
					[["FRIENDLY KILLED ", _ratingScore]] call FriendlyKill;
					
				};
				
				if (_killed == _killer)
				
				then
				{
				
					player addPlayerScores [0, 0, 0, 0, 0];
					
					[["SUICIDE ", _ratingScore]] call Suicide;
					
				};
				
			};
			
		};
		
	}];
	
};

Kill_Type.sqf

0 = [] spawn
{
	while {true} do
	{
		{
			_x addEventHandler ["HitPart",
			{
				(_this select 0) params ["_target", "_shooter", "_projectile", "_position", "_velocity", "_selection", "_ammo", "_vector", "_radius", "_surfaceType", "_isDirect"];
	
				if (_target isKindOf "CAManBase")
	
				then
				{
	
					if (!isPlayer _target)
	
					then
					{
		
						if (isPlayer _shooter)
	
						then
						{
	
							if (_isDirect == true)
	
							then
							{
			
								killType = "HEADSHOT ";
		
							}
							else
							{
								if (_isDirect == false)
					
								then
								{
	
									killType = "EXPLOSIVE KILL ";
					
								};
							};
		
						};

					};

				};

			}];

			_x setVariable ["passedThathitPart",TRUE];
			
		} forEach (allUnits select {isNil {_x getVariable "passedThatHitPart"}});
		
		sleep 2;
		
	};
};

 

Share this post


Link to post
Share on other sites

You have a " addMissionEventHandler ["EntityKilled", " that's being executed on everything that has an interface.  This EH will fire every time an entity is killed, leading to it showing the messages on all machines.  The quick and dirty fix is to add a "if (!local _killer) exitWith {};" right bellow the params of that EH. (untested)  But that function can really use some serious refactoring.

  • Like 2

Share this post


Link to post
Share on other sites

@GaryTheNoTrashCougar, @stanhope,

Simplified,

Spoiler

YOU_ST_format = {	params [["_message", ""], ["_ratingScore", 0]];

	_messageContent = "<t align='right' size='1.25'>" + format ["<t font='PuristaSemibold'>%1</t>%2<br/>", _message] + "</t>";

	if (_ratingScore >= 0) then {
		_messageContent = _messageContent + (format ["<t align='right' color='#ffff00' font='PuristaBold' size='1.4'>+%1</t>", _ratingScore])
	};
	_messageContent
};

YOU_ST_reward = {	params ["_unit", "_killer"];

	private _arr=[];
	if (_unit getHit "head" >0.9) then {	
		_killer addPlayerScores [1, 0, 0, 0, 0];
		_killer addRating 100;
		{_arr pushBack _x} forEach ["HEADSHOT", 250]
	};

	if (_unit distance _killer< 3) then {	
		_killer addPlayerScores [1, 0, 0, 0, 0];
		_killer addRating 100;
		{_arr pushBack _x} forEach ["POINT BLANK", 250]
	};

	if (_unit distance _killer >= 3 && _unit distance _killer< 100) then {
		_killer addPlayerScores [1, 0, 0, 0, 0];
		_killer addRating 100;
		{_arr pushBack _x} forEach ["CQB", 225]
	};

	if (_unit distance _killer> 100) then {	
		_killer addPlayerScores [1, 0, 0, 0, 0];
		_killer addRating 100;
		{_arr pushBack _x} forEach ["DISTANCE KILL", 250]
	};

	private _score= _arr call YOU_ST_format;
	[parseText _score, [safezoneX, safezoneY + safeZoneH * 0.55, safezoneW * 0.62, safeZoneH * 0.57], nil, 1, 0.7,0 ]spawn BIS_fnc_textTiles
};

addMissionEventHandler["EntityKilled",{
	params ["_unit", "_killer"];
	if (!((faction _unit) == (faction _killer)) && !((faction _unit) == "CIV_f")) exitWith {

		if (_killer in allPlayers && local _killer) then {
			[_unit, _killer] call YOU_ST_reward
		};
		true
	}
}];

*Removed indirect for explosives
*Headshots take priority


Have fun!

  • Like 2

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

×