What's wrong with my /fishes command?
#1

Why isn't this displaying all 5 fishing slots instead of just 1?

pawn Код:
CMD:fishes(playerid, params[])
{
    new string[2048];
    SendClientMessage(playerid, COLOR_ORANGE, "Fish Inventory{FFFFFF}:");
    if(PlayerInfo[playerid][pFishName1] == 0)
    {
        SendClientMessage(playerid, COLOR_WHITE, "Slot 1: Empty.");
    }
    else if(PlayerInfo[playerid][pFishName1] == 1)
    {
        format(string, sizeof(string), "Slot 1: Shark weighing %d lbs.", PlayerInfo[playerid][pFish1]);
    }
    else if(PlayerInfo[playerid][pFishName1] == 2)
    {
        format(string, sizeof(string), "Slot 1: Clownfish weighing %d lbs.", PlayerInfo[playerid][pFish1]);
    }
    else if(PlayerInfo[playerid][pFishName1] == 3)
    {
        format(string, sizeof(string), "Slot 1: Angelfish weighing %d lbs.", PlayerInfo[playerid][pFish1]);
    }
    else if(PlayerInfo[playerid][pFishName1] == 4)
    {
        format(string, sizeof(string), "Slot 1: Catfish weighing %d lbs.", PlayerInfo[playerid][pFish1]);
    }
    else if(PlayerInfo[playerid][pFishName1] == 5)
    {
        format(string, sizeof(string), "Slot 1: Dogfish weighing %d lbs.", PlayerInfo[playerid][pFish1]);
    }
    else if(PlayerInfo[playerid][pFishName1] == 6)
    {
        format(string, sizeof(string), "Slot 1: Eel weighing %d lbs.", PlayerInfo[playerid][pFish1]);
    }
    else if(PlayerInfo[playerid][pFishName2] == 0)
    {
        SendClientMessage(playerid, COLOR_WHITE, "Slot 2: Empty.");
    }
    else if(PlayerInfo[playerid][pFishName2] == 1)
    {
        format(string, sizeof(string), "Slot 2: Shark weighing %d lbs.", PlayerInfo[playerid][pFish2]);
    }
    else if(PlayerInfo[playerid][pFishName2] == 2)
    {
        format(string, sizeof(string), "Slot 2: Clownfish weighing %d lbs.", PlayerInfo[playerid][pFish2]);
    }
    else if(PlayerInfo[playerid][pFishName2] == 3)
    {
        format(string, sizeof(string), "Slot 2: Angelfish weighing %d lbs.", PlayerInfo[playerid][pFish2]);
    }
    else if(PlayerInfo[playerid][pFishName2] == 4)
    {
        format(string, sizeof(string), "Slot 2: Catfish weighing %d lbs.", PlayerInfo[playerid][pFish2]);
    }
    else if(PlayerInfo[playerid][pFishName2] == 5)
    {
        format(string, sizeof(string), "Slot 2: Dogfish weighing %d lbs.", PlayerInfo[playerid][pFish2]);
    }
    else if(PlayerInfo[playerid][pFishName2] == 6)
    {
        format(string, sizeof(string), "Slot 2: Eel weighing %d lbs.", PlayerInfo[playerid][pFish2]);
    }
    else if(PlayerInfo[playerid][pFishName3] == 0)
    {
        SendClientMessage(playerid, COLOR_WHITE, "Slot 3: Empty.");
    }
    else if(PlayerInfo[playerid][pFishName3] == 1)
    {
        format(string, sizeof(string), "Slot 3: Shark weighing %d lbs.", PlayerInfo[playerid][pFish3]);
    }
    else if(PlayerInfo[playerid][pFishName3] == 2)
    {
        format(string, sizeof(string), "Slot 3: Clownfish weighing %d lbs.", PlayerInfo[playerid][pFish3]);
    }
    else if(PlayerInfo[playerid][pFishName3] == 3)
    {
        format(string, sizeof(string), "Slot 3: Angelfish weighing %d lbs.", PlayerInfo[playerid][pFish3]);
    }
    else if(PlayerInfo[playerid][pFishName3] == 4)
    {
        format(string, sizeof(string), "Slot 3: Catfish weighing %d lbs.", PlayerInfo[playerid][pFish3]);
    }
    else if(PlayerInfo[playerid][pFishName3] == 5)
    {
        format(string, sizeof(string), "Slot 3: Dogfish weighing %d lbs.", PlayerInfo[playerid][pFish3]);
    }
    else if(PlayerInfo[playerid][pFishName3] == 6)
    {
        format(string, sizeof(string), "Slot 3: Eel weighing %d lbs.", PlayerInfo[playerid][pFish3]);
    }
    else if(PlayerInfo[playerid][pFishName4] == 0)
    {
        SendClientMessage(playerid, COLOR_WHITE, "Slot 4: Empty.");
    }
    else if(PlayerInfo[playerid][pFishName4] == 1)
    {
        format(string, sizeof(string), "Slot 4: Shark weighing %d lbs.", PlayerInfo[playerid][pFish4]);
    }
    else if(PlayerInfo[playerid][pFishName4] == 2)
    {
        format(string, sizeof(string), "Slot 4: Clownfish weighing %d lbs.", PlayerInfo[playerid][pFish4]);
    }
    else if(PlayerInfo[playerid][pFishName4] == 3)
    {
        format(string, sizeof(string), "Slot 4: Angelfish weighing %d lbs.", PlayerInfo[playerid][pFish4]);
    }
    else if(PlayerInfo[playerid][pFishName4] == 4)
    {
        format(string, sizeof(string), "Slot 4: Catfish weighing %d lbs.", PlayerInfo[playerid][pFish4]);
    }
    else if(PlayerInfo[playerid][pFishName4] == 5)
    {
        format(string, sizeof(string), "Slot 4: Dogfish weighing %d lbs.", PlayerInfo[playerid][pFish4]);
    }
    else if(PlayerInfo[playerid][pFishName4] == 6)
    {
        format(string, sizeof(string), "Slot 4: Eel weighing %d lbs.", PlayerInfo[playerid][pFish4]);
    }
    else if(PlayerInfo[playerid][pFishName5] == 0)
    {
        SendClientMessage(playerid, COLOR_WHITE, "Slot 5: Empty.");
    }
    else if(PlayerInfo[playerid][pFishName5] == 1)
    {
        format(string, sizeof(string), "Slot 5: Shark weighing %d lbs.", PlayerInfo[playerid][pFish5]);
    }
    else if(PlayerInfo[playerid][pFishName5] == 2)
    {
        format(string, sizeof(string), "Slot 5: Clownfish weighing %d lbs.", PlayerInfo[playerid][pFish5]);
    }
    else if(PlayerInfo[playerid][pFishName5] == 3)
    {
        format(string, sizeof(string), "Slot 5: Angelfish weighing %d lbs.", PlayerInfo[playerid][pFish5]);
    }
    else if(PlayerInfo[playerid][pFishName5] == 4)
    {
        format(string, sizeof(string), "Slot 5: Catfish weighing %d lbs.", PlayerInfo[playerid][pFish5]);
    }
    else if(PlayerInfo[playerid][pFishName5] == 5)
    {
        format(string, sizeof(string), "Slot 5: Dogfish weighing %d lbs.", PlayerInfo[playerid][pFish5]);
    }
    else if(PlayerInfo[playerid][pFishName5] == 6)
    {
        format(string, sizeof(string), "Slot 5: Eel weighing %d lbs.", PlayerInfo[playerid][pFish5]);
    }
    SendClientMessage(playerid, COLOR_WHITE, string);
    format(string, sizeof(string), "Bait{FFFFFF}: %d "Grey"- "Orange"Rod Durability{FFFFFF}: %d%", PlayerInfo[playerid][pBait], PlayerInfo[playerid][pRodDurab]);
    SendClientMessage(playerid, COLOR_ORANGE, string);
    return 1;
}
Reply
#2

You should start a new if-statement for each name. If a condition goes through, the else-ifs will all fail and the check will be finished.
Reply
#3

I now have it all like this:

pawn Код:
CMD:fishes(playerid, params[])
{
    new string[2048];
    SendClientMessage(playerid, COLOR_ORANGE, "Fish Inventory{FFFFFF}:");
    if(PlayerInfo[playerid][pFishName1] == 0)
    {
        SendClientMessage(playerid, COLOR_WHITE, "Slot 1: Empty.");
    }
    if(PlayerInfo[playerid][pFishName1] == 1)
    {
        format(string, sizeof(string), "Slot 1: Shark weighing %d lbs.", PlayerInfo[playerid][pFish1]);
    }
    if(PlayerInfo[playerid][pFishName1] == 2)
    {
        format(string, sizeof(string), "Slot 1: Clownfish weighing %d lbs.", PlayerInfo[playerid][pFish1]);
    }
    if(PlayerInfo[playerid][pFishName1] == 3)
    {
        format(string, sizeof(string), "Slot 1: Angelfish weighing %d lbs.", PlayerInfo[playerid][pFish1]);
    }
    if(PlayerInfo[playerid][pFishName1] == 4)
    {
        format(string, sizeof(string), "Slot 1: Catfish weighing %d lbs.", PlayerInfo[playerid][pFish1]);
    }
    if(PlayerInfo[playerid][pFishName1] == 5)
    {
        format(string, sizeof(string), "Slot 1: Dogfish weighing %d lbs.", PlayerInfo[playerid][pFish1]);
    }
    if(PlayerInfo[playerid][pFishName1] == 6)
    {
        format(string, sizeof(string), "Slot 1: Eel weighing %d lbs.", PlayerInfo[playerid][pFish1]);
    }
    if(PlayerInfo[playerid][pFishName2] == 0)
    {
        SendClientMessage(playerid, COLOR_WHITE, "Slot 2: Empty.");
    }
    if(PlayerInfo[playerid][pFishName2] == 1)
    {
        format(string, sizeof(string), "Slot 2: Shark weighing %d lbs.", PlayerInfo[playerid][pFish2]);
    }
    if(PlayerInfo[playerid][pFishName2] == 2)
    {
        format(string, sizeof(string), "Slot 2: Clownfish weighing %d lbs.", PlayerInfo[playerid][pFish2]);
    }
    if(PlayerInfo[playerid][pFishName2] == 3)
    {
        format(string, sizeof(string), "Slot 2: Angelfish weighing %d lbs.", PlayerInfo[playerid][pFish2]);
    }
    if(PlayerInfo[playerid][pFishName2] == 4)
    {
        format(string, sizeof(string), "Slot 2: Catfish weighing %d lbs.", PlayerInfo[playerid][pFish2]);
    }
    if(PlayerInfo[playerid][pFishName2] == 5)
    {
        format(string, sizeof(string), "Slot 2: Dogfish weighing %d lbs.", PlayerInfo[playerid][pFish2]);
    }
    if(PlayerInfo[playerid][pFishName2] == 6)
    {
        format(string, sizeof(string), "Slot 2: Eel weighing %d lbs.", PlayerInfo[playerid][pFish2]);
    }
    if(PlayerInfo[playerid][pFishName3] == 0)
    {
        SendClientMessage(playerid, COLOR_WHITE, "Slot 3: Empty.");
    }
    if(PlayerInfo[playerid][pFishName3] == 1)
    {
        format(string, sizeof(string), "Slot 3: Shark weighing %d lbs.", PlayerInfo[playerid][pFish3]);
    }
    if(PlayerInfo[playerid][pFishName3] == 2)
    {
        format(string, sizeof(string), "Slot 3: Clownfish weighing %d lbs.", PlayerInfo[playerid][pFish3]);
    }
    if(PlayerInfo[playerid][pFishName3] == 3)
    {
        format(string, sizeof(string), "Slot 3: Angelfish weighing %d lbs.", PlayerInfo[playerid][pFish3]);
    }
    if(PlayerInfo[playerid][pFishName3] == 4)
    {
        format(string, sizeof(string), "Slot 3: Catfish weighing %d lbs.", PlayerInfo[playerid][pFish3]);
    }
    if(PlayerInfo[playerid][pFishName3] == 5)
    {
        format(string, sizeof(string), "Slot 3: Dogfish weighing %d lbs.", PlayerInfo[playerid][pFish3]);
    }
    if(PlayerInfo[playerid][pFishName3] == 6)
    {
        format(string, sizeof(string), "Slot 3: Eel weighing %d lbs.", PlayerInfo[playerid][pFish3]);
    }
    if(PlayerInfo[playerid][pFishName4] == 0)
    {
        SendClientMessage(playerid, COLOR_WHITE, "Slot 4: Empty.");
    }
    if(PlayerInfo[playerid][pFishName4] == 1)
    {
        format(string, sizeof(string), "Slot 4: Shark weighing %d lbs.", PlayerInfo[playerid][pFish4]);
    }
    if(PlayerInfo[playerid][pFishName4] == 2)
    {
        format(string, sizeof(string), "Slot 4: Clownfish weighing %d lbs.", PlayerInfo[playerid][pFish4]);
    }
    if(PlayerInfo[playerid][pFishName4] == 3)
    {
        format(string, sizeof(string), "Slot 4: Angelfish weighing %d lbs.", PlayerInfo[playerid][pFish4]);
    }
    if(PlayerInfo[playerid][pFishName4] == 4)
    {
        format(string, sizeof(string), "Slot 4: Catfish weighing %d lbs.", PlayerInfo[playerid][pFish4]);
    }
    if(PlayerInfo[playerid][pFishName4] == 5)
    {
        format(string, sizeof(string), "Slot 4: Dogfish weighing %d lbs.", PlayerInfo[playerid][pFish4]);
    }
    if(PlayerInfo[playerid][pFishName4] == 6)
    {
        format(string, sizeof(string), "Slot 4: Eel weighing %d lbs.", PlayerInfo[playerid][pFish4]);
    }
    if(PlayerInfo[playerid][pFishName5] == 0)
    {
        SendClientMessage(playerid, COLOR_WHITE, "Slot 5: Empty.");
    }
    if(PlayerInfo[playerid][pFishName5] == 1)
    {
        format(string, sizeof(string), "Slot 5: Shark weighing %d lbs.", PlayerInfo[playerid][pFish5]);
    }
    if(PlayerInfo[playerid][pFishName5] == 2)
    {
        format(string, sizeof(string), "Slot 5: Clownfish weighing %d lbs.", PlayerInfo[playerid][pFish5]);
    }
    if(PlayerInfo[playerid][pFishName5] == 3)
    {
        format(string, sizeof(string), "Slot 5: Angelfish weighing %d lbs.", PlayerInfo[playerid][pFish5]);
    }
    if(PlayerInfo[playerid][pFishName5] == 4)
    {
        format(string, sizeof(string), "Slot 5: Catfish weighing %d lbs.", PlayerInfo[playerid][pFish5]);
    }
    if(PlayerInfo[playerid][pFishName5] == 5)
    {
        format(string, sizeof(string), "Slot 5: Dogfish weighing %d lbs.", PlayerInfo[playerid][pFish5]);
    }
    if(PlayerInfo[playerid][pFishName5] == 6)
    {
        format(string, sizeof(string), "Slot 5: Eel weighing %d lbs.", PlayerInfo[playerid][pFish5]);
    }
    SendClientMessage(playerid, COLOR_WHITE, string);
    format(string, sizeof(string), "Bait{FFFFFF}: %d "Grey"- "Orange"Rod Durability{FFFFFF}: %d%", PlayerInfo[playerid][pBait], PlayerInfo[playerid][pRodDurab]);
    SendClientMessage(playerid, COLOR_ORANGE, string);
    return 1;
}
But they don't seem to be in ascending order and slot 1 doesn't show:

Reply
#4

That's because you don't send the client message after formatting it when the name isn't equal to 0. As you can see, Slot 2 is sent at the end of it because that's when you send 'string', and Slot 1 won't be sent, as Slot 2 is formatted after, and replacing Slot 1.
Reply
#5

So sending the client message after EVERY format should solve the problem?
Reply
#6

Legend, fixed. +rep.
Just thought considering there's no "return 1" after each format, the send client will recognise each string.
Reply
#7

Well yes, but that would honestly be a waste of code. Here's how I would do it: http://pastebin.com/7KSTwV3w
Reply
#8

Ah, I see, cheers! How could I make this so these fish names that are selected at random, the fish have a higher chance of being called than the moneybags?

pawn Код:
new FishNames[][] =
{
    "Shark",// 0
    "Clownfish",// 1
    "Angelfish",// 2
    "Catfish",// 3
    "Dogfish",// 4
    "Eel",// 5
    "$7 Moneybag"// 6
    "$18 Moneybag"// 7
    "$23 Moneybag"// 8
    "$27 Moneybag"// 9
    "$36 Moneybag"// 10
    "$49 Moneybag"// 11
    "$62 Moneybag"// 12
    "$88 Moneybag"// 13
    "$99 Moneybag"// 14
    "$112 Moneybag"// 15
    "$140 Moneybag"// 16
    "$171 Moneybag"// 17
    "$195 Moneybag"// 18
    "$217 Moneybag"// 19
    "$232 Moneybag"// 20
    "$258 Moneybag"// 21
    "$284 Moneybag"// 22
    "$293 Moneybag"// 23
    "$326 Moneybag"// 24
    "$348 Moneybag"// 25
    "$351 Moneybag"// 26
    "$374 Moneybag"// 27
    "$386 Moneybag"// 28
    "$391 Moneybag"// 29
    "$420 Moneybag"// 30
    "$467 Moneybag"// 31
    "$492 Moneybag"// 32
};
Reply
#9

Well you'd have to use the 'random' function for that.
What you could do was something like this:

pawn Код:
new
    iRand = random(87)
;

if( iRand < 10 ) // 0 - 9
{
    iRand = 0
}
else if( iRand < 20 ) // 10 - 19
{
    iRand = 1;
}
else if( iRand < 30 ) // 20 - 29
{
    iRand = 2;
}
else if( iRand < 40 ) // 30 - 39
{
    iRand = 3;
}
else if( iRand < 50 ) // 40 - 49
{
    iRand = 4;
}
else if( iRand < 60 ) // 50 - 59
{
    iRand = 5;
}
else
{
    iRand -= 54;
}
Here I created a random value from 0 to 86.
Your array has only 33 indexes - this is why I have to check its value.
With the code above, the numbers 0-9 will give you the first index ("Shark"), 10-19 will give you the next one, et cetera.
If your randomly chosen value is 60 or more, it will simply set the moneybags.
Moneybag #1 is on index 6, so value 60 should be index 6, and we all know that 60 - 54 = 6, hence the "iRand -= 54;" expression.

If you want less change of getting moneybags, increase the integer used in the 'random' function call by a number dividible by 6, as you have 6 fishes, then change the if-statements to match it.

To then select your index, you simply have to do this:

pawn Код:
FishNames[ iRand ]

//example:
format( string, sizeof( string ), "%s", FishNames[ iRand ] );
I hope you understand and can and will take this to good use - good luck!
Reply
#10

Thank you so much, I'll rep you again tomorrow. Cheers!!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)