Random Cash
#1

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.
Reply
#2

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
Reply
#3

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.
Reply
#4

ye but if it for Rp server ist usefull
can you even rob a peopels money in reallife ? no you can fail too
Reply
#5

I am not making an RP server
Reply
#6

GivePlayerMoney(forplayerid, random(100000))
Reply
#7

That isn't what I need either, anyone else got an idea?
Reply
#8

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);
Reply
#9

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.
Reply
#10

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)