random selection
#1

Hello, how can i make that so for example there is 10 procent chance to catch a spas
and 30 procent chance to catch a pool cue.. and 70 procent chance to catch a normal fish?
and so on..

pawn Код:
if(PRESSED(KEY_AIM))
    {
        if (FishCaught[playerid] == 1)
        {
            if(IsPlayerNearWater(playerid) || IsPlayerInWater(playerid))
            {
                //if(Fishing[playerid] == 1)
                {
                    new Caught;
                    new rand = Random(1, 16);

                    new fstring[MAX_PLAYER_NAME];
                    new Level = PlayerInfo[playerid][pFishSkill];
                    if(Level >= 0 && Level < 50) { Caught = random(20)-7; }
                    else if(Level >= 50 && Level < 100) { Caught = random(50)-20; }
                    else if(Level >= 100 && Level < 200) { Caught = random(100)-50; }
                    else if(Level >= 200 && Level < 400) { Caught = random(140)-60; }
                    else if(Level >= 400 && Level < 500) { Caught = random(170)-60; }
                    rand = random(FishNamesNumber);
                    if(rand == 1)
                    {
                        SendClientMessage(playerid, COLOR_GREY, "   You caught a headcrab and threw it away!");
                        HidePlayerFishText(playerid);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        RemovePlayerAttachedObject(playerid,0);
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    else if(rand == 2)
                    {
                        SendClientMessage(playerid, COLOR_GREY, "   You caught a g-string and threw it away!");
                        HidePlayerFishText(playerid);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        RemovePlayerAttachedObject(playerid,0);
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    else if(rand == 3)
                    {
                        SendClientMessage(playerid, COLOR_GREY, "   You caught a can and threw it away!");
                        HidePlayerFishText(playerid);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        RemovePlayerAttachedObject(playerid,0);
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    else if(rand == 4)
                    {
                        SendClientMessage(playerid, COLOR_GREY, "   You caught a used condom and threw it away!");
                        HidePlayerFishText(playerid);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        RemovePlayerAttachedObject(playerid,0);
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    else if(rand == 5)
                    {
                        SendClientMessage(playerid, COLOR_GREY, "   You caught some garbage and threw it away!");
                        HidePlayerFishText(playerid);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        RemovePlayerAttachedObject(playerid,0);
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    else if(rand == 6)
                    {
                        new string[85];
                        new weapon[MAX_PLAYERS];
                        AddWeapon(playerid,weapon[playerid] = 22);
                        SendClientMessage(playerid, COLOR_GREY, "   You caught a Colt 45!");
                        format(string, sizeof(string), "* %s reels in a Colt 45.", RemoveUnderScore(playerid));
                        ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                        RemovePlayerAttachedObject(playerid,0);
                        HidePlayerFishText(playerid);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    else if(rand == 7)
                    {
                        new string[85];
                        PlayerInfo[playerid][pIntoxication] += ( 4000 + floatround( floatpower(PlayerInfo[playerid][pIntoxication],0.9) ) );
                        if(PlayerInfo[playerid][pIntoxication] > 50000) PlayerInfo[playerid][pIntoxication] = 50000;
                        SetPlayerDrunkLevel(playerid,PlayerInfo[playerid][pIntoxication]);
                        SendClientMessage(playerid, COLOR_GREY, "   You caught a six-pack with 4 beers left!");
                        format(string, sizeof(string), "* %s reels in a six-pack with 4 beers left.", RemoveUnderScore(playerid));
                        ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                        RemovePlayerAttachedObject(playerid,0);
                        HidePlayerFishText(playerid);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    else if(rand == 8)
                    {
                        new string[85];
                        new randgrams = 2 + random(10);
                        PlayerInfo[playerid][pPot] += randgrams;
                        format(string, sizeof(string), "   You caught a small bag containing %d grams of pot!", randgrams);
                        SendClientMessage(playerid, COLOR_GREY, string);
                        format(string, sizeof(string), "* %s reels in a small bag containing %d grams of pot.", RemoveUnderScore(playerid), randgrams);
                        ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                        RemovePlayerAttachedObject(playerid,0);
                        HidePlayerFishText(playerid);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    else if(rand == 9)
                    {
                        new string[85];
                        new randgrams = 2 + random(10);
                        PlayerInfo[playerid][pCrack] += randgrams;
                        format(string, sizeof(string), "   You caught a small bag containing %d grams of crack!", randgrams);
                        SendClientMessage(playerid, COLOR_GREY, string);
                        format(string, sizeof(string), "* %s reels in a small bag containing %d grams of crack.", RemoveUnderScore(playerid), randgrams);
                        ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                        RemovePlayerAttachedObject(playerid,0);
                        HidePlayerFishText(playerid);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    else if(rand == 10)
                    {
                        new string[85];
                        new weapon[MAX_PLAYERS];
                        AddWeapon(playerid,weapon[playerid] = 30);
                        SendClientMessage(playerid, COLOR_GREY, "   You caught an AK 47!");
                        format(string, sizeof(string), "* %s reels in an AK 47.", RemoveUnderScore(playerid));
                        ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                        RemovePlayerAttachedObject(playerid,0);
                        HidePlayerFishText(playerid);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    else if(rand == 11)  //
                    {
                        new string[85];
                        new weapon[MAX_PLAYERS];
                        AddWeapon(playerid,weapon[playerid] = 23);
                        SendClientMessage(playerid, COLOR_GREY, "   You caught a Silenced Pistol!");
                        format(string, sizeof(string), "* %s reels in a SD Pistol.", RemoveUnderScore(playerid));
                        ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                        RemovePlayerAttachedObject(playerid,0);
                        HidePlayerFishText(playerid);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    else if(rand == 12)  //
                    {
                        new string[85];
                        new weapon[MAX_PLAYERS];
                        AddWeapon(playerid,weapon[playerid] = 27);
                        SendClientMessage(playerid, COLOR_GREY, "   Combat Shotgun!");
                        format(string, sizeof(string), "* %s reels in a Combat Shotgun.", RemoveUnderScore(playerid));
                        ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                        RemovePlayerAttachedObject(playerid,0);
                        HidePlayerFishText(playerid);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    else if(rand == 13)
                    {
                        new string[85];
                        new weapon[MAX_PLAYERS];
                        AddWeapon(playerid,weapon[playerid] = 5);
                        SendClientMessage(playerid, COLOR_GREY, "   You caught a Bat!");
                        format(string, sizeof(string), "* %s reels in a Bat.", RemoveUnderScore(playerid));
                        ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                        RemovePlayerAttachedObject(playerid,0);
                        HidePlayerFishText(playerid);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    else if(rand == 14)
                    {
                        new string[85];
                        new Float:x, Float:y, Float:z;
                        GetPlayerPos(playerid, x, y, z);
                        CreateExplosion(x, y, z, 11, 10.0); // 5
                        SendClientMessage(playerid, COLOR_GREY, "   You caught an undetonated sea mine!");
                        format(string, sizeof(string), "* %s reels in an undetonated sea mine!", RemoveUnderScore(playerid));
                        ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                        RemovePlayerAttachedObject(playerid,0);
                        HidePlayerFishText(playerid);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    else if(rand == 15)
                    {
                        new string[85];
                        new mrand = random(2000);
                        format(string, sizeof(string), "You caught a money bag, containing $%d.", mrand);
                        SendClientMessage(playerid, COLOR_GREY, string);
                        format(string, sizeof(string), "* %s reels in a money bag, containing $%d.", RemoveUnderScore(playerid), mrand);
                        ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                        GiveMoney(playerid, mrand);
                        RemovePlayerAttachedObject(playerid,0);
                        HidePlayerFishText(playerid);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    else if(rand == 16)
                    {
                        new string[85];
                        new weapon[MAX_PLAYERS];
                        AddWeapon(playerid,weapon[playerid] = 7);
                        SendClientMessage(playerid, COLOR_GREY, "   You caught a Pool cue!");
                        format(string, sizeof(string), "* %s reels in a Pool cue.", RemoveUnderScore(playerid));
                        ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                        RemovePlayerAttachedObject(playerid,0);
                        HidePlayerFishText(playerid);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    if(PlayerInfo[playerid][pFishLic] < 1)
                    {
                    }
                    if(Fishes[playerid][pWeight1] == 0)
                    {
                        new string[85];
                        PlayerInfo[playerid][pFishes] += 1;
                        PlayerInfo[playerid][pFishSkill] += 1;
                        format(fstring, sizeof(fstring), "%s", FishNames[rand]);
                        strmid(Fishes[playerid][pFish1], fstring, 0, strlen(fstring), 255);
                        Fishes[playerid][pWeight1] = Caught;
                        format(string, sizeof(string), "* You have caught a %s, which weights %d pounds.", Fishes[playerid][pFish1], Caught);
                        SendClientMessage(playerid, COLOR_GREY, string);
                        format(string, sizeof(string), "* %s reels in a %s, on %d lbs.", RemoveUnderScore(playerid), Fishes[playerid][pFish1], Caught);
                        ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                        RemovePlayerAttachedObject(playerid,0);
                        KillTimer(fishtimer[playerid]);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        HidePlayerFishText(playerid);
                        Fishes[playerid][pLastWeight] = Caught;
                        Fishes[playerid][pLastFish] = 1;
                        Fishes[playerid][pFid1] = rand;
                        Fishes[playerid][pFishID] = rand;
                        if(Caught > PlayerInfo[playerid][pBiggestFish])
                        {
                            format(string, sizeof(string), "* You've beaten your old record of %d pounds!  Your new biggest fish is: %d pounds.", PlayerInfo[playerid][pBiggestFish], Caught);
                            SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                            PlayerInfo[playerid][pBiggestFish] = Caught;
                        }
                    }
                    else if(Fishes[playerid][pWeight2] == 0)
                    {
                        new string[85];
                        PlayerInfo[playerid][pFishes] += 1;
                        PlayerInfo[playerid][pFishSkill] += 1;
                        format(fstring, sizeof(fstring), "%s", FishNames[rand]);
                        strmid(Fishes[playerid][pFish2], fstring, 0, strlen(fstring), 255);
                        Fishes[playerid][pWeight2] = Caught;
                        format(string, sizeof(string), "* You have caught a %s, which weights %d pounds.", Fishes[playerid][pFish2], Caught);
                        SendClientMessage(playerid, COLOR_GREY, string);
                        format(string, sizeof(string), "* %s reels in a %s, on %d lbs.", RemoveUnderScore(playerid), Fishes[playerid][pFish2], Caught);
                        ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                        RemovePlayerAttachedObject(playerid,0);
                        KillTimer(fishtimer[playerid]);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        HidePlayerFishText(playerid);
                        Fishes[playerid][pLastWeight] = Caught;
                        Fishes[playerid][pLastFish] = 2;
                        Fishes[playerid][pFid2] = rand;
                        Fishes[playerid][pFishID] = rand;
                        if(Caught > PlayerInfo[playerid][pBiggestFish])
                        {
                            format(string, sizeof(string), "* You've beaten your old record of %d pounds!  Your new biggest fish is: %d pounds.", PlayerInfo[playerid][pBiggestFish], Caught);
                            SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                            PlayerInfo[playerid][pBiggestFish] = Caught;
                        }
                    }
                    else if(Fishes[playerid][pWeight3] == 0)
                    {
                        new string[85];
                        PlayerInfo[playerid][pFishes] += 1;
                        PlayerInfo[playerid][pFishSkill] += 1;
                        format(fstring, sizeof(fstring), "%s", FishNames[rand]);
                        strmid(Fishes[playerid][pFish3], fstring, 0, strlen(fstring), 255);
                        Fishes[playerid][pWeight3] = Caught;
                        format(string, sizeof(string), "* You have caught a %s, which weights %d pounds.", Fishes[playerid][pFish3], Caught);
                        SendClientMessage(playerid, COLOR_GREY, string);
                        format(string, sizeof(string), "* %s reels in a %s, on %d lbs.", RemoveUnderScore(playerid), Fishes[playerid][pFish3], Caught);
                        ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                        RemovePlayerAttachedObject(playerid,0);
                        KillTimer(fishtimer[playerid]);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        HidePlayerFishText(playerid);
                        Fishes[playerid][pLastWeight] = Caught;
                        Fishes[playerid][pLastFish] = 3;
                        Fishes[playerid][pFid3] = rand;
                        Fishes[playerid][pFishID] = rand;
                        if(Caught > PlayerInfo[playerid][pBiggestFish])
                        {
                            format(string, sizeof(string), "* You've beaten your old record of %d pounds!  Your new biggest fish is: %d pounds.", PlayerInfo[playerid][pBiggestFish], Caught);
                            SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                            PlayerInfo[playerid][pBiggestFish] = Caught;
                        }
                    }
                    else if(Fishes[playerid][pWeight4] == 0)
                    {
                        new string[85];
                        PlayerInfo[playerid][pFishes] += 1;
                        PlayerInfo[playerid][pFishSkill] += 1;
                        format(fstring, sizeof(fstring), "%s", FishNames[rand]);
                        strmid(Fishes[playerid][pFish4], fstring, 0, strlen(fstring), 255);
                        Fishes[playerid][pWeight4] = Caught;
                        format(string, sizeof(string), "* You have caught a %s, which weights %d pounds.", Fishes[playerid][pFish4], Caught);
                        SendClientMessage(playerid, COLOR_GREY, string);
                        format(string, sizeof(string), "* %s reels in a %s, on %d lbs.", RemoveUnderScore(playerid), Fishes[playerid][pFish4], Caught);
                        ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                        RemovePlayerAttachedObject(playerid,0);
                        KillTimer(fishtimer[playerid]);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        HidePlayerFishText(playerid);
                        Fishes[playerid][pLastWeight] = Caught;
                        Fishes[playerid][pLastFish] = 4;
                        Fishes[playerid][pFid4] = rand;
                        Fishes[playerid][pFishID] = rand;
                        if(Caught > PlayerInfo[playerid][pBiggestFish])
                        {
                            format(string, sizeof(string), "* You've beaten your old record of %d pounds!  Your new biggest fish is: %d pounds.", PlayerInfo[playerid][pBiggestFish], Caught);
                            SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                            PlayerInfo[playerid][pBiggestFish] = Caught;
                        }
                    }
                    else if(Fishes[playerid][pWeight5] == 0)
                    {
                        new string[85];
                        PlayerInfo[playerid][pFishes] += 1;
                        PlayerInfo[playerid][pFishSkill] += 1;
                        format(fstring, sizeof(fstring), "%s", FishNames[rand]);
                        strmid(Fishes[playerid][pFish5], fstring, 0, strlen(fstring), 255);
                        Fishes[playerid][pWeight5] = Caught;
                        format(string, sizeof(string), "* You have caught a %s, which weights %d pounds.", Fishes[playerid][pFish5], Caught);
                        SendClientMessage(playerid, COLOR_GREY, string);
                        format(string, sizeof(string), "* %s reels in a %s, on %d lbs.", RemoveUnderScore(playerid), Fishes[playerid][pFish5], Caught);
                        ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                        RemovePlayerAttachedObject(playerid,0);
                        KillTimer(fishtimer[playerid]);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        HidePlayerFishText(playerid);
                        Fishes[playerid][pLastWeight] = Caught;
                        Fishes[playerid][pLastFish] = 5;
                        Fishes[playerid][pFid5] = rand;
                        Fishes[playerid][pFishID] = rand;
                        if(Caught > PlayerInfo[playerid][pBiggestFish])
                        {
                            format(string, sizeof(string), "* You've beaten your old record of %d pounds!  Your new biggest fish is: %d pounds.", PlayerInfo[playerid][pBiggestFish], Caught);
                            SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                            PlayerInfo[playerid][pBiggestFish] = Caught;
                        }
                    }
                }
            }
        }
    }
    return 1;
}
Reply
#2

Can anyone help me?
please tell me if i have to explain better
Reply
#3

pawn Код:
new luck = Random(1, 100);
if (luck <= 10)
{
    // 10% - spas
}
else if (luck <=30)
{
    // 30 % - pool cue
}
Just make sure the lowest percentage comes fist in the if-else statements.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)