PDA

View Full Version : Random money


GTLS
17/05/2015, 09:22 AM
You could also do something like:

new cash = random(40-100);
GivePlayerMoney(playerid, cash);

what does this do?
and yes how do i make it that random money comes between 8000 and 40000 when a player enters a check point?

i also want while doing a job delivery pickup you get random amount of materials loaded between 0(yes 0 also) and 15?

(I am making a trucking delivery job so when a player enters first CP he gets rand mats and then 2nd cp upto 4 and at last when he enters last cp he gets rand money as i stated above and rand mats to player file between 500 and 3000 ||| after that total mats also added to mats bank(the total mats that collects[rand mats] in job x 1000 mats get added) so that when players come in mats bank to buy mats the have some limits.. if some mats get left (ie unpurchased by players) then it wil also be saved.)

Thanks if you can solve me! i will REP+ you with real respect.

VishvaJeet
17/05/2015, 09:27 AM
Ye you can: Simple!

new cash = random(32001);
GivePlayerMoney(playerid, cash+8000);


This code will give player money between 8000-40000 cash.

Konstantinos
17/05/2015, 09:27 AM
The above (from your quote) would return some weird value as the input must be 0 to max-1.


RandomEx(min, max) // By ******
{
return random(max - min) + min;
}

EDIT: usage:
new cash = RandomEx(8000, 40001);

cash is a value between 8000 and 40000.

GTLS
17/05/2015, 09:28 AM
The above would return some weird value as the input must be 0 to max-1.


RandomEx(min, max) // By ******
{
return random(max - min) + min;
}


sorry but i dont understand what should i do with them?

semara456
17/05/2015, 09:30 AM
like this ??

new CP[MAX_PLAYERS];
CMD:work(playerid, params[])
{
CP[playerid] = 1;
SetPlayerCheckpoint(playerid, X,Y,Z, 4.0);
return 1;
}

public OnPlayerEnterCheckpoint(playerid)
{
if (CP[playerid] ==1)
{
DisablePlayerCheckpoint(playerid); // disables his checkpoint since he/she reached it
new cash = random(8000-40000);
GivePlayerMoney(playerid, cash);
}
return 1;
}

edit : well im late
maybe like that hope this work xD

GTLS
17/05/2015, 09:35 AM
semara456 dont worry i get it what were you telling me thaks!

VishvaJeet
17/05/2015, 09:38 AM
Ye you can: Simple!

new cash = random(32000);
GivePlayerMoney(playerid, cash+8000);


This code will give player money between 8000-40000 cash.

GTLS use my code.

GTLS
17/05/2015, 09:40 AM
GTLS use my code.

LOL thanks i will use both codes i probably will merge 2 codes and will use it thanks!!

Konstantinos
17/05/2015, 09:46 AM
sorry but i dont understand what should i do with them?

I was editing my post the time you posted it but you probably didn't see that.

usage:
new cash = RandomEx(8000, 40001);

cash is a value between 8000 and 40000.

It's just that RandomEx is easier to be used: RandomEx(min_number, max_number + 1)

@VishvaJeet: Your code will generate a value between 8000-39999.

GTLS
17/05/2015, 10:02 AM
I was editing my post the time you posted it but you probably didn't see that.

usage:
new cash = RandomEx(8000, 40001);

cash is a value between 8000 and 40000.

It's just that RandomEx is easier to be used: RandomEx(min_number, max_number + 1)

@VishvaJeet: Your code will generate a value between 8000-39999.

Thanks to solve problem....

VishvaJeet
17/05/2015, 10:08 AM
Ye you can: Simple!

new cash = random(32001);
GivePlayerMoney(playerid, cash+8000);


This code will give player money between 8000-40000 cash.

Fixed

GTLS
17/05/2015, 11:09 AM
I was editing my post the time you posted it but you probably didn't see that.

usage:
new cash = RandomEx(8000, 40001);

cash is a value between 8000 and 40000.

It's just that RandomEx is easier to be used: RandomEx(min_number, max_number + 1)

@VishvaJeet: Your code will generate a value between 8000-39999.

The above (from your quote) would return some weird value as the input must be 0 to max-1.


RandomEx(min, max) // By ******
{
return random(max - min) + min;
}

EDIT: usage:
new cash = RandomEx(8000, 40001);

cash is a value between 8000 and 40000.

Dude but gave me this error:

C:\Spandan\Samp servers\Real life roleplay\gamemodes\hilol.pwn(2980) : error 017: undefined symbol "RandomEx"

what now?

Konstantinos
17/05/2015, 11:10 AM
You meant to add the function to the script:

RandomEx(min, max) // By ******
{
return random(max - min) + min;
}

GTLS
17/05/2015, 11:12 AM
You meant to add the function to the script:

RandomEx(min, max) // By ******
{
return random(max - min) + min;
}

Done thanks! it works now