Random fish names
#1

Hello! I've created a stock to store fish names at random, along with a /fish command that should check whether fish name 'linesnap' is chosen - and if it is - display a message to show the players line has snapped.
Unfortunately, the code only calls the line snap message and doesn't choose any other fish at random.
If I remove the linesnap check in the /fish command it works, but I need it this way.
I'm guessing the code below checks if "LineSnap" exists in the actual stock rather than what it generated at random.
How to change it so the code checks whether "LineSnap" is called at random?

Код:
stock FishName()
{
	new name[20];
	switch(random(6))
	{
    	case 0: name = "LineSnap"; // here is what breaks fishing line
    	case 1: name = "Trout";
    	case 2: name = "Shark";
    	case 3: name = "Tuna";
    	case 4: name = "Flounder";
    	case 5: name = "Sea Bass";
	}
	return name;
}
Код:
forward FishingTimer(playerid);
public FishingTimer(playerid)
{
	if(PlayerFishing[playerid] > 0)
	{
	 	new string[128];
		PlayerFishing[playerid] = 0;
	    TogglePlayerControllable(playerid, 1);
	    
	    if(strfind(FishName(), "LineSnap")) // And here is what fucks up the random fishes. Always shows line snapped now
	    {
			format(string, sizeof(string), "%s's rod line has snapped!", GetName(playerid));
			SendActionMessage(string);
			return 1;
	    }
	    else
	    {
	    	format(string, sizeof(string), ""COLOR_CORNSILK"You have caught a fish - %s!", FishName());
	    	SendClientMessage(playerid, -1, string);
	    }
	}
	return 1;
}
Reply
#2

Use this https://pastebin.com/7eXvzTmJ
Reply
#3

Thanks man. Gave it a try and it does this:



https://imgur.com/a/60arO
Reply
#4

This is why the index would always be 0:
pawn Код:
new rFish = random(sizeof(rFish));
Instead do:
pawn Код:
new rFish = random(sizeof(FishName));
Also for the line snap, you can just check if rFish is 0 (or the index if you add more line snaps) instead of comparing the string.
Reply
#5

Thank you both so much! Wish I could rep twice in one day.
Changed strfind to strcmp instead as I think it's faster, right? (or at least serves better meaning here)
Код:
if(strcmp(FishName[rFish], "LineSnap") == 0)
Reply
#6

Quote:
Originally Posted by Abagail
Посмотреть сообщение
This is why the index would always be 0:
pawn Код:
new rFish = random(sizeof(rFish));
Instead do:
pawn Код:
new rFish = random(sizeof(FishName));
Also for the line snap, you can just check if rFish is 0 (or the index if you add more line snaps) instead of comparing the string.
Oops, oversight on my behalf, cheers.
Reply
#7

Another question about this:
How would I store the fish name in a string?

Код:
new FishSlot1[MAX_PLAYERS];
Код:
FishSlot1[playerid] = FishName[rFish];
Error:

Код:
C:\Users\Gamer\Desktop\Generation X\gamemodes\genx.pwn(717) : error 006: must be assigned to an array
Reply
#8

Quote:
Originally Posted by DevBe
Посмотреть сообщение
Another question about this:
How would I store the fish name in a string?

Код:
new FishSlot1[MAX_PLAYERS];
Код:
FishSlot1[playerid] = FishName[rFish];
Error:

Код:
C:\Users\Gamer\Desktop\Generation X\gamemodes\genx.pwn(717) : error 006: must be assigned to an array
https://pastebin.com/raw/JSxkgcEB
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)