Needed help on formating Cash -
Tigerkiller - 03.07.2012
Hello Community, did anyone knows if i enter a value like 9999999999 then it's only returns 1.410.065.407 but i want to get 9.999.999.999 anyone knows how to solve this ?
pawn Код:
stock GetCashResult(Betrag)
{
new idx[20], part;
format(idx, sizeof(idx), "%i", Betrag);
part = strlen(idx)-3;
while(part > 0)
{
strins(idx, ".", part);
part -= 3;
}
return idx;
}
Re: Needed help on formating Cash -
Vince - 03.07.2012
You can't. The maximum integer value for signed integers is 0x7FFFFFFF or 2,147,483,647.
AW: Needed help on formating Cash -
Tigerkiller - 03.07.2012
but how to solve this ? there must be a way to get it work
/edit: anyone ?
Re: Needed help on formating Cash -
[MM]RoXoR[FS] - 03.07.2012
Just a guess...
Get the amount of money you are getting (in your case 1.410. something)
Now give same amount of money(in -ve ) to player...
So,it will decrease his money.
Continue, this until you get money in -ve..
Now , add up all the money and you got the amount of money he had..
Remember to give him back all his money.
Re: Needed help on formating Cash -
Vince - 03.07.2012
Like I said, you simply can't give a player more money than 2 billion; it'll just wrap around one or more times (in this case 4 times). Try it on a calculator;
9,999,999,999 Mod 2,147,483,647 = 1,410,065,411
Re: Needed help on formating Cash -
Roko_foko - 03.07.2012
You can by using an array. It's a bit more difficult to work with it. Array[]="99999999999"; for showing cash you will have to use a textdraw.
Re: Needed help on formating Cash -
[MM]RoXoR[FS] - 04.07.2012
Quote:
Originally Posted by Roko_foko
You can by using an array. It's a bit more difficult to work with it. Array[]="99999999999"; for showing cash you will have to use a textdraw.
|
GetPlayerCash gives cash in int type.
Re: Needed help on formating Cash -
Shelby - 04.07.2012
Why you need more than 2,147,483,647 of cash?
Btw, you can separate the money in several variables, like:
new Money1, Money2;
When Money1 reach 2,147,483,647 start using Money2, make a function to use both(or more) variables like one.
Re: Needed help on formating Cash -
[KHK]Khalid - 04.07.2012
Like Vince said you cannot. But to get around this you can make your own money system, I'll give you some hints:
Make a per player global variable which will be used to get players' money or give them
pawn Код:
new playerMoney[MAX_PLAYERS];
Also make a textdraw that will be used to display cash for a player
(NOTE: This is just the variable, you will have to create the whole textdraw)
pawn Код:
new Text:moneyTD[MAX_PLAYERS];
Now you can make your own functions to give/get/set money
pawn Код:
// To give money
stock GiveMoney(playerid, amount)
{
playerMoney[playerid] = playerMoney[playerid] + amount;
TextDrawSetString(moneyTD[playerid], playerMoney[playerid]);
return 1;
}
// To get a player's money
stock GetMoney(playerid)
{
return playerMoney[playerid];
}
// Set cash ...
stock SetMoney(playerid, amount)
{
playerMoney[playerid] = amount;
TextDrawSetString(moneyTD[playerid], playerMoney[playerid]);
return 1;
}
// Reset cash
stock ResetMoney(playerid)
{
playerMoney[playerid] = 0;
TextDrawSetString(moneyTD[playerid], playerMoney[playerid]);
return 1;
}
Now you gotta replace (CTRL+H) GivePlayerMoney with GiveMoney, GetPlayerMoney with GetMoney and ResetPlayerMoney with ResetMoney. And when done you can simply use those functions to give, get, set or reset players' money.
Re: Needed help on formating Cash -
MP2 - 04.07.2012
What you don't understand is that variables in PAWN are 32-bits.
2,147,483,647 is the maximum value for a 32-bit signed integer (signed meaning they can take negative numbers also).
There's no way around this, unless you use a string - store the 'billions' in one variable and the rest in another, but you'll NEVER be able to convert it to an integer.
Sooooooo instead of
cash = 2147483647
you'll have to do
cash_billions = 2
cash = 147483647
or something.