High interger crash server! -
dieuhanhphuc - 01.01.2015
I make this function:
PHP код:
stock GiveMoney(playerid, money)
{
new str[128];
if(money > 0)
{
format(str, sizeof(str), "~g~+%s$", AddCommas(money));
GameTextForPlayer(playerid, str, 3000, 1);
}
else if(money < 0)
{
format(str, sizeof(str), "~r~%s$", AddCommas(money));
GameTextForPlayer(playerid, str, 3000, 1);
}
PInfo[playerid][Cash] += money;
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, PInfo[playerid][money]);
return 0;
}
I try to use it in my cmd:
PHP код:
CMD:givemoney(playerid, params[])
{
new str[128], player, money;
if(sscanf(params, "ud", player, money)) return SendMessage(playerid, COLOR_LENH, "/givemoney [ID] [Money]", SMLENH);
GiveMoney(player, money);
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] [debug] AMX 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] [debug] AMX 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(playerid, money)
{
new str[128];
if(money > 0)
{
format(str, sizeof(str), "~g~+%s$", AddCommas(money));
GameTextForPlayer(playerid, str, 3000, 1);
}
else if(money < 0)
{
format(str, sizeof(str), "~r~%s$", AddCommas(money)); //HERE 17082
GameTextForPlayer(playerid, str, 3000, 1);
}
PInfo[playerid][Cash] += money;
ResetPlayerMoney(playerid);
GivePlayerMoney(playerid, PInfo[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(str, sizeof(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);