Jump to content
Tuliq

[SCRIPT]Basic killticker

Recommended Posts

UPDATED: 07.04.2013!

Thought I'd post this. This is a simple more advanced killticker I've created for use in my own missions. Thought some other people might have use of it as well. It's not hard to implement.

1411593.jpeg1411606.jpeg

For AI it displays classname of unit, for player it displays user name. It shows a maximum of 8 kills at a time, but this you are of course free to change.

killTicker.sqf

tlq_killTicker = { 

_this addMPEventHandler ['MPKilled',{

	_unit = _this select 0;
	_killer = _this select 1;

	_newKill = [_unit,_killer];

	if (count tlq_killArray > 100) then {tlq_killArray = []};

	tlq_killArray set [count tlq_killArray,_newKill call tlq_parseKill];

	[] spawn tlq_killList;
	if (player == _killer) then {_newKill spawn tlq_killPopUp};


}
];

};



tlq_parseKill = {

_line = "";
_killerName = "";
_victimName = "";
_killerString = "";
_victimString = "";
_killerColor = "#99D5FF";
_victimColor = "#99D5FF";


_victim = _this select 0;
_killer = _this select 1;

if (!(isplayer _killer)) then {
	_killerName = getText (configFile >> "CfgVehicles" >> format["%1",typeOf _killer] >> "Displayname");
	if(vehicle _killer != _killer) then {_killerName = getText (configFile >> "CfgVehicles" >> format["%1 crew",typeof vehicle _killer] >> "Displayname")};
	}else{_killerName = name _killer};

if (!(isplayer _victim)) then {
	_victimName = getText (configFile >> "CfgVehicles" >> format["%1",typeOf _victim] >> "Displayname");
	if(vehicle _victim != _victim) then {_victimName = getText (configFile >> "CfgVehicles" >> format["%1 crew",typeof vehicle _victim] >> "Displayname")};
	}else{_victimName = name _victim};

if ((_killer==player) or (_killer == vehicle player)) then
	{
	_killerColor = "#ffff00"; //yellow
	}
	else
	{
	_killerColor = side group _killer call BIS_fnc_sideColor;

		_r = _killerColor select 0;
		_g = _killerColor select 1;
		_b = _killerColor select 2;

	_killerColor = [_r+0.1,_g+0.1,_b+0.1];

	_killerColor = _killerColor call BIS_fnc_colorRGBtoHTML;

	};

if (_victim==player) then
	{
	_victimColor = "#ffff00"; //yellow
	}
	else
	{
	_victimColor = side group _victim call BIS_fnc_sideColor;

		_r = _victimColor select 0;
		_g = _victimColor select 1;
		_b = _victimColor select 2;

	_victimColor = [_r+0.1,_g+0.1,_b+0.1];

	_victimColor = _victimColor call BIS_fnc_colorRGBtoHTML;

	};

_killerString = format["<t color='%1'>%2</t>",_killerColor ,_killerName];
_victimString = format["<t color='%1'>%2</t>",_victimColor,_victimName];

//the line which shows the final formatted kill
_line = switch(true) do {
	case(_killer == _victim): {format ["%1 killed themselves",_killerString]};
	case(isNull _killer): {format ["Bad luck for %1",_victimString]};
	default {format ["%1 killed %2",_killerString,_victimString]};
};

_line;

};


tlq_killPopUp = {

_victim = _this select 0;
_killer = _this select 1;


_victimName = "";	
_victimString = "";
_victimColor = "#99D5FF";


if (!(isplayer _victim)) then {
	_victimName = getText (configFile >> "CfgVehicles" >> format["%1",typeOf _victim] >> "Displayname");
if(vehicle _victim != _victim) then {_victimName = getText (configFile >> "CfgVehicles" >> format["%1 crew",typeof vehicle _victim] >> "Displayname")};
	}else{_victimName = name _victim};

_victimColor = (side group _victim call BIS_fnc_sideColor) call BIS_fnc_colorRGBtoHTML;

_victimString = format["<t color='%1'>%2</t>",_victimColor,_victimName];

_line = if ((_killer == player) and (_victim == player)) then {
	"<t size='0.5'>You killed yourself</t>";
} else {
	format ["<t size='0.5'>You killed %1</t>",_victimString];
};	

	[_line,0,0.8,2,0,0,7017] spawn bis_fnc_dynamicText;

};



