SA-MP Forums Archive
random amount - 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: random amount (/showthread.php?tid=89059)



random amount - Takumi.WS - 30.07.2009

Код:
 
	  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 ^^


Re: random amount - James_Alex - 30.07.2009

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);



Re: random amount - yezizhu - 30.07.2009

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


Re: random amount - Takumi.WS - 30.07.2009

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...... ?


Re: random amount - illay - 30.07.2009

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




Re: random amount - yezizhu - 01.08.2009

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


Re: random amount - Takumi.WS - 01.08.2009

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, ?



Re: random amount - yezizhu - 01.08.2009

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));



Re: random amount - Daren_Jacobson - 01.08.2009

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);



Re: random amount - Takumi.WS - 01.08.2009

Thanks