Random
#1

pawn Код:
randmoney = random(50000 - 1000) + 1000;
Could anyone plz explain this to me
Reply
#2

random moneys from 1000 to 50000
Reply
#3

This is for a player to pick up

OnPlayerPickUpPickup.
Код:
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);
  }
Or if you want to give people cash

OnPlayerSpawn
Код:
GivePlayerMoney(playerid,random(100000-50000)+50000);
Reply
#4

pawn Код:
randmoney = random(50000 - 1000) + 1000;
// randmoney is a variable. It can store a value.
//random is a function that generate a random number between 0 and it params, for example:

//random(1000) will return a number between 0 and 999.

//+ 1000 always will add 1000 to the random value;
//For example, random return 515. 515 + 1000 = 515, so randmoney = 515.
Reply
#5

Quote:
Originally Posted by arakuta
Посмотреть сообщение
pawn Код:
randmoney = random(50000 - 1000) + 1000;
// randmoney is a variable. It can store a value.
//random is a function that generate a random number between 0 and it params, for example:

//random(1000) will return a number between 0 and 999.

//+ 1000 always will add 1000 to the random value;
//For example, random return 515. 515 + 1000 = 515, so randmoney = 515.
515 + 1000 = 1515 not 515
Reply
#6

The random money sets to 1000 sometimes, how can i change this to a price of between 40k and 100k?
Reply
#7

Код:
40000 + random(60000)
It's not rocket science.
Reply
#8

So from
pawn Код:
randmoney = random(50000 - 1000) + 1000;
to

pawn Код:
randmoney = random(40000 + 60000) + 1000;


What does the +1000 mean?
Reply
#9

No, the above will generate a number between 1000 and 100999. If you confuse and you can't understand what you should do, then use a function ****** wrote:
pawn Код:
stock RandomEx(min, max)
{
    return random(max - min) + min;
}
and usage:
pawn Код:
randmoney = RandomEx(40000, 100000);
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)