[SOLVED] Random Money - 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)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [SOLVED] Random Money (
/showthread.php?tid=69955)
[SOLVED] Random Money -
Alec24 - 21.03.2009
I would like to give the player who picks up a certain pickup to get an amount of cash between $50000 and $100000. I think you have to use random but I have only used that when its a number from 0 to whatever.
Re: Random Money -
Pyrokid - 21.03.2009
This goes at the top of your script.
pawn Код:
#define MAX_CASH 100000
new randmoney;
Then put this in OnPlayerPickUpPickup.
pawn Код:
if(pickupid == your_pickup)
{
randmoney = random(MAX_CASH);
GivePlayerMoney(playerid,randmoney);
}
Re: Random Money -
Alec24 - 21.03.2009
Are you sure that will get a sum of money
between 50000 and 100000 because I didnt see any 50000 in the code. Correct me if im wrong.
Re: Random Money -
Nero_3D - 21.03.2009
pawn Код:
if(pickupid == your_pickup)
{
GivePlayerMoney(playerid, (50_000 + random(50_001)));
}
Re: Random Money -
Amit_B - 21.03.2009
Try this:
pawn Код:
GivePlayerMoney(playerid,random(100000-50000)+50000);
Re: Random Money -
Nero_3D - 21.03.2009
Quote:
Originally Posted by Amit B
Try this:
pawn Код:
GivePlayerMoney(playerid,random(100000-50000)+50000);
|
if you can sub 50000 from 100000 than you see its 50000 and that would be the same as in my post, I just put +1 because he wanted 100000 included
Re: Random Money -
Amit_B - 22.03.2009
Quote:
Originally Posted by ♣ ⓐⓢⓢ
Quote:
Originally Posted by Amit B
Try this:
pawn Код:
GivePlayerMoney(playerid,random(100000-50000)+50000);
|
if you can sub 50000 from 100000 than you see its 50000 and that would be the same as in my post, I just put +1 because he wanted 100000 included
|
Quote:
Originally Posted by ♣ ⓐⓢⓢ
pawn Код:
if(pickupid == your_pickup) { GivePlayerMoney(playerid, ([b]50_000[/b] + random([b]50_001[/b]))); }
|
50
_000?
Re: Random Money -
Kinetic - 22.03.2009
Quote:
Originally Posted by Pyrokid
This goes at the top of your script.
pawn Код:
#define MAX_CASH 100000 new randmoney;
Then put this in OnPlayerPickUpPickup.
pawn Код:
if(pickupid == your_pickup) { randmoney = random(MAX_CASH); GivePlayerMoney(playerid,randmoney); }
|
Close, but no cigar. It should be like this.
There is no need for this
#define MAX_CASH 100000
new randmoney;
OnPlayerPickUpPickup.
pawn Код:
if(pickupid == your_pickup)
{
new str[44];
new randmoney = random(100001) - 50000;
format(str, sizeof(str), " >> Player picked up %s and recieved $%d", your_pickup, randmoney);
SendClientMessage(playerid, 0xffffffff, str);
GivePlayerMoney(playerid, randmoney);
}
Re: Random Money -
Nero_3D - 22.03.2009
Quote:
Originally Posted by Amit B
Quote:
Originally Posted by ♣ ⓐⓢⓢ
Quote:
Originally Posted by Amit B
Try this:
pawn Код:
GivePlayerMoney(playerid,random(100000-50000)+50000);
|
if you can sub 50000 from 100000 than you see its 50000 and that would be the same as in my post, I just put +1 because he wanted 100000 included
|
Quote:
Originally Posted by ♣ ⓐⓢⓢ
pawn Код:
if(pickupid == your_pickup) { GivePlayerMoney(playerid, ([b]50_000[/b] + random([b]50_001[/b]))); }
|
50 _000? 
|
I just use they to better read the numbers, or do you think 300000000000 is better readable as 300_000_000_000 ?
Quote:
Originally Posted by Kinetic
Quote:
Originally Posted by Pyrokid
This goes at the top of your script.
pawn Код:
#define MAX_CASH 100000 new randmoney;
Then put this in OnPlayerPickUpPickup.
pawn Код:
if(pickupid == your_pickup) { randmoney = random(MAX_CASH); GivePlayerMoney(playerid,randmoney); }
|
Close, but no cigar. It should be like this.
There is no need for this
#define MAX_CASH 100000
new randmoney;
OnPlayerPickUpPickup.
pawn Код:
if(pickupid == your_pickup) { new str[44]; new randmoney = random(100001) - 50000; format(str, sizeof(str), " >> Player picked up %s and recieved $%d", your_pickup, randmoney); SendClientMessage(playerid, 0xffffffff, str); GivePlayerMoney(playerid, randmoney); }
|
Did you even looked my or Amit B's post ?, because they have the right answer not yours
Reason:
random(100001) will be a number from 0 till 100000 (0 and 100000 included)
and then you do "- 50000" also lets say the random returns 300 => 300 - 50000 = -40700 :S
I hate this kinds of topics, the right solution got posted in one of the first posts (the 4th in this topic) and gets one page big
Re: Random Money -
Alec24 - 22.03.2009
Thanks I have it now