random amount
#1

Код:
 
	  if(!strcmp(cmdtext, "/transfercash", true))
    {
    if(PlayerToPoint(5, playerid, 364.5175,173.8485,1008.3893))
    {
    SendClientMessageToAll(ADMIN_RED, "[ ! ] BIP ! BIP ! BIP ! BIP ! Casino alarm launched ");
    SendClientMessage(playerid, COLOR_YELLOW, "[ ! ] Shit ! alarm is launched, hurry up man ");
    SendClientMessage(playerid, COLOR_YELLOW, "[ ! ] .... Money transfer in progress .... ");
    SendClientMessage(playerid, COLOR_YELLOW, "[ ! ] .... Money transfer in progress .... ");
    SendClientMessage(playerid, COLOR_YELLOW, "[ ! ] .... Money transfer in progress .... ");
    SendClientMessage(playerid, COLOR_YELLOW, "[ ! ] .... Money transfer in progress .... ");
    SendClientMessage(playerid, COLOR_YELLOW, "[ ! ] Congratulations ! You got your money ");
    SendClientMessage(playerid, COLOR_YELLOW, "[ ! ] PCash info : +5000 PCash ");
    GivePlayerPCash(playerid, 5000);
    SendClientMessage(playerid, COLOR_YELLOW, "[ ! ] Now get the hell out of here, the job is done");
    SendClientMessage(playerid, COLOR_YELLOW, "[ ! ] Perhaps cops will chase you, try to loose them");
    
    
		}
		else
		{
		SendClientMessage(playerid, COLOR_RED, "[ ! ] You are not at the casino safe ");
		}
		return 1;
		}
Now when you type /transfercash, it gives you 5000 PCash, i want to make a random amount of PCash, max : 10000 Pcash & min ; 1000 Pcash

Thanks for reading & helping ^^
Reply
#2

try this
pawn Код:
forward Random(min, max);
public Random(min, max)
{
  new a = random(max - min) + min;
  return a;
}
// then use this
GivePlayerMoney(playerid, Random(1000, 1000);
Reply
#3

pawn Код:
#define randomEx(%1,%2) \
  ((%1)+random((%2)-(%1)+1))
More efficient
Reply
#4

Quote:
Originally Posted by yezizhu
pawn Код:
#define randomEx(%1,%2) \
  ((%1)+random((%2)-(%1)+1))
More efficient
But where to put the max, & the min

& the command

GivePlayerPCash(playerid...... ?
Reply
#5

pawn Код:
#define GiveMoney(%1,%2,%3)GivePlayerMoney(%1,((%2)+random((%3)-(%2)+1)))

Reply
#6

My god, forgot this function.
Код:
clamp(minval,maxval);
eg:
pawn Код:
clamp(2,10);
You can find introduction in pawn-lang.pdf
Reply
#7

Quote:
Originally Posted by yezizhu
My god, forgot this function.
Код:
clamp(minval,maxval);
eg:
pawn Код:
clamp(2,10);
You can find introduction in pawn-lang.pdf
Ok

& GivePlayerPCash(playerid, ?
Reply
#8

Quote:
Originally Posted by Takumi<West-Side>
Quote:
Originally Posted by yezizhu
My god, forgot this function.
Код:
clamp(minval,maxval);
eg:
pawn Код:
clamp(2,10);
You can find introduction in pawn-lang.pdf
Ok

& GivePlayerPCash(playerid, ?
GivePlayerPCash(playerid,clamp(1000,10000));
Reply
#9

clamp just forces the number into the min and max and the syntax is clamp(value, min, max)

so if i did

clamp(100, 20, 200) it would return 100

if i did

clamp(20, 100, 200) it would return 100

and

clamp(53983, 537, 3483) would return 3483

the answer you need has been supplied using RandomEx

pawn Код:
#define randomEx(%1,%2) \
  ((%1)+random((%2)-(%1)+1))
so you would do
pawn Код:
GivePlayerPCash(playerid, randomEx(1000, 10000);
Reply
#10

Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)