Is there a way to optimize this code?
#8

Quote:
Originally Posted by Calisthenics
Посмотреть сообщение
AmigaBlizzard has got a point. Instead of saving money as string, you can have 2 integer arrays. One being for money and the other for coins. Showing the money would look like this (an example):
pawn Код:
format(string, sizeof string, "My money: %d.%02d$", gPlayer[playerid][Money], gPlayer[playerid][Coins]);
The need of splitting is now unnecessary.

%02d ads zero in front in case it is 1 digit. "9" becomes "09".
Actually, I also have those 2 integer arrays just like what you said. It seems that I should write another function like this:
Quote:

_givePlayerMoney(playerid, cash, coin) // I think this will be the best

not
Quote:

_givePlayerMoney(playerid, Float:cash)

Thank you!

Quote:
Originally Posted by ******
Посмотреть сообщение
floatround
floatfract

Don't use strings to process numbers.
Sorry but I don't understand much. I haven't found out the way to work with those two functions.
And this is how I use string to do my thing:
PHP код:
_givePlayerMoney(playeridFloat:amount)
{
    new 
_money[18],
        
_cash,
        
_coin;
    
format(_moneysizeof(_money), "%.2f"amount);
    
sscanf(_money"p<.>dd"_cash_coin);
    
ResetPlayerMoney(playerid);
    
character[playerid][cash] += _cash;
    
character[playerid][coin] += _coin;
    
SetPlayerMoney(playeridcharacter[playerid][cash]);
    
updatePlayerCoinTextDraw(playerid); // I create a textdraw to display player's coin
    
return 1;

Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)