This Maths is wrong? or the Code?
#1

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)...
Reply
#2

What is the value of playerStats[playerid][pGunSkill]?
Reply
#3

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
Reply
#4

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

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:
  • Skip the division and do what Babul suggested. Probably what I'd suggest except you would not get anyone with 100% -- to get 100% then multiple by 2.04081633 (100/49) instead, since your maximum value is 49.
  • Change the '50' to '50.0' and '100' to '100.0' OR use floatdiv and floatmul. You may also need to use float(playerStats[playerid][pGunSkill]) to convert the gun skill to a float making it pure float multiplication/division (I can't remember how Pawn copes with mixed ints/floats)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)