[Tutorial] How to make a simple fishing system.
#1

Hello.
Welcome to my 6th tutorial.In this tutorial you will learn that how to make a simple fishing system.

Okay here is the full code with every explanation you need:
pawn Code:
#include <a_samp>//all know that what it is.
#include <zcmd>//including zcmd include in the script.

new fishes[MAX_PLAYERS];//the variable which will store player's fishes.
new baits[MAX_PLAYERS];//the variables which will store player's baits.

CMD:checkbaits(playerid, params[])//cmd to check player's baits.
{
    new string[128];//this will store the text of the message which would be sended to the player.
    format(string,sizeof(string),"You have %d baits!",baits);//formating the message which would send the player the information of how many baits he have.
    SendClientMessage(playerid,-1,string);//sending the message we formatted.
    return 1;
}
CMD:checkfishes(playerid, params[])//cmd to check player's fishes.
{
    new string[128];//this will store the text of the message which would be sended to the player.
    format(string,sizeof(string),"You have %d fishes!",fishes);//formating the message which would send the player the information of how many fishes he have.
    SendClientMessage(playerid,-1,string);//will send his the message.
    return 1;
}
CMD:fish(playerid, params[])//cmd to fish.
{
    if(baits[playerid] > 1)//this will check that if the player has more than 1 baits,if he does not have it,it will send him an error message.
    {
        SetTimerEx("fishing", 10000, 0, "i",playerid);//this will set a player timer,this is to make it look good.A player would fish once in a 10 sec.(10000 = 10 sec.)
        TogglePlayerControllable(playerid,0);//will freesze the player in one place.
    }
    SendClientMessage(playerid,-1,"You have no baits!");//sending the error message we talked before.
    return 1;
}
CMD:sellfish(playerid, params[])//the cmd to sell the fishes we have.
{
    if(fishes[playerid] > 1)//this will check that if the player has enough fishes to be selled.If he do not have that much fishes he will send him an error message.
    {
        new string[128];//this will store the text of the message which would be sended to the player.
        format(string,sizeof(string),"You have selled your fishes and got $%d",fishes[playerid]);//formating the message which would send the player the information of how many cash he got after selling his fishes.(1 fish = $1)
        GivePlayerMoney(playerid,fishes[playerid]);//this will give the player money.(1 fish = $1)
        SendClientMessage(playerid,-1,string);//will send the formated message.
        fishes[playerid] = 0;//will reset player's fishes back to 0,meaning that the player will have no fishes now.
    }
    SendClientMessage(playerid,-1,"You have no fishes to sell!");//sending the error message.
    return 1;
}
//============= timer we made in the cmd /fish =============//
forward fishing(playerid);
public fishing(playerid)
{
    new str[128];//this will store the text of the message which would be sended to the player.
    switch( random( 3 ) )//this will switch the messages everytime making it random everytime player uses /fish.
        {
            case 0: format( str, 128, "You caught a starfish", str );//the first messages to be switced.
            case 1: format( str, 128, "You caught a turtle", str );//the second messages to be switced.
            case 2: format( str, 128, "You caught a shark", str );//the third messages to be switced.
        }
    SendClientMessage(playerid,-1,str);//sending the random message.
    TogglePlayerControllable(playerid,1);//this will unfreeze the player.
    fishes[playerid] += 1;//this will increase player's fishes increasing it to 1.
    baits[playerid] -= 1;//this will minus player's bait.
}
Hope I helped you.Tell me if anything goes wrong or I missed something.
Reply
#2

You could of explained it better, IMO.
Reply
#3

thanks really useful
Reply
#4

ThAnKs!
Reply
#5

Great, but more explanation could be useful for us .
Reply
#6

Hmm,ThAnKs.I wanted you to please list down the parts that need explanation,I would edit them.
Reply
#7

Your code isnt complete..you should check if player is on a boat in water..
Reply
#8

No that is a additional function so I did not added it,and one more thing that I did not added ranges cause I don't know what places people want for the fishing place,people can make their own edited codes.
Reply
#9

Cool! helped me alot.
Reply
#10

Quote:
Originally Posted by TaLhA XIV
View Post
No that is a additional function so I did not added it,and one more thing that I did not added ranges cause I don't know what places people want for the fishing place,people can make their own edited codes.
It is not an additional function. Think about it. No one can fish on land..Can you?I don't think so.
Make it a little realistic..Search ****** if theres a IsPlayerInWater function cause i am pretty sure it is..use that + GetPlayerVehicleID to check if he is in water+in a boat..
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)