08.09.2012, 14:45
(
Последний раз редактировалось TaLhA XIV; 08.09.2012 в 18:06.
)
Hello,
Welcome to my 5th tutorial which is on how to make a inventory system.
Here is the full code with all the explanation needed:
Hope I heped you.
Welcome to my 5th tutorial which is on how to make a inventory system.
Here is the full code with all the explanation needed:
pawn Код:
#include <a_samp>//you all know that.
#include <zcmd>//including the zcmd include in the script.
#if defined FILTERSCRIPT
#else
#endif
enum invInfo{
weaponname,//the variable which would store the weapon ids.
weaponammo//the variable which would store the weapon ammo.
}
new PlayerInfo[MAX_PLAYERS][invInfo];
forward Weapondata(playerid);//the forward the the public in the next line.
public Weapondata(playerid)//making a cmd for the next commands.
{
new string[200];//the variable which will store the text to send to the player.
{
PlayerInfo[playerid][weaponname] = GetPlayerWeapon(playerid);//this is used to store the players weapon id in the variable
PlayerInfo[playerid][weaponammo] = GetPlayerAmmo(playerid);//this is used to store the players weapon ammo in the variable
format(string,sizeof(string),"You have gun with id %i and %d ammo!",weaponname,weaponammo);//formating the message which will be sent to the player.
SendClientMessage(playerid,-1,string);//sending the formated message.
}
}
forward Storeweaponininv(playerid);//the forward the the public in the next line.
public Storeweaponininv(playerid)//making a cmd for the next commands.
{
new string[200];//the variable which will store the text to send to the player.
{
PlayerInfo[playerid][weaponname] = GetPlayerWeapon(playerid);//this is used to store the players weapon id in the variable "weaponname".
PlayerInfo[playerid][weaponammo] = GetPlayerAmmo(playerid);//this is used to store the players weapon ammo in the variable "weaponammo".
format(string,sizeof(string),"You have gun with id %i with %d ammo stored in your bag!",weaponname,weaponammo);//will format the message and store it in the variable "string".
SendClientMessage(playerid,-1,string);//this will send the text stored in the variable "string".
ResetPlayerWeapons(playerid);//this will remove player's weapon that was to be stored in the variables("weaponname""weaponammo")
}
}
forward takeweaponfrominv(playerid);//the forward the the public in the next line.
public takeweaponfrominv(playerid)//making a cmd for the next commands.
{
new string[200];//the variable which will store the text to send to the player.
format(string,sizeof(string),"You have taken gun with the id %i and %d ammo from the bag!",weaponname,weaponammo);//will format the message and store it in the variable "string".
SendClientMessage(playerid,-1,string);//this will send the text stored in the variable "string".
GivePlayerWeapon(playerid,weaponname,weaponammo);//this will give player the same weapon with the same ammo.
PlayerInfo[playerid][weaponname] = 0;
PlayerInfo[playerid][weaponammo] = 0;
}
CMD:weapondata(playerid,params[])//cmd to check the weapon data.
{
Weapondata(playerid);//sending the data we collected above.
return 1;
}
CMD:storewininv(playerid,params[])//the cmd to store the gun in the inventory.
{
Storeweaponininv(playerid);//storing all the data of the gun in a variable and removing player's weapon.
return 1;
}
CMD:takewfrinv(playerid,params[])//cmd to take the gun out of the inventory.
{
if(PlayerInfo[playerid][weaponammo] == 0 || PlayerInfo[playerid][weaponname] == 0)return SendClientMessage(playerid,-1,"You do not have a weapon in you bag!");//this will check that if he has a weapon in the bag,if he does not have any weapon,it will give him an error message.
takeweaponfrominv(playerid);//this will get all the stored information and give the player back his weapon with the same ammo.
return 1;
}