tlq_killList = {


//flush kills and  show most recent
if (time - tlq_killTime > 37) then {
	tlq_displayedKills = [];
};


tlq_displayedKills set [count tlq_displayedKills, tlq_killArray select (count tlq_killArray - 1)];



_tickerText = "";


_c = 0;
for "_i" from (count tlq_displayedKills) to 0 step -1 do{

	_c = _c + 1;

	_tickerText = format ["%1<br />%2",tlq_displayedKills select _i,_tickerText];

	if (_c > 8) exitWith{};

};

hintsilent parsetext _tickerText;

//["<t size='0.4' align='right'>" + _tickerText + "</t>",safeZoneX,safeZoneY,10,0,0,7016] call bis_fnc_dynamicText;


tlq_killTime = time;

};



//declare global variables

tlq_killArray = [];
tlq_displayedKills = [];
tlq_killTime = 0;

//start kill registration for player
if (!isNull player) then {
player spawn tlq_killTicker;
};

if (isServer) then {
//ai
{
	if (!(isPlayer _x)) then {
		_x spawn tlq_killTicker};
} forEach allUnits;
};

Hotfix 07.04.2013:

  • Tweaked things regarding dedicated servers

Changes 31.03.2013:

  • Fixed bug that caused no kills to get displayed clientside
  • Fixed deletion of kills when lot of kills were happening
  • Moved kill detection clientside because of locality issues

Changes 30.03.2013:

  • Fixed bugs that caused script not to fire
  • Brightened up colors on kills to increase readability
  • Made global variables unique as to not interfere with other scripts
  • Added "tlq_killTicker_init" variable to check if script has initialized

Changes 21.03.2013:

  • Now registers much more accurately for aoe-based weapons (grenades, bombs)
  • Kill detection handled by server (or hosting player)
  • Colors for killed players now reflect their ingame color (blufor blue, opfor red).
  • Fixed some bugs relating to unexpected types of deaths
  • Now registers kills for ALL editor-placed units by default (includes playable units waiting to spawn)

Known bugs:

  • When player disconnects from an ai-disabled slot, script will fire.

Installation:

Place in your mission folder and run "killTicker.sqf" from init.sqf like so:

null = execVM "killTicker.sqf";

To add kill detection to units created during mission, run the following command after creation:

yourunitName spawn tlq_killTicker;

Edited by Tuliq

Share this post


Link to post
Share on other sites

Great! I updated it to make it a lot easier to implement. Remember that this script uses hint for its kill display, so it might not be for everyone.

Share this post


Link to post
Share on other sites

Thanks! Nice to see this getting some exposure! :)

Share this post


Link to post
Share on other sites

Lovely little script! Works great when i'm not trying to use the pictures, but when I remove all of the //'s, I get a error on line 91, which is

<img size='2' image='%3'/>

Isn't this an HTML script? How would I use this? As even though everything us uncommented, but leave this line commented, no pictures show :(

Share this post


Link to post
Share on other sites

Very nice script. I changed just one line just so I can see the weapon name in the kill message. You did all the work naming things I just used them :). Now if I can figure out how to get it to say the name of the gun instead of the classname.

{format ["%1 killed %2 with %3",_killerString,_victimString,_killweapon]};

Share this post


Link to post
Share on other sites

Hey thanks! Glad you have found use of it. To show the real name of the weapon you could create a weaponName variable and grab the displayname from config like so:

_weaponName = getText(configFile >> "CfgWeapons" >> format ["%1",_killweapon] >> "displayname");

replace this variable with the killerweapon one on the line format.

Adding pictures require thar you copy the <img> stuff into the string of the _line variable. It is structured text code and doesnt work alone. You need to also add the weaponpic variable into the format array. Hope this helps!

Share this post


Link to post
Share on other sites

ahh very nice. Learn something new every day. I also "borrowed" a line from another mission I played where you get the distance. Added that to the text and it looks pretty spiffy. Like you, I agree the pictures make it look... blech. However with weapon name/distance it looks nice and gets the point across.

For those wanting the extra lines...

just add

_dist = round (_victim distance _killer);

then change {format ["%1 killed %2 with %3 from %4 meters",_killerString,_victimString,_weaponName,_dist]};

and you get

"Bob killed Bob with peashooter from 600 meters"

Share this post


Link to post
Share on other sites

I've noticed that when using this with AI units spawned during the mission, these units don't have the handler added to them. Perhaps the bit that adds the event handler could be changed to a loop that only adds the handler to units that don't already have it?

Share this post


Link to post
Share on other sites

so should i be using

null = "ALL" execVM "killTicker.sqf";

or

unit spawn killticker;

if i want this to show all kills during a TDM?

Share this post


Link to post
Share on other sites

Script has been updated :)

The new script might suit you better, blinger. It should work for all playable units present in edtior.

Share this post


Link to post
Share on other sites

Nice work Tuliq... really like the script!!

Share this post


Link to post
Share on other sites

