SA-MP Forums Archive
[Tutorial] Inventory System (new.pwn) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Inventory System (new.pwn) (/showthread.php?tid=644656)



Inventory System (new.pwn) - Adain - 11.11.2017

Basic Inventory On Dialogs

Hello there! My previous tutorial was really awful, and I don't promise that this will be better. But I try to correct my mistakes as much as I can.

So, The reason why I DO NOT recommend u to use this code:

- It's absolutely on dialog, without any textdraw.
- This code is a bit outdated.


The reason why I DO recommend u to use this code:

- This code is very useful for absolutely new.pwn (For test, after that u can modify it or re-write on textdraws)
- Some dayz servers use this code



Tutorial contain:
- System of Registration/Login and Saving account by using Dini.
- System of Inventory
- System of Hunger and Thirst
- Screenshots
- Archive with Includes and Plugins

How do it look like
https://imgur.com/a/gr6JI







To all includes
PHP Code:
#include <a_samp> // Include Basic Samp Functions
#include <dini> // Our read/write (also u can use y_ini)
#include <streamer> // Use streamer instead of standard CreateObject (streamer for loot) 
After that make defines of our dialogs:
PHP Code:
#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#define MAX_HUNGER_AMOUNT 3000 // Hunger Stat
#define MAX_THIRST_AMOUNT 3600 // Thirsty Stat
#define COLOR_GREY 0xAFAFAFAA
#define Dialog_Inventory 3 // Inventory Dialog
#define Dialog_Choose 5 // Use/Drop/Info Dialog
#define Dialog_TakeInv 6 // 
To all news we need to add variables
PHP Code:
new total_vehicles_from_files=3000// for our loot system (It will use LoadStaticVehiclesFromFile)
new backpack[MAX_PLAYERS];
new 
file128 ]; // Using for our file ( format( file, sizeof( file ), "Users/%s.ini", GetName(playerid)); ) 
PHP Code:
#define MAX_OBJ 10000 // Max obj 
#define INVNUMBERS 6 // up this number to make more items
new PlayerAdminMassage[MAX_PLAYERS][INVNUMBERS];
new 
playermassagetoadmin[MAX_PLAYERS]; 
Add enum of PlayerInfo, and PlayerInv
PHP Code:
enum pInfo
{
    
pPass// Player Password
    
pAdmin,
    
pHungry// Hunger stat
    
pThirsty// Thirst stat
    
pPack// Player Backpack
    
pSlots // Player Slots in Inventory
}
new 
PlayerInfo[MAX_PLAYERS][pInfo];
enum wInfo //weapon slots info
{
    
wSlot0,
    
wSlot1,
    
wSlot2,
    
wSlot3,
    
wSlot4,
    
wSlot5,
    
wSlot6,
    
wSlot7,
    
wSlot8,
    
wSlot9,
    
wSlot10,
    
wSlot11,
    
wSlot12,
}
new 
Weapon[500][wInfo];
enum dInvEnum
{
Float:ObjPos[3], // Object pos in map
    
ObjID// Object ID
    
ObjData // Object data info for dialog_choose -> info
};
new 
PlayerInv[MAX_PLAYERS][INVNUMBERS]; // Use for giving player loot (for example PlayerInv[playerid][3] = 2; - we give player Bean Can x2 ) 
After that we need to create arrays which will include information about Name of items, object ID's, and what is it for (dialog_choose -> info)
PHP Code:
new InvNames[INVNUMBERS][] = // Names of items in inventory (I also recommend to write down object id near the name)
//2040 iao?iiu
    
"Empty"//1581
    
"Dry Food",//2663
    
"Bean Can",//1666
    
"Sprunk",//1546
    
"Roast Meat",//1546
    
