Number limit?
#1

I have this command, /set money which sets someones money to a value.
This is the command.
Код:
				if(strcmp(item, "money", true) == 0)
				{
					if(EsteManager(playerid))
					{
						format(szMessage, sizeof(szMessage), "You have set %s (ID: %d)'s money to %d.", szPlayerName, userID, amount);
						SendClientMessage(playerid, COLOR_WHITE, szMessage);
						playerVariables[userID][pMoney] = amount;
					}
				}
How ever, if I want to give that user 3.000.000.000, the amount goes negative. I know that there is a way how to fix this, but I have no idea how..
Reply
#2

In Pawn that SA:MP's using, a normal variable is INT32, which means the range is: –2,147,483,648 to 2,147,483,647

You can store your number in another variable. This value of money you're using isn't standard, make it lower!
Reply
#3

Quote:
Originally Posted by Aliassassin123456
Посмотреть сообщение
In Pawn that SA:MP's using, a normal variable is INT32, which means the range is: –2,147,483,648 to 2,147,483,647

You can store your number in another variable. This value of money you're using isn't standard, make it lower!
And how should I do that?
Reply
#4

Код:
if(strcmp(item, "money", true) == 0)
{
	if(EsteManager(playerid))
	{
		if (amount < 2000000000) // This will limit the money to 2 billion
		format(szMessage, sizeof(szMessage), "You have set %s (ID: %d)'s money to %d.", szPlayerName, userID, amount);
		SendClientMessage(playerid, COLOR_WHITE, szMessage);
		playerVariables[userID][pMoney] = amount;
	}
}
You can change the amount in this line if you still have problems:
Код:
if (amount < 2000000000)
Reply
#5

Quote:
Originally Posted by danielpalade
Посмотреть сообщение
And how should I do that?
Look, for example someone put another Infernus for sell for $1,000,000,000, that's wrong way! You can change the price to $1,000,000 instead $1,000,000,000, why this money value is much?
Reply
#6

There /was/ a plugin, but I can't seem to find it.
In the meanwhile check this: https://sampforum.blast.hk/showthread.php?tid=372994

And if things don't work out, you can still treat them as a string (not a good way to do it but possible).
Reply
#7

Quote:
Originally Posted by Darkwood17
Посмотреть сообщение
Код:
if(strcmp(item, "money", true) == 0)
{
	if(EsteManager(playerid))
	{
		if (amount < 2000000000) // This will limit the money to 2 billion
		format(szMessage, sizeof(szMessage), "You have set %s (ID: %d)'s money to %d.", szPlayerName, userID, amount);
		SendClientMessage(playerid, COLOR_WHITE, szMessage);
		playerVariables[userID][pMoney] = amount;
	}
}
You can change the amount in this line if you still have problems:
Код:
if (amount < 2000000000)
The thing is, I don't want to limit it. I want to be able to set his money to whatever amount I want.
Reply
#8

With all due respect, but that's f*cking stupid. The most expensive car to date was sold for a little more than $38 million. The most expensive house for a little less than $150 million. Adjust your server's economy instead of trying to implement something that will undoubtedly give you a massive headache. For your information: only 0,000000235% of the world's population are billionaires.
Reply
#9

Bumping!
Reply
#10

Quote:
Originally Posted by danielpalade
Посмотреть сообщение
The thing is, I don't want to limit it. I want to be able to set his money to whatever amount I want.
Why you need to have 3 billions in SA-MP?
The maximum money you can have in SA-MP is 2.1 billions (2,147,483,647). As the others said you won't need huge value like that. Read what Vince said.
Reply
#11

Quote:
Originally Posted by Vince
Посмотреть сообщение
With all due respect, but that's f*cking stupid. The most expensive car to date was sold for a little more than $38 million. The most expensive house for a little less than $150 million. Adjust your server's economy instead of trying to implement something that will undoubtedly give you a massive headache. For your information: only 0,000000235% of the world's population are billionaires.
The problem is not purchasing. Let's say that someone somehow makes 3 billion in game money. I would be fucked wouldn't I?
Reply
#12

