Jump to content
Sign in to follow this  
doomnet

kill death ratio calculator

Recommended Posts

Yeah i know some of you guys here around will laugh me out for this newbie stupid question

 

But anyway here i go :

 

i have stat system on the server, it counts deaths, kills, xp, etc.....

 

now my question is how do i obtain kill/death ratio from these stats ?

 

i know k/d ratio is kills divide by deaths to obtain kill death ratio, how to calculate it in sqf file

 

what is the code to put in here ?

//This converts the string to an array
	_get = call compile _get;

	//only select the inner array, throw away this outer array shell
	_get = _get select 0;
	_get = _get select 0;

	_string = _get select 0;
	_xp = parseNumber _string;
	_string = _get select 1;
	_kills = parseNumber _string;
	_string = _get select 2;
	_deaths = parseNumber _string;
	
	player_stats_add = [_xp,_kills,_deaths];
	owner _unit publicVariableClient "player_stats_add";
	player_stats_got = 1;
	owner _unit publicVariableClient "player_stats_got";

or am i wrong ? is it elsewhere ? or maybe can i make a new sqf file ?

Share this post


Link to post
Share on other sites

Available math commands can be found here: https://community.bistudio.com/wiki/Category:Command_Group:_Math

Calculating it is just the same as your school maths, so instead of using normal math symbols, you use computer symbols.

You can then display your result with:

hint format ["Ratio: %1 / %2", my_first_variable, my_second_variable];
  • Like 1

Share this post


Link to post
Share on other sites

I rewrote your code so it's about 2x easier to read, but still contained in 16 lines:

_get = call compile _get;

_clientID = owner _unit;

_get = (_get select 0) select 0;

player_stats_add =
[
	parseNumber (_get select 0), //xp
	parseNumber (_get select 1), //kills
	parseNumber (_get select 2) //deaths
];

_clientID publicVariableClient "player_stats_add";

player_stats_got = 1;
_clientID publicVariableClient "player_stats_got";

Anyway, I don't think this is the right place to add a kill/death calculation. It would be much better off making the receiving client do it, in which case you would add it to the Public Variable Event Handler

"player_stats_add" addPublicVariableEventHandler
{
	_variableName = /*_this select 1;*/ EDIT: _this select 0;
	_incomingData = _this select 1;
	
	//other code
	
	systemChat format ["Kills/Deaths ratio:\n%1",(_incomingData select 1)/(_incomingData select 2)];
};

Also, really?

  • Like 1

Share this post


Link to post
Share on other sites

Available math commands can be found here: https://community.bistudio.com/wiki/Category:Command_Group:_Math

Calculating it is just the same as your school maths, so instead of using normal math symbols, you use computer symbols.

You can then display your result with:

 

hint format ["Ratio: %1 / %2", my_first_variable, my_second_variable];

ok thanks for the link and explanations !I get it, i know how to display the result i have playerloop.sqf + rsctitles in description.ext to do that with variable _kdstats i'm gonna try to save it also to my databse.

Share this post


Link to post
Share on other sites

I rewrote your code so it's about 2x easier to read, but still contained in 16 lines:

_get = call compile _get;

_clientID = owner _unit;

_get = (_get select 0) select 0;

player_stats_add =
[
	parseNumber (_get select 0), //xp
	parseNumber (_get select 1), //kills
	parseNumber (_get select 2) //deaths
];

_clientID publicVariableClient "player_stats_add";

player_stats_got = 1;
_clientID publicVariableClient "player_stats_got";

Anyway, I don't think this is the right place to add a kill/death calculation. It would be much better off making the receiving client do it, in which case you would add it to the Public Variable Event Handler

"player_stats_add" addPublicVariableEventHandler
{
	_variableName = _this select 1;
	_incomingData = _this select 1;
	
	//other code
	
	systemChat format ["Kills/Deaths ratio:\n%1",(_incomingData select 1)/(_incomingData select 2)];
};

Also, really?

thanks for the reply and taking the time to look at it, but even if your code is better writed , idk i just needed to know how calculate it, to display it i already know how to hopefully.

Share this post


Link to post
Share on other sites

I whipped up something for you to get you started: ;)

Tut.sqf

Num1 = 1;
Num2 = 45;
Num3 = 23;

_sum = Num1 + Num2 + Num3;
player sideChat format ["Working out the sum in Arma is easy! %1 + %2 + %3 = %4", Num1, Num2, Num3, _sum];

sleep 3;
Num1 = 4;
Num2 = 3;

_multiply = Num1 * Num2;
player sideChat format ["For multiplying, it's: %1 x %2 = %3", Num1, Num2, _multiply];

sleep 3;
Num1 = 10;
Num2 = 2;

_divide = Num1 / Num2;
player sideChat format ["For division, we can simply divide %1 by %2, to get %3", Num1, Num2, _divide];

sleep 3;
Num1 = 5;
Num2 = 2;

_subtract = Num2 - Num1;
player sideChat "Since addition is the same as Subtraction, but taking away numbers. Arma can also do negative numbers";

sleep 2;
player sideChat format ["%1 - %2 = %3", Num2, Num1, _subtract];

sleep 3;
player sideChat "This concludes basic maths for Arma...Now get out there! And use others like sin, cos and tan! :) ";
Run in your init or player:

null = execVM "tut.sqf";

Enjoy and Good Luck, ;)

Rawner135

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  

×