SA-MP Forums Archive
Server side Money Crash - 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: Server side Money Crash (/showthread.php?tid=643999)



Server side Money Crash - vassilis - 01.11.2017

Hello guys, i have a major problem on my server. I am using server side money for my server. I have a stock named TDConvertPrice which converts the price inserting a comma to make it look neater.
For example if i have a x=1000 i do TDConvertPrice(x) and will print on my textdraw $1,000

I would like to point out that if i sum 100k 10 times it works correctly .
I do not know if it is strins or valstr bug or something else
Me and a friend have tried almost everything. Any possible idea?
However whenever i use values >= 1mil it crashes server.
Here is the code:
Код:
stock TDConvertPrice(price)
{
    new pricestring[12];
    new j = valstr(pricestring,price);
    while(j >= 4) { j -= 3; strins(pricestring,"~y~,~w~",j); }
    strins(pricestring,"~g~$~w~",0);
    return pricestring;
}
My setplayermoney function
Код:
SetPlayerMoney(playerid, value)
{
	new query[67], str[67];
	pinfo[playerid][Money] = value;
	format(str, sizeof(str), "Cash:_%s", TDConvertPrice(pinfo[playerid][Money]));
	PlayerTextDrawSetString(playerid, PlayerGUIPTD[4][playerid], str);
	UpdatePlayerTextDraw(playerid, PlayerGUIPTD[4][playerid]);
	mysql_format(mysql, query, sizeof(query), "UPDATE `players` SET `Money` = %d WHERE `ID`=%d", pinfo[playerid][Money], pinfo[playerid][ID]);
	mysql_pquery(mysql, query, "","");
	return 1;
}



Re: Server side Money Crash - Eoussama - 01.11.2017

Here you go:

PHP код:
stock TDConvertPrice(price)
{
    new 
pricestring[50], valstr(pricestringprice);
    while(
0)
    {
        if(
== && pricestring[j] != '\0')
            
strins(pricestring"~y~,~w~", (strlen(pricestring) - j));
        
j--;
    }
    
strins(pricestring"~g~$~w~"0);
    return 
pricestring;

I'd suggest using custom specifiers for this kind of formatting,
refer to this thread for more information: https://sampforum.blast.hk/showthread.php?tid=313488


Re: Server side Money Crash - vassilis - 03.11.2017

[QUOTE=Eoussama;3948841]Here you go:

PHP код:
stock TDConvertPrice(price)
{
    new 
pricestring[50], valstr(pricestringprice);
    while(
0)
    {
        if(
== && pricestring[j] != '\0')
            
strins(pricestring"~y~,~w~", (strlen(pricestring) - j));
        
j--;
    }
    
strins(pricestring"~g~$~w~"0);
    return 
pricestring;

Still crashes..