14.09.2012, 15:25
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:
Hope I helped you.Tell me if anything goes wrong or I missed something.
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.
}
