Jump to content

Recommended Posts

I'm finding some difficulty: 

 

in a few cases I'm seeing that count will not work and will not cause an error..

only way I figured this out is playing around with forEach ...

 

 

ie:

 

count allUnits; works

count  _Units; doesn't cause error "but" doesn't work

 

I could be mistaken , I'm very tierd.. anyone else having any issues with this?

Share this post


Link to post
Share on other sites

Could you use it in example that you are trying to use?

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 isEqualTo _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 isEqualTo player) or (_killer isEqualTo 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 isEqualTo 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 isEqualTo _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 isEqualTo player) and (_victim isEqualTo 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;

};

//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};
	}count allUnits;<---------------------------only works if its foreach
};

Share this post


Link to post
Share on other sites

you could try to return true inside ur count. i do that in each count with code in it.

Share this post


Link to post
Share on other sites

Are you running this script with doFSM?

 

Description is saying:

_units    list of all persons in subgroup

try debug _units. See what is in that variable before using it.

systemChat format ["%1", _units];

Share this post


Link to post
Share on other sites

(removed)

Edited by cx64

Share this post


Link to post
Share on other sites

Hmm, am I seeing multiple functions in the same file? I think it would be wise to put each function inside a different file, if it actually looks like this.

 

Nothing wrong with having multiple functions declared in a single file.

 

I found the original post for this script and it's using allUnits.  It's also meant to be called from the init.sqf so it just loads once and not run as an FSM.  

 

I can only imagine in his sleep delirium dr death jm remembered that _units can be a special variable and thought it always was, so he tried it? :)

  • Like 1

Share this post


Link to post
Share on other sites

I think it would be wise to put each function inside a different file, if it actually looks like this.

 

I want to improve this a wise idea - it is better to put each command in a separate file!

 

Sarcasm mode OFF. Sorry

  • Like 1

Share this post


Link to post
Share on other sites

I want to improve this a wise idea - it is better to put each command in a separate file!

 

Sarcasm mode OFF. Sorry

How about each character in it's own file?

Share this post


Link to post
Share on other sites

How about each character in it's own file?

Fn_WiseExecute = {
	call compile (_this apply {loadFile _x} joinString "")
};

Fn_TestWiseExecute = {
	["s.sqf", "y.sqf", "s.sqf", "t.sqf", "e.sqf", "m.sqf", "C.sqf", "h.sqf", "a.sqf", "t.sqf", "spc.sqf",
		"dqt.sqf", "C.sqf", "o.sqf", "d.sqf", "e.sqf", "spc.sqf", "W.sqf", "i.sqf", "s.sqf", "e.sqf", "l.sqf", "y.sqf", "xcl.sqf", "dqt.sqf"] call Fn_WiseExecute
};

Demo mission: CodeWisely.Altis

 

Now I am considering idea how to put each file containing a character on a separate hard drive

  • Like 1

Share this post


Link to post
Share on other sites


_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];

if (player isEqualTo _killer) then {_newKill spawn tlq_killPopUp};


// instead of _newKill = [_unit, _killer] you can use _this variable containing same values

_this call tlq_parseKill;

_this spawn tlq_killPopup;

// if you want to add something at the end of array you can use more effective pushBack command

tlq_killArray pushBack (_this call tlq_parseKill);

  • Like 1

Share this post


Link to post
Share on other sites
if (isServer) then {
	//ai
	{
		if (!(isPlayer _x)) then {
			_x spawn tlq_killTicker};
	}count allUnits;<---------------------------only works if its foreach
};

 

In this case you execute something for each element of array. Who you trying to enumerate array elements using count command instead of forEach?

Share this post


Link to post
Share on other sites

Nothing wrong with having multiple functions declared in a single file.

 

I found the original post for this script and it's using allUnits.  It's also meant to be called from the init.sqf so it just loads once and not run as an FSM.  

 

I can only imagine in his sleep delirium dr death jm remembered that _units can be a special variable and thought it always was, so he tried it? :)

yup... you figured it... I was trying ... (I'm still a noob).

it seems as I learn new code/scripts/engine is updated.. I'm gone 12 hours a day (work) I cant keep up, lol

I get up 4am just to look thru things arma3 related .. get to work at 530 am... get home anywere from 4pm to 6 pm... cook and clean (kids)... shower and then arma3 till bed ... (what a life I have )

Share this post


Link to post
Share on other sites

I want to improve this a wise idea - it is better to put each command in a separate file!

 

Sarcasm mode OFF. Sorry

I like this way of thinking

Share this post


Link to post
Share on other sites
// instead of _newKill = [_unit, _killer] you can use _this variable containing same values
_this call tlq_parseKill;
_this spawn tlq_killPopup;


// if you want to add something at the end of array you can use more effective pushBack command
tlq_killArray pushBack (_this call tlq_parseKill);

I'm still a noob... I understand but :banghead:

Share this post


Link to post
Share on other sites

In this case you execute something for each element of array. Who you trying to enumerate array elements using count command instead of forEach?

count is a tiny little faster... optimizing is my ocd

Share this post


Link to post
Share on other sites

also .. script above is just an example...

its edited to fit my needs...

but we all should maybe make a thread somewhere, just for optimizing code.

id love to post some code and have you pro's rip into it... ;)

Share this post


Link to post
Share on other sites

id love to post some code and have you pro's rip into it... ;)

 

I'll start!  Click MultiQuote on the various messages you want to reply to, then click the "Reply to X posts" at the very bottom to condense them all into one post. :)

  • 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

×