SA-MP Forums Archive
How can I convert exp to percentage? - 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: How can I convert exp to percentage? (/showthread.php?tid=661076)



How can I convert exp to percentage? - zowzow - 21.11.2018

PHP код:
forward PlayerCheck();
public 
PlayerCheck()
{
    static
        
str[128];
        
    foreach (new 
Player)
    {
        new 
exp_max 50 + (Player[playerid][Level] - 2) * 50 50;
        
        
format(strsizeof(str), "%d"PlayerInfo[i][pLevel]);
        
PlayerTextDrawSetString(ipTextDraws[i][4], str);
        
format(strsizeof(str), "(%d%c)"PlayerInfo[i][pExp], '%');
        
PlayerTextDrawSetString(ipTextDraws[i][3], str);
        
PlayerTextDrawTextSize(ipTextDraws[i][1], PlayerInfo[i][pExp]*1.0915.749994);  // max progress = 109.559906
        
        
PlayerTextDrawShow(ipTextDraws[i][1]);
        if(
PlayerInfo[i][pExp] >= exp_max)
        {
            
PlayerTextDrawTextSize(ipTextDraws[i][1], 0.015.749994);
            
PlayerTextDrawShow(ipTextDraws[i][1]);
            
PlayerInfo[i][pLevel]++;
            
PlayerInfo[i][pExp] = 0;
        }
    }
    return 
1;

Here is the code
Level 1 = 50 exp and *2 after every next level


Re: How can I convert exp to percentage? - PT - 21.11.2018

you just need to do some maths..


example:

100 EXP (max exp variable) = 100%
20 EXP = X

just convert that to code and you easly do that


Re: How can I convert exp to percentage? - Joe Staff - 21.11.2018

Код:
float((PlayerInfo[i][pExp]/exp_max)*100);
And when formatting the string, replace '%d' with '%f.0'


Re: How can I convert exp to percentage? - zowzow - 21.11.2018

Thanks you guys for help

But I still don't understand how to build the code like you said
This is stupid for me

I used this from joe staff and Its worked fine if my exp was max even over 50-100 value
example : max exp is 250 then I set it to 300 or 350 after that they show me 100% and reset to 0%
The problem is when my exp around 10/50 20/50 and they are not showing the real value Its always 0%
But 50/50 is 100% work fine

My English's really bad too

PHP код:
        format(strsizeof(str), "(%f.0%c)"float((Player[i][Exp]/exp_max)*100), '%'); 
        
PlayerTextDrawSetString(iTDEditor_PTD[i][31], str); 



Re: How can I convert exp to percentage? - Cheryl666 - 21.11.2018

Well....It's very difficult for me)))