[SOLVED] Random Money
#1

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.
Reply
#2

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);
    }
Reply
#3

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.
Reply
#4

pawn Код:
if(pickupid == your_pickup)
    {
        GivePlayerMoney(playerid, (50_000 + random(50_001)));
    }
Reply
#5

Try this:
pawn Код:
GivePlayerMoney(playerid,random(100000-50000)+50000);
Reply
#6

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
Reply
#7

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?
Reply
#8

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);
  }
Reply
#9

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
Reply
#10

Thanks I have it now
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)