SA-MP Forums Archive
High interger crash server! - 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: High interger crash server! (/showthread.php?tid=553971)



High interger crash server! - dieuhanhphuc - 01.01.2015

I make this function:
PHP код:
stock GiveMoney(playeridmoney)
{
    new 
str[128];
    if(
money 0)
    {
        
format(strsizeof(str), "~g~+%s$"AddCommas(money));
        
GameTextForPlayer(playeridstr30001);
    }
    else if(
money 0)
    {
        
format(strsizeof(str), "~r~%s$"AddCommas(money));
        
GameTextForPlayer(playeridstr30001);
    }
    
PInfo[playerid][Cash] += money;
    
ResetPlayerMoney(playerid);
    
GivePlayerMoney(playeridPInfo[playerid][money]);
    return 
0;

I try to use it in my cmd:

PHP код:
CMD:givemoney(playeridparams[])
{
    new 
str[128], playermoney;
    if(
sscanf(params"ud"playermoney)) return SendMessage(playeridCOLOR_LENH"/givemoney [ID] [Money]"SMLENH);
    
GiveMoney(playermoney);
    return 
1;

When i use this cmd with high negative value (ex: -100.000.000), it cause a crash -_- ! Someone help me pls, tks!

P/s: Sr for my bad English


Re: High interger crash server! - ball - 01.01.2015

Server logs? Use crashdetect if you don't have.


Re: High interger crash server! - dieuhanhphuc - 01.01.2015

Here:
PHP код:
[01:51:08] [debugAMX backtrace:
[
01:51:08] [debug#0 native format () from samp03svr
[01:51:08] [debug#1 000ea124 in public cmd_givemoney () from OCP.amx
[01:51:08] [debug#2 native CallLocalFunction () from samp03svr
[01:51:08] [debug#3 00000d74 in public OnPlayerCommandText (0x00000000, 0x022c2cf8) from OCP.amx 



Re: High interger crash server! - ball - 01.01.2015

Compile script with debug mode -d3. Then you will get error line.


Re: High interger crash server! - dieuhanhphuc - 01.01.2015

How can i complier with debug mode?!?


Re: High interger crash server! - dieuhanhphuc - 01.01.2015

Ok, i find it:
PHP код:
[02:12:27] [debugAMX backtrace:
[
02:12:27] [debug#0 native format () from samp03svr
[02:12:27] [debug#1 0011f4e0 in public cmd_givemoney () at OCP.pwn:17082
[02:12:27] [debug#2 native CallLocalFunction () from samp03svr
[02:12:27] [debug#3 00001064 in public OnPlayerCommandText (playerid=0, cmdtext[]=@0x022c2cec "/givemoney 0 -100000000") at E:\Game\Pawn Code\include\zcmd.inc:109 



Re: High interger crash server! - dieuhanhphuc - 01.01.2015

Line 17082 is:
PHP код:
stock GiveMoney(playeridmoney

    new 
str[128]; 
    if(
money 0
    { 
        
format(strsizeof(str), "~g~+%s$"AddCommas(money));
        
GameTextForPlayer(playeridstr30001); 
    } 
    else if(
money 0
    { 
        
format(strsizeof(str), "~r~%s$"AddCommas(money));  //HERE 17082
        
GameTextForPlayer(playeridstr30001); 
    } 
    
PInfo[playerid][Cash] += money
    
ResetPlayerMoney(playerid); 
    
GivePlayerMoney(playeridPInfo[playerid][money]); 
    return 
0
}
stock AddCommas(number)
{
    new
        
tStr[13]; // Up to 9,999,999,999,999
 
    
format(tStr,sizeof(tStr),"%d",number);
 
    if(
strlen(tStr) < 4)
     return 
tStr;
 
    new
        
//rNumber = floatround((number+(number/3)),floatround_floor),
        
iPos strlen(tStr),
        
iCount 1;
 
    while(
iPos 0)
    {
        if(
iCount == 4)
        {
            
iCount 0;
            
strins(tStr,",",iPos,1);
            
iPos ++;
        }
        
iCount ++;
        
iPos --;
    }
    return 
tStr;




Re: High interger crash server! - ball - 01.01.2015

Line 17082?

//EDIT

Give one line 17082, not full function.


Re: High interger crash server! - dieuhanhphuc - 01.01.2015

Line 17082! It doesn't seem have any problem, so i think you'll need full code
PHP код:
format(strsizeof(str), "~r~%s$"AddCommas(money));  //HERE 17082 



Re: High interger crash server! - ball - 01.01.2015

Try without function AddCommas

Код:
format(str, sizeof(str), "~r~%d$", money);