SA-MP Forums Archive
Print %f remains 0 - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Print %f remains 0 (/showthread.php?tid=425478)



Print %f remains 0 - klotebandit - 25.03.2013

Hi,

I'm trying to make a simple ranking script. My ranks are working already but I also want to have a exp bar. i managed to create an expbar that changes size with the amount of kills left. however i want to display the percentage, somehow it remains 0 after the calculation

Код:
        killsleft[playerid] = tillnext[playerid] - GetPlayerScore(playerid);
	units[playerid] = (638/ tillnext[playerid]) * killsleft[playerid];
	displaypercentage[playerid] = (units[playerid]/638)*100;//this line goes wrong
	
	new string[24+3+1];
	format(string,sizeof(string),"Exp: %f%%", displaypercentage[playerid]);
Ok, so 638 is the maximum width, units[playerid] is the width of the bar(this changes when the player makes more kills)


Re: Print %f remains 0 - Dubya - 25.03.2013

Attempt this:

pawn Код:
// change
new displaypercentage[MAX_PLAYERS];
// to
new Float:displaypercentage[MAX_PLAYERS];
// Also, do this:

format(string,sizeof(string),"Exp: %f", displaypercentage[playerid]);



Re: Print %f remains 0 - klotebandit - 25.03.2013

I tried it but it doesn't have any effect except for that the percentage sign after the "Exp: 0.000000" is removed. Good suggestion though. It seems that somehow the deviding makes it 0


Re: Print %f remains 0 - Patrick - 25.03.2013

Im not sure about this

as you are using percentage i think you must use
Example
pawn Код:
format(string,sizeof(string),"Exp: %02f", displaypercentage[playerid]);
as you insert a Floating number


Re: Print %f remains 0 - klotebandit - 25.03.2013

Thats not it either, i tested it. it now shows "Exp: 00.00000" in the textdraw


Re: Print %f remains 0 - Vince - 25.03.2013

What are the tags of all those variables? An integer divided by another integer will remain an integer. There is no implied conversion.


Re: Print %f remains 0 - klotebandit - 25.03.2013

that could be the problem, is there a way to cast to a different datatype like in java?

EDIT: NVM it did the trick, thanks. i changed both the datatypes to float