SA-MP Forums Archive
Bug while fishing with random. - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Bug while fishing with random. (/showthread.php?tid=171611)



Bug while fishing with random. - Jochemd - 27.08.2010

Hello,

I created my Fisherman job a few days ago. Now it is bugging. For example: when I catch a 2kg fish, it counts always every fish like 34kg. Isn't that weird?

pawn Код:
new RandomFish[][] =
{
    {"* You caught a 2 kilogramm Carper.", 2 },
    {"* You caught a 3 kilogramm Carper.", 3 },
    {"* You caught a 4 kilogramm Carper.", 4 },
    {"* You caught a 5 kilogramm Carper.", 5 },
    {"* You caught a 2 kilogramm Driftfish.", 2 },
    {"* You caught a 3 kilogramm Driftfish.", 3 },
    {"* You caught a 4 kilogramm Driftfish.", 4 },
    {"* You caught a 5 kilogramm Driftfish.", 5 },
    {"* You caught a 6 kilogramm Driftfish.", 6 },
    {"* You didn't catch a fish, sorry.", 0 },
    {"* You didn't catch a fish, sorry.", 0 },
    {"* You didn't catch a fish, sorry.", 0 },
    {"* You didn't catch a fish, sorry.", 0 },
    {"* You didn't catch a fish, sorry.", 0 },
    {"* You didn't catch a fish, sorry.", 0 },
    {"* You didn't catch a fish, sorry.", 0 },
    {"* You didn't catch a fish, sorry.", 0 },
    {"* You didn't catch a fish, sorry.", 0 },
    {"* You didn't catch a fish, sorry.", 0 },
    {"* You didn't catch a fish, sorry.", 0 },
    {"* You didn't catch a fish, sorry.", 0 },
    {"* You didn't catch a fish, sorry.", 0 },
    {"* You didn't catch a fish, sorry.", 0 },
    {"* You didn't catch a fish, sorry.", 0 }
};
pawn Код:
dcmd_fish(playerid,params[])
{
    #pragma unused params
    if(PlayerInfo[playerid][gTeam] == TEAM_FISHERMANS)
    {
        if(IsPlayerInVehicle(playerid,FishermanBoat1) || IsPlayerInVehicle(playerid,FishermanBoat2)|| IsPlayerInVehicle(playerid,FishermanBoat3))
        {
            if(IsPlayerInRangeOfPoint(playerid,50,-2490.133300,2001.119873,-0.331034) || IsPlayerInRangeOfPoint(playerid,50,-1329.810913, 1586.480590, -0.475296) || IsPlayerInRangeOfPoint(playerid,50,1970.885742, -140.405670, -0.250106))
            {
                new rand = random(sizeof(RandomFish));
                SendClientMessage(playerid,COLOR_GREEN,RandomFish[rand][0]);
                PlayerInfo[playerid][CaughtFish] = PlayerInfo[playerid][CaughtFish] + RandomFish[rand][2];
            }
            else return SendClientMessage(playerid,COLOR_RED,"* There is no fish in this area, type /fisharea to go to one.");
        }
        else return SendClientMessage(playerid,COLOR_RED,"* You can't fish in this boat.");
    }
    else return SendClientMessage(playerid,COLOR_RED,"* You are not a Fisherman.");
    return 1;
}
I hope someone knows this bug

Regards, Jochem


Re: Bug while fishing with random. - Jochemd - 27.08.2010

Quick note: maybe the mistake is while setting the variable?..


Re: Bug while fishing with random. - BuLLeT[LTU] - 27.08.2010

new RandomFish[][]

You have to write size in [] []


Re: Bug while fishing with random. - Jochemd - 27.08.2010

What do you mean: size?


Re: Bug while fishing with random. - iggy1 - 27.08.2010

No [][] is fine the compiler will calculate the size of the variable.

EDIT:
Try changing this
pawn Код:
SendClientMessage(playerid,COLOR_GREEN,RandomFish[rand][0]);
To
pawn Код:
SendClientMessage(playerid,COLOR_GREEN,RandomFish[rand]);



Re: Bug while fishing with random. - Jochemd - 27.08.2010

Well the messages aren't the problem. The problem is while setting the variable, it sets 34 when catching a fish (or not)


Re: Bug while fishing with random. - iggy1 - 27.08.2010

Hmm try,
pawn Код:
PlayerInfo[playerid][CaughtFish] = PlayerInfo[playerid][CaughtFish] + RandomFish[rand][1];
Maybe that will work. Does "PlayerInfo[playerid][CaughtFish]" hold anything to begin with?


Re: Bug while fishing with random. - Jochemd - 27.08.2010

It still keeps adding 32, even if I didnt catch anything.


Re: Bug while fishing with random. - Jochemd - 27.08.2010

No, it starts holding a value when I start fishing.


Re: Bug while fishing with random. - Hiddos - 27.08.2010

Tried:

pawn Код:
PlayerInfo[playerid][CaughtFish] += RandomFish[rand][1];
Instead of:
pawn Код:
PlayerInfo[playerid][CaughtFish] = PlayerInfo[playerid][CaughtFish] + RandomFish[rand][2]; //Can only select between 0 & 1, 2 is beyond the array's limit.