[Tutorial] How to make a inventory system.(ZCMD)
#1

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:
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;
}
Hope I heped you.
Reply
#2

Thanks its useful
Reply
#3

Quote:
Originally Posted by xMCx
Посмотреть сообщение
Thanks its useful
ThAnKs!
Reply
#4

More replies would be appreciated.
Reply
#5

That won't even compile. It's terrible if you're expecting people to learn something off of it.
Reply
#6

This is not "inventory system" its like tempory pocket when you rester/get kicked/.... lost connection to server everything you have its pfff gone ,if you have make it to be save that it that will be ok but this ... noone will use it
Reply
#7

You think it won't compile?
here you go:Click here and take a look

And please check before posting negative remarks.Thank you.

Quote:
Originally Posted by doreto
Посмотреть сообщение
This is not "inventory system" its like tempory pocket when you rester/get kicked/.... lost connection to server everything you have its pfff gone ,if you have make it to be save that it that will be ok but this ... noone will use it
I am not showing all the things,people have to create and add there own fuctions.
Reply
#8

Quote:
Originally Posted by doreto
Посмотреть сообщение
This is not "inventory system" its like tempory pocket when you rester/get kicked/.... lost connection to server everything you have its pfff gone ,if you have make it to be save that it that will be ok but this ... noone will use it
This isn't a saving tutorial... It's a tutorial on how to make a weapon inventory system
Reply
#9

Quote:
Originally Posted by [ABK]Antonio
Посмотреть сообщение
This isn't a saving tutorial... It's a tutorial on how to make a weapon inventory system
define your meaning of word : inventory


" Inventory is word wich mean storing something on place" - wikipedia
Reply
#10

Quote:
Originally Posted by doreto
Посмотреть сообщение
define your meaning of word : inventory


" Inventory is word wich mean storing something on place" - wikipedia
....You can't be serious. That's exactly what's being done. He's storing a weapon into a variable then removing it from the player. Then the player can take it back when they want. It's not hard to add a saving system yourself into it. Making a tutorial with a saving system hinders you (unless it's a tutorial on something that it's really needed or the saving system itself). It can be more confusing for newer players to see a saving system in there... Also, there's plenty of tutorials on the saving system of your choice.

I don't understand the problem.

Quote:
Originally Posted by leonardo1434
Посмотреть сообщение
this won't work properly.
I believe I already stated that...
Reply


Forum Jump:


Users browsing this thread: 6 Guest(s)