Jump to content
Sign in to follow this  
Dariox

Score for kill AI

Recommended Posts

Hello everyone, I have a game mode style PvP domination, I would like to assign the score for Kill AI that spawns via script. any idea?

thx Dario

Share this post


Link to post
Share on other sites

thx for reply ;)

I have a hud in a game where I add the score of the several goals, with, scoreW = scoreW +1; pubblicVariable "ScoreW";

"ScoreW" updates the score in the hud.

how can I use your example, to add the score of AI killed?

sorry Google traslate ;)

Share this post


Link to post
Share on other sites

Just put your code in place of the "(_this select 1) addScore 1;"

Share this post


Link to post
Share on other sites
Just remember that the "killed" event handler is local, so you should only create them on the server

or do it with bis_fnc_mp...

Share this post


Link to post
Share on other sites

I'm sorry guys, but I need a new script to add the kill AI for both factions, my variables are scoreW and scoreE. can you help?

thx

Dario

Share this post


Link to post
Share on other sites

Just add a couple if statements checking the side of the killer:

if (side (_this select 1) isEqualTo WEST) then
{
   scoreW = scoreW+1; publicVariable "scoreW";
};
//same for other side

Share this post


Link to post
Share on other sites

but the script as he does know that the AI, created by a script, are killed?

I'm sorry but I did not understand. I noob ;)

in this way?

_AI addEventHandler ["Killed",
{

if (side (_this select 1) isEqualTo WEST) then
{
   scoreW = scoreW+1; publicVariable "scoreW";
};
   (_this select 1) addScore 1;
}];

but who starts this script?

many thx

Dario

Edited by Dariox

Share this post


Link to post
Share on other sites
or do it with bis_fnc_mp...

This is a really good way to create a lot of unnecessary traffic over the network. Since the clients never need to have the event handlers installed anyway, this method should be avoided like ebola

Edited by DreadedEntity

Share this post


Link to post
Share on other sites
This is a really good way to create a lot of unnecessary traffic over the network. Since the clients never need to have the event handlers installed anyway, this method should be avoided like ebola

Tell it to the Arma developpers !!!!

Share this post


Link to post
Share on other sites

I have this code, but no show and no publicvariabile " punteggioW = punteggioW +1; publicVariable "punteggioW";" in Multiplayer, any idea?

thx

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};

	if (side (_this select 1) isEqualTo WEST) then
{
   punteggioW = punteggioW +1; publicVariable "punteggioW";
};
if (side (_this select 1) isEqualTo East) then
{
   punteggioE = punteggioE +1; publicVariable "punteggioW";
};

Share this post


Link to post
Share on other sites
Tell it to the Arma developpers !!!!

They've done a well enough job already, now it's up to us as script writers to write low-cost code

Share this post


Link to post
Share on other sites
I have this code, but no show and no publicvariabile " punteggioW = punteggioW +1; publicVariable "punteggioW";" in Multiplayer, any idea?

thx

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};

	if (side (_this select 1) isEqualTo WEST) then
{
   punteggioW = punteggioW +1; publicVariable "punteggioW";
};
if (side (_this select 1) isEqualTo East) then
{
   punteggioE = punteggioE +1; publicVariable "punteggioW";
};

Cause you need to close off the event handler and the function add the following at the end of your code:

}];
};

Share this post


Link to post
Share on other sites

I'm sorry,

I copied and pasted only part of the code, this is the complete code, can you correct it?

I realized that if I add in an AI editor that works. As if I create a soldier with a script that does not recognize it.

Thx

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};

	if (side (_this select 1) isEqualTo WEST) then
{
   punteggioW = punteggioW +1; publicVariable "punteggioW";
};
if (side (_this select 1) isEqualTo East) then
{
   punteggioE = punteggioE +1; publicVariable "punteggioW";
};

}
];

};



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;
};

---------- Post added at 11:50 ---------- Previous post was at 11:46 ----------

I

put the code under IsServer ?

Edited by Dariox

Share this post


Link to post
Share on other sites

That's because if you spawn an AI later, this script has already run once at mission start (for all editor spawned AI), so you need to loop this in a fashion that is friendly to performance but also gives you the desired effects.

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  

×