23.08.2014, 03:50
Hello guys, today i write tutorial how to make inventory simple textdraw use include mSelection
Include https://sampforum.blast.hk/showthread.php?tid=407045 ( you can learn how to use it)
Ok start
first you need include
Step 1efine and new
Ok now we make stock ShowInventory , AddItem , RemoveItem , SaveInventory , LoadInventory , ResetInventory
* Save and Load
* Show, Add , Remove and Reset
How to use Item
it i test use pickup health
* command test
Finish All code
Pic :
Include https://sampforum.blast.hk/showthread.php?tid=407045 ( you can learn how to use it)
Ok start
first you need include
pawn Код:
#include <zcmd> //Zeex
#include <dini>//to save inventory by DracoBlue
#include <mSelection> by d0
pawn Код:
#define INVENTORY_MENU 1 //1 is extraid mslection
enum inv
{
iSlot[20],// inventory i use 20 slot for player
}
new InvInfo[MAX_PLAYERS][inv] // Inventory player info
* Save and Load
pawn Код:
stock SaveInventory(playerid)/// Use Dini include .
{
new file[64];
format(file, sizeof(file), "Inventory/%s.ini", GetName(playerid));// forlder Inventory
if(!dini_Exists(file)) dini_Create(file);
dini_IntSet(file, "Slot0", InvInfo[playerid][iSlot][0]);// Set value Item in slot 0
dini_IntSet(file, "Slot1", InvInfo[playerid][iSlot][1]);// Set value Item in slot 1
dini_IntSet(file, "Slot2", InvInfo[playerid][iSlot][2]);
dini_IntSet(file, "Slot3", InvInfo[playerid][iSlot][3]);
dini_IntSet(file, "Slot4", InvInfo[playerid][iSlot][4]);
dini_IntSet(file, "Slot5", InvInfo[playerid][iSlot][5]);
dini_IntSet(file, "Slot6", InvInfo[playerid][iSlot][6]);
dini_IntSet(file, "Slot7", InvInfo[playerid][iSlot][7]);
dini_IntSet(file, "Slot8", InvInfo[playerid][iSlot][8]);
dini_IntSet(file, "Slot9", InvInfo[playerid][iSlot][9]);
dini_IntSet(file, "Slot10", InvInfo[playerid][iSlot][10]);
dini_IntSet(file, "Slot11", InvInfo[playerid][iSlot][11]);
dini_IntSet(file, "Slot12", InvInfo[playerid][iSlot][12]);
dini_IntSet(file, "Slot13", InvInfo[playerid][iSlot][13]);
dini_IntSet(file, "Slot14", InvInfo[playerid][iSlot][14]);
dini_IntSet(file, "Slot15", InvInfo[playerid][iSlot][15]);
dini_IntSet(file, "Slot16", InvInfo[playerid][iSlot][16]);
dini_IntSet(file, "Slot17", InvInfo[playerid][iSlot][17]);
dini_IntSet(file, "Slot18", InvInfo[playerid][iSlot][18]);
dini_IntSet(file, "Slot19", InvInfo[playerid][iSlot][19]);
}
stock LoadInventory(playerid)
{
new file[64];
format(file, sizeof(file), "Inventory/%s.ini", GetName(playerid));
InvInfo[playerid][iSlot][0] = dini_Int(file,"Slot0"); // Load Item in Slot 0
InvInfo[playerid][iSlot][1] = dini_Int(file,"Slot1");// Load Item in Slot 1
InvInfo[playerid][iSlot][2] = dini_Int(file,"Slot2");
InvInfo[playerid][iSlot][3] = dini_Int(file,"Slot3");
InvInfo[playerid][iSlot][4] = dini_Int(file,"Slot4");
InvInfo[playerid][iSlot][5] = dini_Int(file,"Slot5");
InvInfo[playerid][iSlot][6] = dini_Int(file,"Slot6");
InvInfo[playerid][iSlot][7] = dini_Int(file,"Slot7");
InvInfo[playerid][iSlot][8] = dini_Int(file,"Slot8");
InvInfo[playerid][iSlot][9] = dini_Int(file,"Slot9");
InvInfo[playerid][iSlot][10] = dini_Int(file,"Slot10");
InvInfo[playerid][iSlot][11] = dini_Int(file,"Slot11");
InvInfo[playerid][iSlot][12] = dini_Int(file,"Slot12");
InvInfo[playerid][iSlot][13] = dini_Int(file,"Slot13");
InvInfo[playerid][iSlot][14] = dini_Int(file,"Slot14");
InvInfo[playerid][iSlot][15] = dini_Int(file,"Slot15");
InvInfo[playerid][iSlot][16] = dini_Int(file,"Slot16");
InvInfo[playerid][iSlot][17] = dini_Int(file,"Slot17");
InvInfo[playerid][iSlot][18] = dini_Int(file,"Slot18");
InvInfo[playerid][iSlot][19] = dini_Int(file,"Slot19");
}
stock GetName(playerid)// GetPlayer Name
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
return name;
}
pawn Код:
stock ShowInventory(playerid)
{
new iteminv[20];//20 item 0->19
for(new i = 0; i < 20;i++)// Get all form 0 to 19
{
iteminv[i] = InvInfo[playerid][iSlot][i];// Check item in slot
if(InvInfo[playerid][iSlot][i] == 0) // if slot i no have item . it will return model '!'
{
iteminv[i] = 1239;// 1239 is model '!'
}
}
ShowModelSelectionMenuEx(playerid, iteminv,20, "Inventory",INVENTORY_MENU, 0.0, 0.0,0.0);//mSelection
return 1;
}
stock AddItem(playerid,modelid)
{
for(new i = 0;i<20;i++)// get all form 0 to 19 = 20 item
{
if(InvInfo[playerid][iSlot][i] == 0) // slot i no have item . It will add item to this slot
{
InvInfo[playerid][iSlot][i] = modelid;// modelid = model item will rewive
break;// stop get when finish add item
}
}
return 1;
}
stock RemoveItem(playerid,modelid)
{
for(new i = 0;i<20;i++)// Get all form 0 to 19 = 20 slot
{
if(InvInfo[playerid][iSlot][i] == modelid) // if slot i have item model == modelid
{
InvInfo[playerid][iSlot][i] = 0; //remove item in this slot
break;// stop
}
}
return 1;
}
stock ResetInventory(playerid)
{
for(new i = 1 ; i <20;i++) InvInfo[playerid][iSlot][i] = 0;// get all slot form 0 to 19 and set slot item to 0
return 1;
}
it i test use pickup health
pawn Код:
public OnPlayerModelSelectionEx(playerid, response, extraid, modelid)
{
if(extraid == INVENTORY_MENU)
{
if(response)
{
if(modelid == 1239) return SendClientMessage(playerid,-1,"This slot no have item ");
if(modelid == 1240)// test item pickup health model 1240
{
SendClientMessage(playerid,-1,"Health = 100");
SetPlayerHealth(playerid,100);
RemoveItem(playerid,modelid);//remove this item
}
}
else SendClientMessage(playerid, 0xFF0000FF, "Close Inventory");
}
return 1;
}
pawn Код:
CMD:inventory(playerid,params[])
{
ShowInventory(playerid);// show inventory for player
return 1;
}
CMD:additem(playerid,params[])
{
AddItem(playerid,1240);// add item model 1240 to inventory
return 1;
}
pawn Код:
//INVENTORY TEXTDRAW
#include <a_samp>
#include <dini>
#include <zcmd>
#include <mSelection>
#define INVENTORY_MENU 1
enum inv
{
MSlot,
iSlot[20]
}
new InvInfo[MAX_PLAYERS][inv];
CMD:inventory(playerid,params[])
{
ShowInventory(playerid);
return 1;
}
CMD:add(playerid,params[])
{
AddItem(playerid,1240);
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
SaveInventory(playerid);
return 1;
}
public OnPlayerSpawn(playerid)
{
LoadInventory(playerid);
return 1;
}
public OnPlayerDeath(playerid, killerid, reason)
{
return 1;
}
public OnPlayerModelSelectionEx(playerid, response, extraid, modelid)
{
if(extraid == INVENTORY_MENU)
{
if(response)
{
if(modelid == 1239) return SendClientMessage(playerid,-1,"This slot no have item ");
if(modelid == 1240)
{
SendClientMessage(playerid,-1,"Health = 100");
SetPlayerHealth(playerid,100);
RemoveItem(playerid,modelid);
}
SendClientMessage(playerid,-1,"Inventory");
}
else SendClientMessage(playerid, 0xFF0000FF, "Close Inventory");
}
return 1;
}
//stock
stock RemoveItem(playerid,modelid)
{
for(new i = 0;i<20;i++)
{
if(InvInfo[playerid][iSlot][i] == modelid)
{
InvInfo[playerid][iSlot][i] = 0;
break;
}
}
return 1;
}
stock AddItem(playerid,modelid)
{
for(new i = 0;i<20;i++)
{
if(InvInfo[playerid][iSlot][i] == 0)
{
InvInfo[playerid][iSlot][i] = modelid;
break;
}
}
return 1;
}
stock ShowInventory(playerid)
{
new iteminv[21];
for(new i = 0; i < 20;i++)
{
iteminv[i] = InvInfo[playerid][iSlot][i];
if(InvInfo[playerid][iSlot][i] == 0)
{
iteminv[i] = 1239;
}
}
ShowModelSelectionMenuEx(playerid, iteminv,20, "Inventory",INVENTORY_MENU, 0.0, 0.0,0.0);
return 1;
}
stock ResetInventory(playerid)
{
for(new i = 1 ; i <21;i++) InvInfo[playerid][iSlot][i] = 0;
return 1;
}
stock SaveInventory(playerid)
{
new file[64];
format(file, sizeof(file), "Inventory/%s.ini", GetName(playerid));
if(!dini_Exists(file)) dini_Create(file);
dini_IntSet(file, "Slot0", InvInfo[playerid][iSlot][0]);
dini_IntSet(file, "Slot1", InvInfo[playerid][iSlot][1]);
dini_IntSet(file, "Slot2", InvInfo[playerid][iSlot][2]);
dini_IntSet(file, "Slot3", InvInfo[playerid][iSlot][3]);
dini_IntSet(file, "Slot4", InvInfo[playerid][iSlot][4]);
dini_IntSet(file, "Slot5", InvInfo[playerid][iSlot][5]);
dini_IntSet(file, "Slot6", InvInfo[playerid][iSlot][6]);
dini_IntSet(file, "Slot7", InvInfo[playerid][iSlot][7]);
dini_IntSet(file, "Slot8", InvInfo[playerid][iSlot][8]);
dini_IntSet(file, "Slot9", InvInfo[playerid][iSlot][9]);
dini_IntSet(file, "Slot10", InvInfo[playerid][iSlot][10]);
dini_IntSet(file, "Slot11", InvInfo[playerid][iSlot][11]);
dini_IntSet(file, "Slot12", InvInfo[playerid][iSlot][12]);
dini_IntSet(file, "Slot13", InvInfo[playerid][iSlot][13]);
dini_IntSet(file, "Slot14", InvInfo[playerid][iSlot][14]);
dini_IntSet(file, "Slot15", InvInfo[playerid][iSlot][15]);
dini_IntSet(file, "Slot16", InvInfo[playerid][iSlot][16]);
dini_IntSet(file, "Slot17", InvInfo[playerid][iSlot][17]);
dini_IntSet(file, "Slot18", InvInfo[playerid][iSlot][18]);
dini_IntSet(file, "Slot19", InvInfo[playerid][iSlot][19]);
}
stock LoadInventory(playerid)
{
new file[64];
format(file, sizeof(file), "Inventory/%s.ini", GetName(playerid));
InvInfo[playerid][iSlot][0] = dini_Int(file,"Slot0");
InvInfo[playerid][iSlot][1] = dini_Int(file,"Slot1");
InvInfo[playerid][iSlot][2] = dini_Int(file,"Slot2");
InvInfo[playerid][iSlot][3] = dini_Int(file,"Slot3");
InvInfo[playerid][iSlot][4] = dini_Int(file,"Slot4");
InvInfo[playerid][iSlot][5] = dini_Int(file,"Slot5");
InvInfo[playerid][iSlot][6] = dini_Int(file,"Slot6");
InvInfo[playerid][iSlot][7] = dini_Int(file,"Slot7");
InvInfo[playerid][iSlot][8] = dini_Int(file,"Slot8");
InvInfo[playerid][iSlot][9] = dini_Int(file,"Slot9");
InvInfo[playerid][iSlot][10] = dini_Int(file,"Slot10");
InvInfo[playerid][iSlot][11] = dini_Int(file,"Slot11");
InvInfo[playerid][iSlot][12] = dini_Int(file,"Slot12");
InvInfo[playerid][iSlot][13] = dini_Int(file,"Slot13");
InvInfo[playerid][iSlot][14] = dini_Int(file,"Slot14");
InvInfo[playerid][iSlot][15] = dini_Int(file,"Slot15");
InvInfo[playerid][iSlot][16] = dini_Int(file,"Slot16");
InvInfo[playerid][iSlot][17] = dini_Int(file,"Slot17");
InvInfo[playerid][iSlot][18] = dini_Int(file,"Slot18");
InvInfo[playerid][iSlot][19] = dini_Int(file,"Slot19");
}
stock GetName(playerid)
{
new name[MAX_PLAYER_NAME];
GetPlayerName(playerid, name, sizeof(name));
return name;
}