PDA

View Full Version : How can I bypass the 32 bit integer limit? (2,147,483,647)

12/12/2016, 12:47 AM
-- DELETED --

Hansrutger
12/12/2016, 03:11 AM
Well one way is to always make it a string, but of course that has its own bad... "annoyments"... :P To display it you'd probably want to use a textdraw then. But to answer your actual question if you can make it a 64 bit, I doubt it, not an expert on that field however. Please no suing sir.

Swedky
12/12/2016, 03:38 AM
You may div a player money. For example: 1,525,000,000 / 1,000,000 = 1,525 millions, but it's not exactly, it just round the amount.

SickAttack
12/12/2016, 03:57 AM
The HUD only has 8 digits, so an extremely surreal unrealistic economy wasn't a really bright idea.

About getting the total amount of cash held by the users on the server. You can do that with a simple SQL statement that does all the work for you. You just have to display the number it gives you.

About players being able to have so unrealistic amounts of money, you can create an array. Look at them as pockets, wallets or whatever.

Wallet 1: 500 bucks
Wallet 2: 200 bucks
Total cash by adding all the wallets up: 700 bucks

You just gotta think out of the box sometimes. Good luck and have fun!

AbyssMorgan
12/12/2016, 05:48 AM

PrO.GameR
12/12/2016, 07:30 AM
A) use mysql to bypass it
B) simply let go of a thousand (if players can get to 2 billion \$ anything under \$1000 is pennies) and then sum it up (doubt you'd have thousand players with that much money)
You can't make a player have more than that much money unless you use multiple vars for your money and make a sum of them as total money.

12/12/2016, 09:04 AM
The HUD only has 8 digits, so an extremely surreal unrealistic economy wasn't a really bright idea.

About getting the total amount of cash held by the users on the server. You can do that with a simple SQL statement that does all the work for you. You just have to display the number it gives you.

About players being able to have so unrealistic amounts of money, you can create an array. Look at them as pockets, wallets or whatever.

Wallet 1: 500 bucks
Wallet 2: 200 bucks
Total cash by adding all the wallets up: 700 bucks

You just gotta think out of the box sometimes. Good luck and have fun!

But let's say I'd calculate the total sum of the array, I would use a loop. And the variable that returns the total amount is still a 32 bit integer. So I could I do that?

I mean, I already kinda know how to add the money, but I don't know how to calculate it.

new money[MAX_PLAYERS][20];

{
for(new i; i < 20; i++)
{
if(money[playerid][i] < 2147483647)
{
if(money[playerid][i] + money <= 2147483647)
{
money[playerid][i] += money;
break;
}
}
}
}

AmigaBlizzard
12/12/2016, 09:36 AM
You can have 2 integer variables that you could join together, sort of anyways.
Name one variable HIGH and the other LOW (for example here).
When LOW exceeds 1 billion (1.000.000.000), substract 1 billion from it and add 1 to HIGH.

When LOW gets negative, add 1 billion to it and substract 1 from HIGH.

When displaying the money, you can simply print both values behind eachother

printf("%i%9i", HIGH, LOW);

The %9i is used to always make it 9 chars long and it adds leading zero's until it's 9 chars long.

But you are still limited to calculations up to 2 billion.

What's the smallest amount of money being processed?
What's the cheapest item on your server?

Your players may think they earn alot of money when they receive 100 million for a simple job, but when they buy a drink that costs 10 million as well, it still isn't alot of money.
It's still like the drink costs \$10 and you earn \$100, the ratio remains the same.

SAMP is 32-bit and you could use some workarounds but you're just making it harder than it needs to be.
You'll always be limited by 32-bit values.

Or you could use a string and manually perform calculations on that, then you can have calculations as high as you need it to be.
You could even display 128 character long values if you like and also perform calculations that long.
That would make your economy really big, I just can't grasp why you would need such high values.

Even the richest man on Earth doesn't have money that high.
Even if you add up all the money in the world, it isn't that high.

BiosMarcel
12/12/2016, 01:49 PM

SickAttack
12/12/2016, 03:45 PM
But let's say I'd calculate the total sum of the array, I would use a loop. And the variable that returns the total amount is still a 32 bit integer. So I could I do that?

I mean, I already kinda know how to add the money, but I don't know how to calculate it.

new money[MAX_PLAYERS][20];

{
for(new i; i < 20; i++)
{
if(money[playerid][i] < 2147483647)
{
if(money[playerid][i] + money <= 2147483647)
{
money[playerid][i] += money;
break;
}
}
}
}

Just return a string of adding up all of the values.