SA-MP Forums Archive
Weird thing when I want to add exp to player... - 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: Weird thing when I want to add exp to player... (/showthread.php?tid=134884)



Weird thing when I want to add exp to player... - leapfish - 17.03.2010

Hello, I made code about adding exp points to players every 30seconds...
So after they play 1seconds they will get 0.346 experience points, when I tried it, player got A WAY TOO MUCH EXP like 1318926827 I was surprised...

Here is the code...

Код:
public Experience()
{
  for(new i=0; i<MAX_PLAYERS; i++)
  {
     if(IsPlayerConnected(i))
     {
        Seconds[i]++;
        if(Seconds[i] >= 30)
        {
           Seconds[i]=0;
           PlayerInfo[i][Exppoints]+=0.346;
					 GameTextForPlayer(i, "Exp~n~~w~+0.346", 3000, 1);
        }
     }
  }
}
Please help me so I get 0.346 exp every 30 secs


Re: Weird thing when I want to add exp to player... - cessil - 17.03.2010

probably adding a non full number and you probably have it as a decimal and not a float which is what you need if you want to have x.xx


Re: Weird thing when I want to add exp to player... - leapfish - 17.03.2010

Can you help me fixing it please?


Re: Weird thing when I want to add exp to player... - Babul - 17.03.2010

try a
Код:
new Float:PlayerInfo[i][Exppoints];



Re: Weird thing when I want to add exp to player... - leapfish - 17.03.2010

Maybe it's because on /stats command I use
Код:
(Exp: %d, (PlayerInfo[playerid][Exppoints])
Maybe that causes it?


Re: Weird thing when I want to add exp to player... - Babul - 18.03.2010

yep. use %f (floating point), to solve the tons of zeros after the dot, use %.2f



Re: Weird thing when I want to add exp to player... - leapfish - 18.03.2010

So something like this?

Код:
(Exp: %f.%2f, (PlayerInfo[playerid][Exppoints])
Thanks for the reply...



Re: Weird thing when I want to add exp to player... - leapfish - 18.03.2010

Quote:
Originally Posted by HeGe
So something like this?

Код:
(Exp: %f.%2f, (PlayerInfo[playerid][Exppoints])
Thanks for the reply...
OK I tried it in game, now it's little bit better, shows like Exp: 0.346999. 0.000000000 (How to remove that 999 at the end, and how to remove that 0.00000000 after it...)

EDIT: After 2nd experience add, it still shows some BIG NUMBERS LIKE 1031245123.00000 or something, PLEASE HELP ME


Re: Weird thing when I want to add exp to player... - Babul - 18.03.2010

may i see your snipped u r using? it will help me fixing your problem. u already defined that value as
Код:
new Float:PlayerInfo[i][Exppoints];
? if not, do it. if you display an integer and add a float value, it always grows at large amounts..
maybe that will fix your problem, if i give you some examples:
lets assume you got this value of 120.0 and adding your 0.346
%f == 120.346000
%.3f == 120.346
%.4f == 120.3460
%.8f == 120.34600000
%8.f == 00000120.346
%8.8f == 00000120.34600000
and, finally, maybe u need this:
%3.3f == 120.346
hope it helps a bit


Re: Weird thing when I want to add exp to player... - leapfish - 18.03.2010

Код:
new Float:PlayerInfo[i][Exppoints];
Where I need to add this??

When I try, it shows me this errors

Код:
warning 219: local variable "PlayerInfo" shadows a variable at a preceding level
error 008: must be a constant expression; assumed zero
error 036: empty statement
Please help me..