SA-MP Forums Archive
Just practice - 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: Just practice (/showthread.php?tid=595067)



Just practice - Razturach - 27.11.2015

Hey I was wondering how to display something in percents so this is what I did:

pawn Код:
new Celota = 270;
new Enota = 270;
pawn Код:
SetTimerEx("EnotaDol", 1000, true, "i", playerid);
pawn Код:
public EnotaDol()
{
    Enota --;
    return 1;
}
pawn Код:
stock Procenti(playerid)
{
    new string[128];
    new Procent;
    Procent = floatround((Enota / Celota)*100, floatround_round);
   
    format(string, sizeof(string),"There is currently %d Enot, which is exactly %.0f% percent!",Enota,float(Procent));
    SendClientMessage(playerid,-1,string);
}
pawn Код:
CMD:procenti(playerid, params[])
{
    Procenti(playerid);
    return 1;
}
Everything is working fine but.. it doesn't actually calculate how much percent is "Enota" of 270...(Celota) so it says "which is exactly 0 percent" .. can you help me out from this cuz I somehow feel I'm so close with that code..


Re: Just practice - TwinkiDaBoss - 28.11.2015

Floataround returns as int and you are trying to display it as float.

pawn Код:
new Float:CurrentPercent = (Enota/Celota)*100
printf("%f%%",CurrentPercent);
example
pawn Код:
(220/250)*100 = 88.00%
Which means, Enota is 12% less than Celota


Re: Just practice - Razturach - 28.11.2015

Not working properly first time it shows 100% but other numbers are displayed still as 0..
So what I'm trying to do is to reduce 270 for 1 every 1 second and display this in percentage everytime..
Added your code but not working properly

pawn Код:
stock Procenti(playerid)
{
    new string[128];
    new Float:CurrentPercent = (Enota/Celota)*100;
    printf("%f%%",CurrentPercent);

    format(string, sizeof(string),"There is currently %d Enot, which is exactly %.0f% percent!",Enota,CurrentPercent);
    SendClientMessage(playerid,-1,string);
}
Bit more help ? ^^


Re: Just practice - TwinkiDaBoss - 28.11.2015

Quote:
Originally Posted by Razturach
Посмотреть сообщение
Not working properly first time it shows 100% but other numbers are displayed still as 0..
So what I'm trying to do is to reduce 270 for 1 every 1 second and display this in percentage everytime..
Added your code but not working properly

pawn Код:
stock Procenti(playerid)
{
    new string[128];
    new Float:CurrentPercent = (Enota/Celota)*100;
    printf("%f%%",CurrentPercent);

    format(string, sizeof(string),"There is currently %d Enot, which is exactly %.0f% percent!",Enota,CurrentPercent);
    SendClientMessage(playerid,-1,string);
}
Bit more help ? ^^
Try changing
pawn Код:
(Enota/Celota)*100;
to
pawn Код:
((Enota/Celota) *100);

Look at this thread
http://forum.sa-mp.com/archive/index.php/t-114524.html


Re: Just practice - Ahmad45123 - 28.11.2015

Make sure EVERYTHING has the tag Float so the correct operator is used... or just use floatdiv or floatmul.

So, First of all, Set the Enota and Celota correctly by doing:
PHP код:
new Float:Celota 270.0;
new 
Float:Enota 270.0
And then at the stock:
PHP код:
stock Procenti(playerid)
{
    new 
string[128];
    new 
Procent floatround(((Enota Celota) * 100.0), floatround_round);
    
    
format(stringsizeof(string),"There is currently %f Enot, which is exactly %.0f% percent!",Enota,float(Procent));
    
SendClientMessage(playerid,-1,string);

Try it and tell us if it works.


Re: Just practice - AbyssMorgan - 28.11.2015

new Float:CurrentPercent = (Enota*100.0/Celota);


Re: Just practice - Razturach - 01.12.2015

Without your help I wouldn't figure it out guys so the final code is:
pawn Код:
stock Procenti(playerid)
{
    new string[128];
    new Float:CurrentPercent = floatround ((100 * Enota) / Celota);
    printf("%f%%",CurrentPercent);

    format(string, sizeof(string),"There is currently %d Enot, which is exactly %.0f% percent!",Enota, CurrentPercent);
    SendClientMessage(playerid,-1,string);
}
And it's exactly what I wanted ^^
Ty