bug with random weitht output
#1

sometimes when i catch a fish, it says the weight for example -45Lbs
and sometimes 32Lbs, also it goes minus- How come?

pawn Код:
if(PRESSED(KEY_AIM))
    {
        if (FishCaught[playerid] == 1)
        {
            if(IsPlayerNearWater(playerid) || IsPlayerInWater(playerid))
            {
                //if(Fishing[playerid] == 1)
                {
                    new Caught;
                    new rand;
                    new luck = Random(1, 100);
                    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(luck <= 6)
                    {
                        SendClientMessage(playerid, COLOR_GREY, "   You caught a headcrab and threw it away!");
                        HidePlayerFishText(playerid);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        Fishes[playerid][pTempFishName] = 0;
                        RemovePlayerAttachedObject(playerid,0);
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    if(luck <= 7)
                    {
                        SendClientMessage(playerid, COLOR_GREY, "   You caught a g-string and threw it away!");
                        HidePlayerFishText(playerid);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        Fishes[playerid][pTempFishName] = 0;
                        RemovePlayerAttachedObject(playerid,0);
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    if(luck <= 8)
                    {
                        SendClientMessage(playerid, COLOR_GREY, "   You caught a can and threw it away!");
                        HidePlayerFishText(playerid);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        Fishes[playerid][pTempFishName] = 0;
                        RemovePlayerAttachedObject(playerid,0);
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    if(luck <= 9)
                    {
                        SendClientMessage(playerid, COLOR_GREY, "   You caught a used condom and threw it away!");
                        HidePlayerFishText(playerid);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        Fishes[playerid][pTempFishName] = 0;
                        RemovePlayerAttachedObject(playerid,0);
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    if(luck <= 15)
                    {
                        new string[85];
                        new weapon[MAX_PLAYERS];
                        HidePlayerFishText(playerid);
                        AddWeapon(playerid,weapon[playerid] = 31);
                        PlayerInfo[playerid][pFishSkill] += 1;
                        Fishes[playerid][pTempFishName] = 0;
                        format(string, sizeof(string), "* %s reels in an M4.", RemoveUnderScore(playerid));
                        ProxDetector(30.0, playerid, string, COLOR_RED,COLOR_RED,COLOR_RED,COLOR_RED,COLOR_RED);
                        RemovePlayerAttachedObject(playerid,0);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    if(luck <= 18)
                    {
                        new string[85];
                        new weapon[MAX_PLAYERS];
                        HidePlayerFishText(playerid);
                        AddWeapon(playerid,weapon[playerid] = 30);
                        PlayerInfo[playerid][pFishSkill] += 1;
                        Fishes[playerid][pTempFishName] = 0;
                        format(string, sizeof(string), "* %s reels in an AK 47.", RemoveUnderScore(playerid));
                        ProxDetector(30.0, playerid, string, COLOR_RED,COLOR_RED,COLOR_RED,COLOR_RED,COLOR_RED);
                        RemovePlayerAttachedObject(playerid,0);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        KillTimer(fishtimer[playerid]);
                        return 1;
                    }
                    if(luck <= 70)
                    {
                        new string[85];
                        HidePlayerFishText(playerid);
                        PlayerInfo[playerid][pFishes] += 1;
                        PlayerInfo[playerid][pFishSkill] += 1;
                        format(fstring, sizeof(fstring), "%s", FishNames[rand]);
                        strmid(Fishes[playerid][pFish], fstring, 0, strlen(fstring), 255);
                        Fishes[playerid][pWeight3] = Caught;
                        format(string, sizeof(string), "* %s reels in a %s, weighing %d lbs!", RemoveUnderScore(playerid), Fishes[playerid][pFish], Caught);
                        ProxDetector(30.0, playerid, string, COLOR_RED,COLOR_RED,COLOR_RED,COLOR_RED,COLOR_RED);
                        RemovePlayerAttachedObject(playerid,0);
                        KillTimer(fishtimer[playerid]);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        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;
                        }
                        return 1;
                    }
                    if(luck <= 70)
                    {
                        new string[85];
                        HidePlayerFishText(playerid);
                        PlayerInfo[playerid][pFishes] += 1;
                        PlayerInfo[playerid][pFishSkill] += 1;
                        format(fstring, sizeof(fstring), "%s", FishNames[rand]);
                        strmid(Fishes[playerid][pFish], fstring, 0, strlen(fstring), 255);
                        Fishes[playerid][pWeight4] = Caught;
                        format(string, sizeof(string), "* %s reels in a %s weighing %d lbs!", RemoveUnderScore(playerid), Fishes[playerid][pFish], Caught);
                        ProxDetector(30.0, playerid, string, COLOR_RED,COLOR_RED,COLOR_RED,COLOR_RED,COLOR_RED);
                        RemovePlayerAttachedObject(playerid,0);
                        KillTimer(fishtimer[playerid]);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        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;
                        }
                        return 1;
                    }
                    if(luck <= 70)
                    {
                        new string[85];
                        HidePlayerFishText(playerid);
                        PlayerInfo[playerid][pFishes] += 1;
                        PlayerInfo[playerid][pFishSkill] += 1;
                        format(fstring, sizeof(fstring), "%s", FishNames[rand]);
                        strmid(Fishes[playerid][pFish], fstring, 0, strlen(fstring), 255);
                        Fishes[playerid][pWeight5] = Caught;
                        format(string, sizeof(string), "* %s reels in a %s weighing %d lbs!", RemoveUnderScore(playerid), Fishes[playerid][pFish], Caught);
                        ProxDetector(30.0, playerid, string, COLOR_RED,COLOR_RED,COLOR_RED,COLOR_RED,COLOR_RED);
                        RemovePlayerAttachedObject(playerid,0);
                        KillTimer(fishtimer[playerid]);
                        FishCaught[playerid] = 0;
                        Fishing[playerid] = 0;
                        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;
                    }
                    if(PlayerInfo[playerid][pFishSkill] == 50)
                    { SendClientMessage(playerid, COLOR_YELLOW, "* Your fishing skill is now level 2."); }
                    else if(PlayerInfo[playerid][pFishSkill] == 100)
                    { SendClientMessage(playerid, COLOR_YELLOW, "* Your fishing skill is now level 3."); }
                    else if(PlayerInfo[playerid][pFishSkill] == 200)
                    { SendClientMessage(playerid, COLOR_YELLOW, "* Your fishing skill is now level 4."); }
                    else if(PlayerInfo[playerid][pFishSkill] == 400)
                    { SendClientMessage(playerid, COLOR_YELLOW, "* Your fishing skill is now level 5."); }
                    else if(PlayerInfo[playerid][pFishSkill] == 700)
                    { SendClientMessage(playerid, COLOR_YELLOW, "* The fish gods are mad at you!. You no longer can catch fish."); }
                }
            }
        }
    }
    return 1;
}
Reply
#2

Could you please give us some more information. What did the excecutor say?
Reply
#3

Quote:
Originally Posted by Codeah
Посмотреть сообщение
Could you please give us some more information. What did the excecutor say?
What do you mean by that?
Reply
#4

Rethink what your code does
PHP код:
Caught random(20)-7
random(20) will return a number from 0 till 19
subtacting 7 will result in an overall output from -7 till 12
Reply
#5

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Rethink what your code does
PHP код:
Caught random(20)-7
random(20) will return a number from 0 till 19
subtacting 7 will result in an overall output from -7 till 12
How should i make it then?
Reply
#6

What do you want to achive ?

If you want to have a random value between two numbers use Random(7, 20); like you did with the luck variable
Reply
#7

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
What do you want to achive ?

If you want to have a random value between two numbers use Random(7, 20); like you did with the luck variable
Yes, but it must be based on the skill levels, so as higher your skill is, as heavier fish can you catch
Reply
#8

I changed it to this
pawn Код:
if(Level >= 0 && Level < 50) { Caught = random(7, 20); }
                    else if(Level >= 50 && Level < 100) { Caught = random(20, 50); }
                    else if(Level >= 100 && Level < 200) { Caught = random(50, 100); }
                    else if(Level >= 200 && Level < 400) { Caught = random(60, 140); }
                    else if(Level >= 400 && Level < 500) { Caught = random(60, 170); }
But that gave me this output
pawn Код:
C:\Users\Maya\Desktop\gf_july21_2016.pwn(30507) : warning 202: number of arguments does not match definition
C:\Users\Maya\Desktop\gf_july21_2016.pwn(30508) : warning 202: number of arguments does not match definition
C:\Users\Maya\Desktop\gf_july21_2016.pwn(30509) : warning 202: number of arguments does not match definition
C:\Users\Maya\Desktop\gf_july21_2016.pwn(30510) : warning 202: number of arguments does not match definition
C:\Users\Maya\Desktop\gf_july21_2016.pwn(30511) : warning 202: number of arguments does not match definition
Reply
#9

Yes, because the function uses only one parameter.
pawn Код:
native random(max);
Use this:
pawn Код:
if(Level >= 0   && Level < 50)  { Caught = random((20 -  7 + 1)) + 7; }
else if(Level >= 50  && Level < 100) { Caught = random((50 - 20 + 1)) + 20; }
else if(Level >= 100 && Level < 200) { Caught = random((100 - 50 + 1)) + 50; }
else if(Level >= 200 && Level < 400) { Caught = random((140 - 60 + 1)) + 60; }
else if(Level >= 400 && Level < 500) { Caught = random((170 - 60 + 1)) + 60; }
min. value: +7
max. value: +170

or this:
pawn Код:
if(Level >= 0   && Level < 50)  { Caught = random((20 -  7 + 1)) - 7; }
else if(Level >= 50  && Level < 100) { Caught = random((50 - 20 + 1)) - 20; }
else if(Level >= 100 && Level < 200) { Caught = random((100 - 50 + 1)) - 50; }
else if(Level >= 200 && Level < 400) { Caught = random((140 - 60 + 1)) - 60; }
else if(Level >= 400 && Level < 500) { Caught = random((170 - 60 + 1)) - 60; }
Reply
#10

Quote:
Originally Posted by MayaEU
Посмотреть сообщение
I changed it to this
pawn Код:
if(Level >= 0 && Level < 50) { Caught = random(7, 20); }
                    else if(Level >= 50 && Level < 100) { Caught = random(20, 50); }
                    else if(Level >= 100 && Level < 200) { Caught = random(50, 100); }
                    else if(Level >= 200 && Level < 400) { Caught = random(60, 140); }
                    else if(Level >= 400 && Level < 500) { Caught = random(60, 170); }
You have to use Random not random like in that line

Quote:
Originally Posted by MayaEU
Посмотреть сообщение
pawn Код:
new luck = Random(1, 100);
Random should be somewhere in your script which basically does what VVWVV did

Random(min, max) return random(max - min + 1) + min;
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)