Method 1:
https://sampforum.blast.hk/showthread.php?tid=372994
It has more limits, but I think it is easier to use method 2.

Method 2:
https://sampforum.blast.hk/showthread.php?tid=598933
Reply
#13

You could use 2 integer variables to work as a 64-bit long integer.
One variable is used to hold 9 digits maximum, so up to 999,999,999.
When this value reaches 1 billion, you substract 1 billion from it and add 1 to the second variable.
This second variable is actually the "billions counter".

When the first variable gets negative, add 1 billion to it and substract 1 from the second variable.

To display the complete value, you can put them behind eachother in a string.
PHP Code:
printf("Total value: %i%09i"variable2variable1); 
Something like this.
The %09i is there to make the second value always 9 digits long.

But remember, PAWN is still a 32-bit language as well as SAMP and GTA SA.
You won't be able to display that value using the normal GivePlayerMoney function and have it display normally on the client.
You'll need to use a textdraw and display the total value as a string onto that textdraw.

But still, you should restrict your economy to avoid such huge numbers, especially for money in a game.

When a player reaches 2 billion, it's easier to show them a message that they should transfer some of their money into a bank-account or vault or whatever you can program into your server to store excess money.
And limit their money to 2 billion.
If they earn excess money without transferring some of their money elsewhere, it's simply gone.

That's how most games do it to protect the player to roll-over into negative values (going over 2.1 billion will get them into -2.1 billion).
Even big-budget games deal with excess money this way.
Either to protect the player from going into negative, or to protect the game from bugs/exploits.

I know about a bug in Aion (an MMORPG) when it still was 32-bit.
Players could buy stuff and the buy-window would count the payment upwards until the values displayed in that window rolled over into negative.
Then after clicking "Buy", the player didn't pay anything, but they became instant billionaires.
Substracting "-2 billion" from their money actually gave them the money, as well as their merchandise they wanted to buy.
You don't want to deal with such bugs on your server.
They converted the entire game-engine and server-package into 64-bit to deal with this exploit.

If they think it's stupid (they won't unless they're 6-year old kids), they don't understand 32-bit computer values simply can't hold much larger values.
If anyone (even scientists) ever managed to store higher values than 2.1 billion in a 32-bit signed integer, 64-bit computers didn't have to be invented.

It's simply a technological limit.
You can either accept it and adjust your money values to fit within the range of -2.1 billion to 2.1 billion, or use some weird-looking, headache-bringing functions to get around it using strings instead of integer variables.

As said before, most people on Earth never reach that amount of money except for the 0,000000235% mentioned above.
Reply
#14

Quote:
Originally Posted by danielpalade
View Post
Let's say that someone somehow makes 3 billion in game money
How, exactly? And why would anyone stockpile that amount?

You can create fictitious money out of thin air but the real world doesn't work that way. Are you familiar with the concept of inflation? The more money that's being printed, the lesser the value of each individual bill. As a result, prices will go up.

Don't artificially inflate your server's economy. The amount of money coming in should be more or less equal to the amount of money going out.
Reply
#15

Quote:
Originally Posted by Vince
View Post
And why would anyone stockpile that amount?
Don't underestimate the need for e-peen. Fatal mistake.
Reply
#16

Quote:
Originally Posted by Vince
View Post
How, exactly? And why would anyone stockpile that amount?

You can create fictitious money out of thin air but the real world doesn't work that way. Are you familiar with the concept of inflation? The more money that's being printed, the lesser the value of each individual bill. As a result, prices will go up.

Don't artificially inflate your server's economy. The amount of money coming in should be more or less equal to the amount of money going out.
Well that's the thing. Your thinking about the reality. Its a game, alright? I don't really care what the reality is. I just want to be able to have more then 2.4 billion. Thanks.
Reply
#17

Quote:

Well that's the thing. Your thinking about the reality. Its a game, alright? I don't really care what the reality is. I just want to be able to have more then 2.4 billion. Thanks.

What if, that's not possible?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)