"Alice Backpack"// 3026
};
new 
InvObjects[INVNUMBERS] = // When u'll drop items it will use this ID's.
{
    
1581//empty
    
2663//
    
1666//bean
    
1546//Sprunk
    
2806//meat
    //backpacks (for instance)
    
3026
};
enum subinfo // Give information about items for example ( dialogmsgbox ) - Dry Food - Up your hunger stat
{
    
iD_sub[64],//noaouy
    
iD_text[256]//Iacaaiea
};
new 
InfoSub[INVNUMBERS][subinfo] = {
    {
"Empty""Empty."},
    {
"Dry Food""Up your hunger stat"},
    {
"Bean Can""Up your hunger stat"},
    {
"Sprunk""Up your thirsty stat"},
    {
"Roast Meat""Up your hunger stat"},
    {
"Alice BackPack""You have more slots for items (loot)"}
};
new 
dInvData[MAX_OBJ][dInvEnum]; 
Go to the end of your mode and put this stock

PHP Code:
stock GetName(playerid// This stock more better than always use GetPlayerName
{
    new 
name32 ]; // array which write down player nickname
    
GetPlayerName(playeridnamesizeofname )); // Get player name
    
return name// return this name for %s


Quick Registration/Login System

public OnPlayerConnect(playerid) // When Player connect
PHP Code:
formatfilesizeoffile ), "Users/%s.ini"GetName(playerid)); // Use format for getting player file. For example Mr_Bean.ini
    
if(dini_Exists(file)) // If player file exist show him dialog of login
    
{
        new 
string[128];
        
format(string,sizeof(string),"Hello %s.\nWrite down you pass below:",GetName(playerid)); // Get Player Name and show it in dialog
          
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_INPUT,"Log in",string,"Enter","Quit");
    }
    else 
// If else - Player file not exist show him dialog of register
    
{
        new 
string[128];
        
format(string,sizeof(string),"Write down you pass below:",GetName(playerid));// Get Player Name and show it in dialog
         
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_INPUT,"Registration",string,"Register","Quit");
    } 

public OnPlayerDialogResponse
PHP Code:
switch( dialogid )
    {
        case 
DIALOG_REGISTER// Register dialog
        
{
            if (!
response) return Kick(playerid); // If player click 'Esc' or Quit button - kick him
            
if(response// If Player click 'Enter' or Register button - do next step
            
{
                if(!
strlen(inputtext)) {new string[128];format(string,sizeof(string),"Incorrect pass type, make new pass:");ShowPlayerDialog(playeridDIALOG_REGISTER
DIALOG_STYLE_INPUT"Register",string,"Register","Quit");} // If the line in dialog is empty show player this dialog again with message
                
else // If the line in dialog NOT empty do next step
                
{
                
formatfilesizeoffile ), "Users/%s.ini"GetName(playerid)); // Get Player Name and path to our file
                
dini_Createfile ); // Dini create file in folder scriptfiles/Users/%s.ini
                
dini_Setfile"Password"inputtext); // In this file write down player new password entered in dialog of register
                
dini_IntSetfile"Admin"); // Write down other PlayerInfo stat
                
dini_IntSetfile"Pack");
                
dini_IntSetfile"Slots");
                
dini_IntSetfile"Hungry");
                
dini_IntSetfile"Thirsty");
                        
PlayerInfoplayerid ][ pHungry ] = MAX_HUNGER_AMOUNT// After register give player full amount of Hunger
                        
PlayerInfoplayerid ][ pThirsty ] = MAX_THIRST_AMOUNT;
                        
PlayerInfo[playerid][pPack] = 1;
                
PlayerInfo[playerid][pSlots] = 3;// Give player 3 slots for items ('cuz other string is items )
                
PlayerInv[playerid][1] = 1// 1 item - Dry Food x1
                
PlayerInv[playerid][2] = 1// 2 item - Bean Can x1
                
PlayerInv[playerid][3] = 1// 3 item - Sprunk x1
                //Spawn(playerid);
                
}
            }
        }
        case 
DIALOG_LOGIN// Login dialog
        
{
            if ( !
response ) return Kick playerid ); // If player click 'Esc' or Quit button - kick him
            
if( response // If Player click 'Enter' or Login button - do next step
            
{
                new 
pass256 ]; // Create array to get player pass
                
formatfilesizeoffile ), "Users/%s.ini"GetName(playerid)); // Get player path to fil
                
