SA-MP Forums Archive
This Maths is wrong? or the Code? - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: This Maths is wrong? or the Code? (/showthread.php?tid=183483)



This Maths is wrong? or the Code? - DarrenReeder - 15.10.2010

pawn Код:
new Float:percent;
//new percent; // Tried with both Float and this one...
percent = (playerStats[playerid][pGunSkill]/50)*100;
Whats wrong with that? It just shows up as 0.00000 (or just 0 with the non Float Number)...


Re: This Maths is wrong? or the Code? - Calgon - 15.10.2010

What is the value of playerStats[playerid][pGunSkill]?


Re: This Maths is wrong? or the Code? - DarrenReeder - 15.10.2010

It has been from 0-49 and its always 0...

Very strange (i even show the actual Value of the pGunSkill in my script when you use the /skills command)

pawn Код:
CMD:skills(playerid, params[]){
    if(playerLogged[playerid] == 0) return SendClientMessage(playerid, COLOR_RED, "[ERROR] - Please log in first!");
    new string[60], level, Float:percent;
    SendClientMessage(playerid, COLOR_YELLOW, "---------------[Skills]---------------");
    //Gun Dealer
    if(playerStats[playerid][pGunSkill] < 50){ level = 1; percent = (playerStats[playerid][pGunSkill]/50)*100; }
    else if(playerStats[playerid][pGunSkill] > 50 && playerStats[playerid][pGunSkill] < 150){ level = 2; percent = (playerStats[playerid][pGunSkill]/150)*100; }

    format(string, sizeof(string), " * Gun Dealer Level: %d -- %f %s Completed (%d)", level, percent, "%%", playerStats[playerid][pGunSkill]);
    SendClientMessage(playerid, COLOR_WHITE, string);
    // Gun Dealer
   
    SendClientMessage(playerid, COLOR_YELLOW, "---------------[Skills]---------------");
    return 1;
}
EDIT:
i already realise there is a few problems with this code.. like when pGunSkill is on "50" it has no level..but dw about all the problems.. just need the percentage sorted


Re: This Maths is wrong? or the Code? - Babul - 15.10.2010

Код:
percent = (playerStats[playerid][pGunSkill])*2;
maybe?


Re: This Maths is wrong? or the Code? - Simon - 15.10.2010

Quote:
Originally Posted by DarrenReeder
Посмотреть сообщение
pawn Код:
new Float:percent;
//new percent; // Tried with both Float and this one...
percent = (playerStats[playerid][pGunSkill]/50)*100;
Whats wrong with that? It just shows up as 0.00000 (or just 0 with the non Float Number)...
Your maths is pretty much correct based on the information given, except that you should divide by 49 if you have a max of 49. However, that's not what's causing the problem: it looks like pGunSkill is an integer rather than a float, which is causing your division to spit out an integer:

integer / integer = integer

Integers have the numbers after their decimal point truncated (cut off), so 0.9, 0.333, 0.4 etc. would become 0. That also means any value of the calculation 'playerStats[playerid][pGunSkill]/50' would become 0 since pGunSkill is always lower than 50.

In order to fix it you can do two solutions: