String not complete
#1

I have a fishing timer, but when I catch a Sea Bass it only shows it as "Sea B" or "Floun" (for Flounder) when I type /inventory.

Код:
new FishName[][] =
{
    {"LineSnap"},
    {"Trout"},
    {"Shark"},
    {"Tuna"},
    {"Flounder"},
    {"Sea Bass"}
};
Код:
forward public FishingTimer(playerid);
public FishingTimer(playerid)
{
    if(PlayerFishing[playerid] > 0)
    {
        new string[128];
        PlayerFishing[playerid] = 0;
        TogglePlayerControllable(playerid, 1);

        new rFish = random(sizeof(FishName));
        new randSize = randomEx(5, 118);
        if(strcmp(FishName[rFish], "LineSnap") == 0) // Line broken
        {
            format(string, sizeof(string), "%s's rod line has snapped!", GetName(playerid));
            SendActionMessage(string);
            return 1;
        }
        else
        {
        	if(strcmp(Player[playerid][FishSlot1], "None") == 0)
        	{
				Player[playerid][FishSize1] = randSize;
        		format(Player[playerid][FishSlot1], sizeof(FishName), "%s", FishName[rFish]);
			}
			else
			{
			    Player[playerid][FishSize2] = randSize;
				format(Player[playerid][FishSlot2], sizeof(FishName), "%s", FishName[rFish]);
			}
			format(string, sizeof(string), "You have caught a %dlb %s!", randSize, FishName[rFish]);
			SendClientMessage(playerid, -1, string);
        }
    }
    return 1;
}
Код:
CMD:inventory(playerid, params[])
{
	if(Player[playerid][IsLoggedIn] == false) return 0;

	new string[250];
    SendClientMessage(playerid, -1, ""COLOR_GREY"-- Inventory --");
 	format(string, sizeof(string), ""COLOR_WHITE"(Cash: $%d) (Lighter: %d percent) (Cigarettes: %d)", GetCash(playerid), Player[playerid][Lighter], Player[playerid][Cigs]);
 	format(string, sizeof(string), ""COLOR_WHITE"(Fish Slot 1: %dlb %s) (Fish Slot 2: %dlb %s)", Player[playerid][FishSize1], Player[playerid][FishSlot1], Player[playerid][FishSize2], Player[playerid][FishSlot2]);
	SendClientMessage(playerid, -1, string);
	return 1;
}
Reply
#2

Show us the line where you defined FishSlot1 and FishSlot2
Reply
#3

pawn Код:
format(Player[playerid][FishSlot1], sizeof(FishName), "%s", FishName[rFish]);

format(Player[playerid][FishSlot2], sizeof(FishName), "%s", FishName[rFish]);
You use as second parameter (length) the number of elements in the 1st dimension so this means you have 6 fishes; thus 6 length. The correct would be:
pawn Код:
sizeof FishName[]
to read the size of the 2nd dimension. This is a good way to use it for the size of FishSlot1 and FishSlot2 as well in case you want to add more fishes with more characters and you won't have to change the size on those two manually every time.

Look for strcpy for copying strings, format is slower.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)