formatpasssizeofpass ), "%s"dini_Get(file"Password")); // array 'pass' will contain info about Password from player file
                //new lenght = strlen(inputtext); 
                
if(strcmp(inputtextpass) == 0// If inputtext = Player Password from file - setup players pInfo stats
                
{
                               
PlayerInfoplayerid ][ pAdmin ] = dini_Intfile"Admin");
                
PlayerInfoplayerid ][ pPack ] = dini_Intfile"Pack");
                
PlayerInfoplayerid ][ pSlots ] = dini_Intfile"Slots");
                
PlayerInfoplayerid ][ pHungry ] = dini_Intfile"Hungry");
                
PlayerInfoplayerid ][ pThirsty ] = dini_Intfile"Thirsty");
                    for(new 
i=0;i<INVNUMBERS;i++) // For every INVNUMBERS slots get info about inventory
                
{
                    new 
idstr[256]/*, ammostr[128]*/;
                    
formatfilesizeoffile ), "Users/%s.ini"GetName(playerid)); // Get file path
                    
format(idstrsizeof(idstr), "id%d"i);
                    
PlayerInv[playerid][i] = dini_Intfileidstr ); //Load player invetory from file
                    //dini_Int(file, idstr, PlayerInv[playerid][i]);
                    //Player[playerid][pSlots] = i;
                
}
                }
                else 
// If inputtext is not equal to Player Password from file - show this dialog again
                
{
                    
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_INPUT,"Log In","Incorrect pass!!!","Enter","Quit");
                }
                return 
1;
            }
        }
    } 

public OnPlayerDisconnect - when player disconnect
PHP Code:
format(filesizeof(file), "Users/%s.ini"GetName(playerid)); // Get file path
    
if( dini_Existsfile ) ) // If player file exist write down his new stats to file
    
{
        
dini_IntSetfile"Admin"PlayerInfoplayerid ][ pAdmin ]);
        
dini_IntSetfile"Pack"PlayerInfo[playerid][pPack]);
        
dini_IntSetfile"Slots"PlayerInfo[playerid][pSlots]);
        
        for(new 
i=0;i<INVNUMBERS;i++) // For every slots get info about inventory and write down it to file
        
{
        new 
idstr[256];
        
format(idstrsizeof(idstr), "id%d",i); // For example id1 - it's 'Dry Food', id2 - 'Bean Can'
        
dini_IntSetfileidstrPlayerInv[playerid][i]); // Write down it to every slots
        
}
    } 
We have created Reg/Log system


Inventory (Picking up/Dropping objects)

