Random Cash - 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)
+--- Thread: Random Cash (
/showthread.php?tid=305558)
Random Cash -
Infamous - 22.12.2011
Hi there, have asked a few people for help on this but am still stuck.
Basically I want it so when you rob a player you rob a random amount of his cash, within the boundries of 1 - 100k.
Here is what I have tried:
pawn Код:
new pcash = GetPlayerMoney(forplayerid) + random(100000 - 1);
This just doesn't work, any help is appreciated as always.
Re: Random Cash -
Tigerkiller - 22.12.2011
pawn Код:
new pcash = random(100000);
if(pcash > GetPlayerMoney(target))
{
pcash = random(100000);
if(pcash > GetPlayerMoney(target))
{
// failed to rob
}
else
{
GivePlayerMoney(robber,pCash);
GivePlayerMoney(target,-pCash);
}
else
{
GivePlayerMoney(robber,pCash);
GivePlayerMoney(target,-pCash);
}
//Edit: problem fixed
Re: Random Cash -
Infamous - 22.12.2011
The thing is i don't want the robbery to fail, I want it to always return some of the players cash.
Or to put it another way I want the robber to get say 20-40% of the victims cash.
Re: Random Cash -
Tigerkiller - 22.12.2011
ye but if it for Rp server ist usefull
can you even rob a peopels money in reallife ? no you can fail too
Re: Random Cash -
Infamous - 22.12.2011
I am not making an RP server
Re: Random Cash -
[ABK]Antonio - 23.12.2011
GivePlayerMoney(forplayerid, random(100000))
Re: Random Cash -
Infamous - 23.12.2011
That isn't what I need either, anyone else got an idea?
AW: Re: Random Cash -
Nero_3D - 23.12.2011
Quote:
Originally Posted by Infamous
Or to put it another way I want the robber to get say 20-40% of the victims cash.
|
pawn Код:
new pcash = ((GetPlayerMoney(forplayerid) * (20 + random(21))) / 100);
Re: Random Cash -
Infamous - 24.12.2011
Thanks Nero, im guessing the 20 is the minimum, +21 is the max but why is it divided over 100?
Just want to understand the code a bit better before I put it to use.
Re: Random Cash -
Lorenc_ - 24.12.2011
Quote:
Originally Posted by Infamous
Thanks Nero, im guessing the 20 is the minimum, +21 is the max but why is it divided over 100?
Just want to understand the code a bit better before I put it to use.
|
pawn Код:
#define RandomEx(%0,%1) (random((%1) - (%0)) + (%0))
new pcash = RandomEx(1000, 100000); //1000 <-> 100000