I've not been able to get this to work for me. I'm not sure if it's because I am spawning AI during the mission, but even when I die the ticker doesn't fire. Since the script doesn't use the "ALL" settings anymore, is there any other change that might be needed to ensure this works? Also I noticed you have removed the weapons and distance parts, are you going to add those or are they removed because there is a problem?

Share this post


Link to post
Share on other sites

During some tests I have found that there are a bunch of problems with the script right now. I can upload the version I am currently using myself , which has endured extensive testing, and most of the problems like you mentioned should be fixed. I will do this ASAP. For as the weapon and distance parts, I removed them because I personally had no use of them, and they did not register correctly for grenades or bombs. Using a combination of the "killed" and "fired" eventhandler, weapon detection could be done much more accurately. That would be my ideal solution.

Share this post


Link to post
Share on other sites

Script is updated again, should work a lot more reliably now.

If anyone encounters problems making it work, please post here! :)

Edited by Tuliq

Share this post


Link to post
Share on other sites

Tuliq, sorry for newbie question, but how exactly run your script. i call it in init.sqf, and... then? :(

Share this post


Link to post
Share on other sites

No problem! After you add the line

null = execVM "killTicker.sqf"

, the script should start running for all units present in editor. If you are adding kill detection to units spawned in during mission, you must do a

%unitname% spawn tlq_killTicker;

I just fixed a bug that had caused no kills to display if you were a client on a server. Should be fixed now.

Just had another major fix-session with my buddy. We seem to have fixed most of the problems I know of atm. I recommend everyone using this script to get the current version posted in the op before trying the script.

Edited by Tuliq

Share this post


Link to post
Share on other sites
To show the real name of the weapon you could create a weaponName variable and grab the displayname from config like so:
_weaponName = getText(configFile >> "CfgWeapons" >> format ["%1",_killweapon] >> "displayname");

replace this variable with the killerweapon one on the line format.

Thanks for the great script Tuliq! We got everything working except for the weapon part. Please correct me if I overlook something! Do I need to setup a configFile "CfgWeapons" manually to display the killweapon? Or do I need to define _killweapon in someway, which is not in killTicker.sqf by default? (Despite you have excluded the weapon info due to the fact it does not work correctly with grenades and such, we would like to implement it.)

Share this post


Link to post
Share on other sites

Hi! Thanks for the praise! Basically add:

_killweapon = getText(configFile >> "CfgWeapons" >> format ["%1",currentWeapon _killer] >> "displayname");

after _killer has been defined in the tlq_parsekill function. Then edit _line as such:

	_line = switch(true) do {
	case(_killer == _victim): {format ["%1 killed themselves",_killerString]};
	case(isNull _killer): {format ["Bad luck for %1",_victimString]};
	default {format ["%1 killed %2 with %3",_killerString,_victimString,_killWeapon]};
};

I added the _killweapon string into the format of the default case of the switch (which is the standard kill message). Of course you will have to adjust the formatting of the kill line to your own tastes :) Now it is like "Slammin killed Tuliq with BB Gun".

For the next version of the script I want to get rid of the hint - box, and instead use bis_fnc_dynamicText to display the kill list. Only problem is I just can't seem to get the positioning right across all different aspect ratios and interface sizes. Would totally appreciate if someone could tell me how to do this.

Edited by Tuliq

Share this post


Link to post
Share on other sites

Cheers Tuliq! We've got it all working now with the two codes you posted above. Wish I could be of any assistance with your bis_fnc_dynamicText-positioning request. I keep an eye out if I come across something that might be useful!

Share this post


Link to post
Share on other sites

Hi,

i am new in this forums and this ist my first try to creating MP maps.

I tryed to install and run the killticker for me and its working when i test it in the editor.

But when i am uploading the mpmission on a server and try to test it, the killticker does not work.

Can anybody help me to fix that problem, what did i do wrong.

Share this post


Link to post
Share on other sites

Hey! I think this could me my fault. I don't really have much experience with dedi-server scripting. Can you try this fix?

Go to

if (local player) then {
player spawn tlq_killTicker;
};

and replace with

if (!isNull player) then {
player spawn tlq_killTicker;
};

Maybe this will work :)

Also, are you exporting the mission into PBO format? If that is the case, it would be wise to unpack the PBO and check if all the scripts were transferred correctly. Use something like Eliteness to unpack and repack pbo's.

Edited by Tuliq

Share this post


Link to post
Share on other sites

Thanks for the quick response.

Also, are you exporting the mission into PBO format? If that is the case, it would be wise to unpack the PBO and check if all the scripts were transferred correctly. Use something like Eliteness to unpack and repack pbo's.

I have checked this, all files incl. killTicker.sqf are on the server.

sry but where can i find this lines in killTicker.sqf ?

if (local player) then {

player spawn tlq_killTicker;

};

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

×