public OnPlayerKeyStateChange
PHP Code:
if(newkeys == KEY_YES// If player click 'Y' button - Show Player Inventory
    
{
        
Inventory(playerid);//open inventory
        
return 1;
    }
    
    if(
newkeys == KEY_CROUCH// If Player click 'C' button - Show Player Loot point
    
{
        
Equipment(playerid); // Player need to be near loot point to use this
        
return 1;
    } 
Go again to the end of the mode and add this stocks

PHP Code:
stock Equipment(playerid// Loot point
{
    if(
GetPlayerState(playerid) != PLAYER_STATE_ONFOOT) return 1;
    new 
total_vehicles_from_files+1;
    new 
str[1024], listitems[1024], adm=0;
    for(new 
0total_vehicles_from_filesa++) // total_vehicles_from_files it's our object loaded from file
    
{
        if(
IsPlayerInRangeOfPoint(playerid1.8dInvData[a][ObjPos][0], dInvData[a][ObjPos][1], dInvData[a][ObjPos][2])) // If is player near the loot
        
{
            
a;
            
PlayerAdminMassage[playerid][adm] = f// Get info
            
adm ++;
            
format(strsizeof(str), "%s\n"InvNames[dInvData[f][ObjData]]); // Get Names of object 
            
if(dInvData[f][ObjData] > 0strins(listitemsstrstrlen(listitems), strlen(str)); // And put it for dialog TakeInv
        
}
    }
    if(
total_vehicles_from_files) return 1;
    
ShowPlayerDialog(playerid,Dialog_TakeInv,DIALOG_STYLE_LIST,"Equipment",listitems,"Take","Quit"); // Show Player TakeInv dialog
    
return 1;
}
stock Inventory(playerid// Inventory (main core)
{
   new 
str[1024], slotstr[1024];
    new 
listitems[1024], adm=0;
    for(new 
slot;slot<INVNUMBERS;slot++) // For every slots of INVNUMBERS
    
{
        if(
PlayerInv[playerid][slot] > && slot != 0)  // If player inventory is not empty
        
{
            
PlayerAdminMassage[playerid][adm] = slot;
            
adm ++;
            
format(strsizeof(str), "[%d]\t%s\n"PlayerInv[playerid][slot],InvNames[slot]); // Get info amount - name (For instance [1] - Bean Can)
            
strins(listitemsstrstrlen(listitems), strlen(str));
        }
    }
//    if(PlayerInfo[playerid][pPack] == 0) format(slotstr,sizeof(slotstr),"No BackPack [%d/%d]",PlayerInfo[playerid][pSlots],PlayerInfo[playerid][pPack]*10);
    
if(PlayerInfo[playerid][pPack] == 1format(slotstr,sizeof(slotstr),"No Backpack [%d/%d]",PlayerInfo[playerid][pSlots],PlayerInfo[playerid][pPack]*10);
    
ShowPlayerDialog(playerid,Dialog_Choose,DIALOG_STYLE_LIST,slotstr,listitems,"Choose","Quit"); // Show Player Inventory
    
return 1;
}
stock CreateDroppedInv(idFloat:gPosXFloat:gPosYFloat:gPosZ// When player drop items from his inventory
{
    if(
id == 0) return 1;
    new 
total_vehicles_from_files+1;
    for(new 
0total_vehicles_from_filesa++)
    {
        if(
dInvData[a][ObjPos][0] == 0.0// Object pos 0.0 will be use for respawning loot
        
{
            
a;
            break;
        }
    }
    if(
total_vehicles_from_files) return 1;
    
    
dInvData[f][ObjData] = id// Get information about object which we want to drop
    
dInvData[f][ObjPos][0] = gPosX// GetPlayerPos X - to drop near the player
    
dInvData[f][ObjPos][1] = gPosY// GetPlayerPos Y
    
dInvData[f][ObjPos][2] = gPosZ// GetPlayerPos Z
    
new x_l random(2);
    new 
y_l random(2);
    
//Use 'CreateDynamicObject' from streamer because standard is limited
    
dInvData[f][ObjID] = CreateDynamicObject(InvObjects[id], dInvData[f][ObjPos][0]+x_ldInvData[f][ObjPos][1]+y_ldInvData[f][ObjPos][2]-1.00.0360.0250.0);
    if(
id == 78SetDynamicObjectMaterial(dInvData[f][ObjID], 02060"cj_ammo""CJ_CANVAS2"0);
    
//printf("%d,%f",id,dInvData[f][ObjPos][0]);
    
return 1;
}
stock RemovePlayerWeapon(playeridweaponid)
{
    if(!
IsPlayerConnected(playerid) || weaponid || weaponid 50)
    return;
    new 
saveweapon[13], saveammo[13];
    for(new 
slot 0slot 13slot++)
    
GetPlayerWeaponData(playeridslotsaveweapon[slot], saveammo[slot]);
    
ServerResetPlayerWeapons(playerid);
    for(new 
slotslot 13slot++)
    {
        if(
saveweapon[slot] == weaponid || saveammo[slot] == 0)
        continue;
        
ServerGivePlayerWeapon(playeridsaveweapon[slot], saveammo[slot]);
    }
    
ServerGivePlayerWeapon(playerid01);
}
//
stock UseItem(playerid,itemid// Use item (Here's main core for adding new items etc.)
{
    if(
itemid == 1)//Dry Food
    
{
        new 
Float:health;
        
GetPlayerHealth(playerid,health);
        
SetPlayerHealth(playeridhealth+15);
        
PlayerInfo[playerid][pHungry] = MAX_HUNGER_AMOUNT;
        
PlayerInv[playerid][itemid]--;
        
PlayerInfo[playerid][pSlots] --;
        
SendClientMessage(playerid,0xA9A9A9ff,"* You have ate Dry Food");
    }
    if(
itemid == 2)//Bean can
    
{
        new 
Float:health;
        
GetPlayerHealth(playerid,health);
        
SetPlayerHealth(playerid,health+5);
        
PlayerInfo[playerid][pHungry] = MAX_HUNGER_AMOUNT;
        
PlayerInv[playerid][itemid]--;
        
PlayerInfo[playerid][pSlots] --;
        
SendClientMessage(playerid,0xA9A9A9ff,"* You have ate Bean Can");
    }
    if(
itemid == 3)//Sprunk
    
{
        new 
Float:health;
        
GetPlayerHealth(playerid,health);
        
SetPlayerHealth(playerid,health+2.0);
        
PlayerInfo[playerid][pThirsty] = MAX_THIRST_AMOUNT;
        
PlayerInv[playerid][itemid]--;
        
PlayerInfo[playerid][pSlots] --;
        
SendClientMessage(playerid,0xA9A9A9ff,"* You have drunk Sprunk");
    }
    if(
itemid == 4)//Roast Meat
    
{
        new 
Float:health;
        
GetPlayerHealth(playerid,health);
        
SetPlayerHealth(playerid,health+20);
        
PlayerInfo[playerid][pHungry] = MAX_HUNGER_AMOUNT;
        
PlayerInv[playerid][itemid]--;
        
PlayerInfo[playerid][pSlots] --;
        
SendClientMessage(playerid,0xA9A9A9ff,"* You have ate Roast Meat");
    }
        return 
1;

public OnDialogResponse

PHP Code:
if(dialogid == Dialog_Inventory// Inventory Dialog
    
{
        if(
response == 1)
        {
            if(
listitem == 0// Player click 'Use' - Use this item
            
{
                
UseItem(playerid,playermassagetoadmin[playerid]);
            }
            if(
listitem == 1// Player click 'Drop' - Drop this item near player
            
{
                if(
IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playeridCOLOR_GREY"You can't do this in car!"); // Forbid player drop 
item in vehicle
                
if(PlayerInv[playerid][playermassagetoadmin[playerid]] == 0) return 1;
                new 
str[128],Float:pos[3]; // new array for format and player pos
                
GetPlayerPos(playerid,pos[0],pos[1],pos[2]); // Get info about player position
                
CreateDroppedInv(playermassagetoadmin[playerid],pos[0],pos[1],pos[2]); // Create items near player
                
format(str,sizeof(str),"{A9A9A9}* You have dropped %s from your inventory",InvNames[playermassagetoadmin[playerid]]); 
                
PlayerInv[playerid][playermassagetoadmin[playerid]]--; // Remove this item from inventory
                
PlayerInfo[playerid][pSlots] --; // Remove 1 slots, because we have dropped 1 item ( 1 item - 1 slot )
                
SendClientMessage(playerid,0xFF0000FF,str);
                
total_vehicles_from_files++; // +1 to world loot object
            
}
            if(
listitem == 2// Player click 'Info' - Show him dialog with info about this item
            
{
                new 
string[512], Desc_sub[512], nazvanie_one[64], Name_sub[64];
                
strmid(Name_subInfoSub[playermassagetoadmin[playerid]][iD_sub], 0strlen(InfoSub[playermassagetoadmin[playerid]][iD_sub]), 255);
                
strmid(Desc_subInfoSub[playermassagetoadmin[playerid]][iD_text], 0strlen(InfoSub[playermassagetoadmin[playerid]][iD_text]), 512);
                
format(nazvanie_onesizeof(nazvanie_one),"%s"Name_sub);
                
format(stringsizeof(string), "%s"Desc_sub);
                
ShowPlayerDialog(playerid,465,DIALOG_STYLE_MSGBOX,nazvanie_one,string,"OK","");
            }
        }
        return 
1;
    }
    if(
dialogid == Dialog_Choose)
    {
        if(
response == 1)
        {
            new 
nazvanie_one[64];
            
playermassagetoadmin[playerid] = PlayerAdminMassage[playerid][listitem];
            
format(nazvanie_onesizeof(nazvanie_one),  "%s"InvNames[playermassagetoadmin[playerid]]);
            new 
listitems[] = "- Use\n- Drop\n- Info";
            
ShowPlayerDialog(playerid,Dialog_Inventory,DIALOG_STYLE_LIST,nazvanie_one,listitems,"Choose","Back");
        }
        if(
response == 0)
        {
        }
        return 
1;
    }
    if(
dialogid == Dialog_TakeInv)
    {
        
//new slots = PlayerInfo[playerid][pPack]*10-PlayerInfo[playerid][pSlots];
        
playermassagetoadmin[playerid] = PlayerAdminMassage[playerid][listitem];
        if(
response == 1)
        {
            if(
dInvData[playermassagetoadmin[playerid]][ObjData] == 0) return SendClientMessage(playerid0xA9A9A9FF"* Sorry, sbs take this object");
            new 
buffer[120];
            
format(buffersizeof(buffer), "* %s now in your backpack."InvNames[dInvData[playermassagetoadmin[playerid]][ObjData]]);
                if(
PlayerInfo[playerid][pSlots]  >= PlayerInfo[playerid][pPack]*10) return SendClientMessage(playerid0xA9A9A9FF"* Your backpack is 
full, drop something."
);
                if(
PlayerInv[playerid][dInvData[playermassagetoadmin[playerid]][ObjData]] > 0PlayerInv[playerid][dInvData[playermassagetoadmin
[playerid]][ObjData]] +=1PlayerInfo[playerid][pSlots] ++;
                else 
PlayerInv[playerid][dInvData[playermassagetoadmin[playerid]][ObjData]] +=1PlayerInfo[playerid][pSlots] ++;
                
SendClientMessage(playerid0xA9A9A9FFbuffer);
            }
            
//DestroyDynamic3DTextLabel(loot[playermassagetoadmin[playerid]]);
            
total_vehicles_from_files--;
            
DestroyDynamicObject(dInvData[playermassagetoadmin[playerid]][ObjID]);
            
dInvData[playermassagetoadmin[playerid]][ObjPos][0] = 0.0;
            
dInvData[playermassagetoadmin[playerid]][ObjPos][1] = 0.0;
            
dInvData[playermassagetoadmin[playerid]][ObjPos][2] = 0.0;
            
dInvData[playermassagetoadmin[playerid]][ObjID] = -1;
            
dInvData[playermassagetoadmin[playerid]][ObjData] = 0;
            
Equipment(playerid);//Iiyou ioe?uoea
            
return 1;
        }
        } 

Hunger and Thirst System

Add to all forward

PHP Code:
forward ProcessAllPlayers(); // All player process
forward ProcessPlayerHunger(playerid); // Hunger
forward ProcessPlayerThirsty(playerid); // Thirst 
public OnPlayerGameModeInit

PHP Code:
SetTimer("ProcessAllPlayers",1000,1); // Timer with repeating every seconds 
Create this publics

PHP Code:
public ProcessPlayerHunger(playerid)
{
    
PlayerInfoplayerid ][ pHungry ]--; // every second -1 hunger stat
    
if(PlayerInfoplayerid ][ pHungry ] <= 0)// If player hunger stat <= 10 - kill player
    
{
    
SetPlayerHealth(playerid, -10);
    }
    return 
1;
}
public 
ProcessPlayerThirsty(playerid)
{
    
PlayerInfoplayerid ][ pThirsty ]--; // every second -1 thirst stat
    
if(PlayerInfoplayerid ][ pThirsty ] <= -10// If player thirst stat <= 10 - kill player
    
{
    
SetPlayerHealth(playerid, -10);
    }
    return 
1;
}
public 
ProcessAllPlayers()
{
    for (new 
0MAX_PLAYERSi++)
    {
        if (
PlayerInfo][ pLogged ] == true)
        {
        
            
ProcessPlayerHunger(i);
            
            
ProcessPlayerThirsty(i);
        }
    }
    return 
1;




Re: Inventory System (new.pwn) - Kane - 12.11.2017

Quote:

So, The reason why I DO NOT recommend u to use this code:

- It's absolutely on dialog, without any textdraw.
- This code is a bit outdated.
- This code is not written well.

So why release it?


Re: Inventory System (new.pwn) - Ponga - 12.11.2017

How can we add looting items?


Re: Inventory System (new.pwn) - Zeth - 12.11.2017

Deleting old thread because of negative comments and making a new one isn't a smart work boi!


Re: Inventory System (new.pwn) - Adain - 12.11.2017

Arthur Kane, because If you have played on different samp dayz server, it's the most popular inventory (on dialogs)
Debjit, I really don't care about negative comments, I make this tutorial for beginners, and this system is really useful. If u are not support my work, you can skip my threads.
Ponga ,if u want to add new items u need to do next steps (sry for my eng)

It will looks like that - https://imgur.com/a/ZDhLq

Find this
PHP Code:
#define INVNUMBERS 6 
and change from 6 to 7. Because if u are not change this it will cause multi-dimensional error

Find this
PHP Code:
new InvNames[INVNUMBERS][] =
{
    
"Empty",
    
"Dry Food",
    
"Bean Can",
    
"Sprunk",
    
"Roast Meat",
    
"Alice Backpack"
    'M4A1' 
// our new item
}; 
And after 'Alice Backpack create name of your item

Here you write the ID of Model(object) of item (In our case it's 356)
PHP Code:
new InvObjects[INVNUMBERS] =
{
    
1581,
    
2663,
    
1666,
    
1546,
    
2806,
    
3026,
    
356 // Object ID of our M4A1
}; 
After this u need to create info about this item, find this lines in your code

PHP Code:
new InfoSub[INVNUMBERS][subinfo] = {
    {
"Empty""Empty."},
    
//Еда и питье
    
{"Dry Food""Up your hunger stat"},
    {
"Bean Can""Up your hunger stat"},
    {
"Sprunk""Up your thirsty stat"},
    {
"Roast Meat""Up your hunger stat"},
    {
"Alice BackPack""You have more slots for items (loot)"},
    {
"M4A1","Use for protect yourself"// We add new info
}; 
Go to stock UseItem(playerid) and add the function of using this item

PHP Code:
if(itemid == 6)// m4a1
    
{
        
GivePlayerWeapon(playerid31500); // Give player m4a1
        
PlayerInv[playerid][itemid]--; // Remove from inventory
        
PlayerInfo[playerid][pSlots] --; // Remove 1 slot from inventory ('cause be use this item)
    




Re: Inventory System (new.pwn) - Eoussama - 12.11.2017

I discourage working with strings.


Re: Inventory System (new.pwn) - Janoz12 - 22.06.2018

And if I want to place an object directly on the ground for the user to look for it? that does not appear directly in the inventory but that you should look for it

Sorry to revive theme but I really need this system


Re: Inventory System (new.pwn) - CodeStyle175 - 22.06.2018

what is this thing?


Re: Inventory System (new.pwn) - Logic_ - 22.06.2018

A few critiques:

1. Use SQLite (Better than Dini and alternative to MySQL and INI file saving systems and NATIVE-LY implemented in SA-MP!!)
2. Use one array for all the object information and macros?

PHP Code:
#define        GetObjectName(%0)            \
            
gObjects[%0][E_OBJECT_NAME]
#define        GetObjectModelID(%0)        \
            
gObjects[%0][E_OBJECT_ID]
#define        GetObjectDescription(%0)    \
            
gObjects[%0][E_OBJECT_DESCRIPTION]
enum E_OBJECTS {
    
E_OBJECT_ID,
    
E_OBJECT_NAME[10],
    
E_OBEJCT_DESCRIPTION[100],
};
enum {
    
OBJECT_M4A1,
};
new 
gObjects[][E_OBJECTS] = {
    {
356,    "M4A1",        "The M4A1 is a fully automatic variant of the M4 carbine – a shorter and lighter variant of the M16."}
}; 



Re: Inventory System (new.pwn) - JasonRiggs - 22.06.2018

I guess this aint a tutorial but its some filterscript or smth..