Help converting to Random
#1

Hello guys, I am using a rob bank script that looks like this:

pawn Код:
#include <a_samp>
#include <zcmd>

new timer1

new Robbank[MAX_PLAYERS];

CMD:robbank(playerid, params[])
{
    if (Robbank[playerid] == 0 )
    if(IsPlayerInRangeOfPoint(playerid, 2.0, 362.0921,173.6848,1008.3828))
    {
    SendClientMessage(playerid, COLOR_GREEN, "You start robbing bank!");
    Robbank[playerid] = 1;
    SetPlayerWantedLevel(playerid, GetPlayerWantedLevel(playerid)+3);
    timer1 = SetTimerEx("RobBank", 10000, false, "i", playerid);
    SetTimerEx("after1", 50000, false, "i", playerid);
    } else {
    SendClientMessage(playerid, COLOR_RED, "[ERROR:]You are not inside the Bank checkpoint!");
    }
    return 1;
}
forward RobBank(playerid);
public RobBank(playerid)
{
    if(GetPlayerWeapon(playerid) == 0) GivePlayerMoney(playerid,20);
    if(GetPlayerWeapon(playerid) == 22) GivePlayerMoney(playerid,380);
    if(GetPlayerWeapon(playerid) == 23) GivePlayerMoney(playerid,640);
    if(GetPlayerWeapon(playerid) == 24) GivePlayerMoney(playerid,800);
    if(GetPlayerWeapon(playerid) == 25) GivePlayerMoney(playerid,1000);
    if(GetPlayerWeapon(playerid) == 26) GivePlayerMoney(playerid,1450);
    if(GetPlayerWeapon(playerid) == 27) GivePlayerMoney(playerid,2000);
    if(GetPlayerWeapon(playerid) == 28) GivePlayerMoney(playerid,2300);
    if(GetPlayerWeapon(playerid) == 29) GivePlayerMoney(playerid,2600);
    if(GetPlayerWeapon(playerid) == 30) GivePlayerMoney(playerid,4200);
    if(GetPlayerWeapon(playerid) == 31) GivePlayerMoney(playerid,5100);
    if(GetPlayerWeapon(playerid) == 32) GivePlayerMoney(playerid,3000);
    if(GetPlayerWeapon(playerid) == 33) GivePlayerMoney(playerid,6000);
    if(GetPlayerWeapon(playerid) == 34) GivePlayerMoney(playerid,6000);
    if(GetPlayerWeapon(playerid) == 35) GivePlayerMoney(playerid,8500);
    if(GetPlayerWeapon(playerid) == 36) GivePlayerMoney(playerid,10000);
    SendClientMessage(playerid, COLOR_GREEN, "You have robbed the bank and you recieved 3 stars.");
    TogglePlayerControllable(playerid,1);
    return 1;

forward after1(playerid);
public after1(playerid)
{
    Robbank[playerid] = 0;
    SendClientMessage(playerid, COLOR_RED, "You can now rob the bank again.");
    return 1;
  }

public OnPlayerDeath(playerid, killerid, reason)
{
    KillTimer(timer1);
    return 1;
}
Now to my question, I need help to make the money you recieve to a random amount instead of what it is right now. How can I do that?

Much thanks in advance.






EDIT:

Never mind, i kindof asked before trying myself , i switched the
pawn Код:
public RobBank(playerid)
{
    if(GetPlayerWeapon(playerid) == 0) GivePlayerMoney(playerid,20);
    if(GetPlayerWeapon(playerid) == 22) GivePlayerMoney(playerid,380);
    if(GetPlayerWeapon(playerid) == 23) GivePlayerMoney(playerid,640);
    if(GetPlayerWeapon(playerid) == 24) GivePlayerMoney(playerid,800);
    if(GetPlayerWeapon(playerid) == 25) GivePlayerMoney(playerid,1000);
    if(GetPlayerWeapon(playerid) == 26) GivePlayerMoney(playerid,1450);
    if(GetPlayerWeapon(playerid) == 27) GivePlayerMoney(playerid,2000);
    if(GetPlayerWeapon(playerid) == 28) GivePlayerMoney(playerid,2300);
    if(GetPlayerWeapon(playerid) == 29) GivePlayerMoney(playerid,2600);
    if(GetPlayerWeapon(playerid) == 30) GivePlayerMoney(playerid,4200);
    if(GetPlayerWeapon(playerid) == 31) GivePlayerMoney(playerid,5100);
    if(GetPlayerWeapon(playerid) == 32) GivePlayerMoney(playerid,3000);
    if(GetPlayerWeapon(playerid) == 33) GivePlayerMoney(playerid,6000);
    if(GetPlayerWeapon(playerid) == 34) GivePlayerMoney(playerid,6000);
    if(GetPlayerWeapon(playerid) == 35) GivePlayerMoney(playerid,8500);
    if(GetPlayerWeapon(playerid) == 36) GivePlayerMoney(playerid,10000);
    SendClientMessage(playerid, COLOR_GREEN, "You have robbed the bank and you recieved 3 stars.");
    TogglePlayerControllable(playerid,1);
    return 1;
with this

pawn Код:
forward RobBank(playerid);
public RobBank(playerid)
{
        new string[128];
        new cash = random(500000);
        GivePlayerMoney(playerid, cash);
        format(string, sizeof(string), "   * You have successfully robbed $%d from the bank *", cash);
        SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
}
You can lock this thread or remove it, sorry
Reply
#2

use the function called random

Here a wiki on it: https://sampwiki.blast.hk/wiki/Random
Reply
#3

If you like, you can use this method:
Код:
new rand = random(5)+1;
               switch(rand)
               {
                case 1: GivePlayerMoney(playerid,5000);
                case 2: GivePlayerMoney(playerid,1000);
                case 3: GivePlayerMoney(playerid,6000);
                case 4: GivePlayerMoney(playerid,7000);
                case 5: GivePlayerMoney(playerid,100);
                default: GivePlayerMoney(playerid,20000);
               }
Reply
#4

Carxi, always start a switch with case 0, not 1.

This can lead to problems.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)