SA-MP Forums Archive
[Tutorial] How to make inventory textdraw - 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] How to make inventory textdraw (/showthread.php?tid=533177)



How to make inventory textdraw - VinPure - 23.08.2014

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
pawn Код:
#include <zcmd> //Zeex
#include <dini>//to save inventory by DracoBlue
#include <mSelection> by d0
Step 1efine and new
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
Ok now we make stock ShowInventory , AddItem , RemoveItem , SaveInventory , LoadInventory , ResetInventory
* 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;
}
* Show, Add , Remove and Reset
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;
}
How to use Item
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;
}
* command test
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;
}
Finish All code
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;
}
Pic :


Re: How to make inventory textdraw - Cannary2048 - 23.08.2014

Awesome TUT, VinPure +REP
I have a question, how to create an accurate clickable textdraw with iPleomax TD?


Re: How to make inventory textdraw - [WSF]ThA_Devil - 24.08.2014

Nice tutorial but, I was wondering why isn't DINI extinct yet, and is used in so many projects...
Like, you can find better alternatives everywhere -
SQLite, MySQL, Y_INI and others that are way faster, and more efficient.


Re: How to make inventory textdraw - JustinAn - 24.08.2014

Quote:
Originally Posted by [WSF]ThA_Devil
Посмотреть сообщение
Nice tutorial but, I was wondering why isn't DINI extinct yet, and is used in so many projects...
Like, you can find better alternatives everywhere -
SQLite, MySQL, Y_INI and others that are way faster, and more efficient.
^ That.

OT: Anyways, great tutorial.


Re: How to make inventory textdraw - VinPure - 02.09.2014

Yeb i will update it .. and database with SQLite


Re: How to make inventory textdraw - Snipa - 03.09.2014

Dini? What is this, 2009?


Re: How to make inventory textdraw - MBilal - 26.01.2015

Код:
its Awesome But 
I try to add the Objects Hat
the Black Cowboyhat

CMD:add1(playerid,params[])
{
    AddItem(playerid,18962);
    return 1;
}

its not showing in the Inventory why ?

    if(listid == 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);
        }
        if(modelid == 18962)
        {
        SendClientMessage(playerid,-1,"Black Cowboy Hat");
	 	SetPlayerAttachedObject(playerid, 0, modelid, 2);
        }

        
        SendClientMessage(playerid,-1,"Inventory");
        }
        else SendClientMessage(playerid, 0xFF0000FF, "Close Inventory");
    }

why its not showing i tried also other Hat object same thing...
Fixed Awesome


Re: How to make inventory textdraw - Izaki - 05.04.2015

Work System Thanks


Re: How to make inventory textdraw - Frasco95 - 12.05.2015

How can I roteate the image on the menu?