killsчdeaths Ratio problem
#1

I want to get the value Ratio=Kills/Deaths. I succesfully save and load kills and deaths with dini. But when a player has for example 5 deaths and 6 kills, Ratio becomes 1. If kills<deaths, then Ratio=0. How can I make ratio=5/6=0.83?
I also have R as Float like this:
pawn Код:
new Float:R;
Reply
#2

Quote:
Originally Posted by HurtLocker
Посмотреть сообщение
with dini
* Vince shivers.

Anyway, integer divided by integer remains integer. Use something like:

pawn Код:
new Float:ratio = float(kills)/float(deaths);
Reply
#3

Thanks a lot.
Reply
#4

In order to use the /stats command, I need to load the Ratio value from .ini file. I tried dini_Float(file, "Ratio"). I received, error: tag mismatch. Then, I tried dini_Int instead of dini_Float but the ratio value that was shown was 0.000. How can I load the Ratio value unharmed with this format?
pawn Код:
format(string,sizeof(string), "%s's STATS: [ Kills: %d || Deaths: %d || Ratio: %f || Money: %d || Score: %d || Admin level: %d ]", name, kills, deaths, R, money, score, alv);
SendClientMessage(playerid, 0x87CEEBFF, string);
Reply
#5

WHATISHERE = dini_Float(...);

and how do you declare ('new') it?
Reply
#6

No, don't do that. The ratio is changing everytime you get a kill/death and loading from a file would be failure, as it should save the kills/deaths again and again. Just make a variable that is assigned with the value of kills/deaths and then just print that!
Reply
#7

Quote:
Originally Posted by MP2
Посмотреть сообщение
WHATISHERE = dini_Float(...);

and how do you declare ('new') it?
Thanks a lot. I didnt type "Float:R"...

Quote:
Originally Posted by Dwane
Посмотреть сообщение
No, don't do that. The ratio is changing everytime you get a kill/death and loading from a file would be failure, as it should save the kills/deaths again and again. Just make a variable that is assigned with the value of kills/deaths and then just print that!
I don't understand why it would "fail" but nice idea.
Reply
#8

Quote:
Originally Posted by HurtLocker
Посмотреть сообщение
In order to use the /stats command, I need to load the Ratio value from .ini file.
Let's say you're in a minigame and you get 50 kills and 10 deaths in 4 minutes. Doing what you said above will show the old ratio, so you need to save every new kill/death.

However, there's just an easier way to do that and that's to store the result of (kills/deaths) to a new variable and display it everytime someone uses the /stats command. It doesn't need to save and load the ratio at all, it's just pointless!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)