[Ajuda] Salvar items do inventario?
#1

Como salvo os items do iventario? eu ja coloquei pra salvar os slots e mochilas mas nao sei colocar para salvar os items que tao no inventario! aguen da uma forcinha ai

Quote:

new ItemInfo[][Item_Data] =
{
/* id, objeto, nome, rotacao x, rotacao y, rotacao z */
/* ============ [ Mochilas ] ============ */
{0, 3026, "Taloon Backpack", -88.399, 0.0, 0.0 },
{1, 1310, "Hunting Backpack", -90.299, 0.0, 0.0 },
{2, 19559, "Hiker Backpack", -91.799, 0.0, 0.0 },
{3, 1550, "Drybag Backpack", 0.0, -94.899, 0.0 },
/* ========== [ Items Medicos ] ========== */
{4, 11738, "Medical Kit", 0.0, 0.0, 0.0 },
{5, 11748, "Bandage", 0.0, 0.0, 0.0 },
{6, 2752, "Morphine Injector", 0.0, 0.0, 0.0 },
{7, 2709, "Painkiller", 0.0, 0.0, 0.0 },
{8, 1580, "Blood Bag", 0.0, 0.0, 0.0 },
/* ============= [ Bebidas ] ============= */
{9, 19570, "Fresh Milk", 0.0, 0.0, 0.0 },
{10, 2683, "Water Canteen", 0.0, 0.0, 0.0 },
{11, 1546, "Sprunk Can", 0.0, 0.0, 0.0 },
{12, 19823, "Whisky Bottle", 0.0, 0.0, 0.0 },
{13, 19563, "Orange Juice", 0.0, 0.0, 0.0 },
{14, 19564, "Apple Juice", 0.0, 0.0, 0.0 },
{15, 19835, "Coffee", 0.0, 0.0, 0.0 },
/* ============= [ Comidas ] ============= */
{16, 19847, "Leg Ham", 0.0, 0.0, 0.0 },
{17, 19883, "Bread Slice", 0.0, 0.0, 0.0 },
{18, 2768, "Burger", 0.0, 0.0, 0.0 },
{19, 19561, "Cereal Box", 0.0, 0.0, 0.0 },
{20, 19580, "Pizza", 0.0, 0.0, 0.0 },
{21, 2769, "Taco", 0.0, 0.0, 0.0 },
{22, 19567, "Ice Cream", 0.0, 0.0, 0.0 },
{23, 2858, "Chinese Food", 0.0, 0.0, 0.0 },
{24, 19574, "Orange", 0.0, 0.0, 0.0 },
{25, 19575, "Apple", 0.0, 0.0, 0.0 },
{26, 19576, "Green Apple", 0.0, 0.0, 0.0 },
{27, 19577, "Tomato", 0.0, 0.0, 0.0 },
{28, 19578, "Banana", 0.0, 0.0, 0.0 },
/* ============= [ Armas ] ============= */
{29, 348, "Pistol .50", 90.0, 0.0, 0.0 },
{30, 346, "Glock 19", 90.0, 0.0, 0.0 },
{31, 347, "M9 SD", 90.0, 0.0, 0.0 },
{32, 357, "Mosin 9130", 90.0, 0.0, 0.0 },
{33, 358, "Hunting Rifle", 90.0, 0.0, 0.0 },
{34, 356, "AR-15", 90.0, 0.0, 0.0 },
{35, 355, "AKS-74U", 90.0, 0.0, 0.0 },
{36, 349, "MP-133 Shotgun", 90.0, 0.0, 0.0 },
{37, 350, "Sawed-off IZH-43", 90.0, 0.0, 0.0 },
{38, 351, "Pump Shotgun", 90.0, 0.0, 0.0 },
{39, 372, "CZ61 Skorpion", 90.0, 0.0, 0.0 },
{40, 352, "PDW", 90.0, 0.0, 0.0 },
{41, 353, "MP5-K", 90.0, 0.0, 0.0 },
/* ============= [ Armas Brancas ] ============= */
{42, 336, "Baseball Bat", 90.0, 0.0, 0.0 },
{43, 339, "Sword", 90.0, 0.0, 0.0 },
{44, 335, "Combat Knife", 90.0, 0.0, 0.0 },
{45, 337, "Shovel", 90.0, 0.0, 0.0 },
/* ============= [ Granadas ] ============= */
{46, 342, "Frag Grenade", 0.0, 0.0, 0.0 },
/* ============= [ Munições ] ============= */
{47, 3013, "Assault Ammo", 0.0, 0.0, 0.0 },
{48, 2043, "Shotgun Ammo", 0.0, 0.0, 0.0 },
{49, 2042, "SMG Ammo", 0.0, 0.0, 0.0 },
{50, 2037, "Pistol Ammo", 0.0, 0.0, 0.0 },
{51, 2038, "Sniper Ammo", 0.0, 0.0, 0.0 },
/* ============= [ Variados ] ============= */
{52, 18875, "GPS", 0.0, 0.0, 0.0 },
{53, 2386, "Clothing", 0.0, 0.0, 0.0 },
{54, 1010, "Engine", 0.0, 0.0, 0.0 },
{55, 19921, "Toolbox", 0.0, 0.0, 0.0 },
{56, 2967, "Radio Device", 0.0, 0.0, 0.0 },
{57, 19515, "Armour Vest", 90.0, 0.0, 0.0 },
{58, 19472, "Gas Mask", 0.0, 0.0, 0.0 },
{59, 19514, "Helmet", 0.0, 0.0, 0.0 },
{60, 1650, "Fuel Canister", 90.0, 0.0, 0.0 },
/* ============= [ Vazios ] ============= */
{61, 2683, "Empty Water Canteen", 0.0, 0.0, 0.0 },
{62, 1650, "Empty Fuel Canister", 90.0, 0.0, 0.0 }
};

eu so sei salvar quando e enum, nao sei salvar desse jeito ai nao alguem explica pfv? sou novato nessa area!
Reply
#2

Qual gamemode й essa?
Reply
#3

essa:
https://sampforum.blast.hk/showthread.php?tid=600273
Reply
#4

Essa enum ai funciona mais como um database dos items existentes, pra quando o server quiser criar um item ele tem onde puxar o ID do Objeto, o Nome do item e tals, agora jб pra fazer salvar os items й outra coisa, tem que mexer com o sistema de inventбrio, infelizmente o sistema de inventбrio dessa gm й uma porcaria mas ele tem uma funзгo pra salvar, acho que й SaveInventory ou SaveInv

Se servir de ajuda, aqui tem o tуpico desse sistema de inventбrio que eu usei nessa gm
https://sampforum.blast.hk/showthread.php?tid=130436

@edit

Jб que vocк й novato, recomendo dar uma olhada no gm do RodrigoMSR, uma boa base pra dayz
https://sampforum.blast.hk/showthread.php?tid=626829
Reply
#5

Quote:

stock SaveInventory(playerid)
{
gItemList="";
new filename[48];
GetPlayerName(playerid,filename,24);
format(filename,48,Inventarios,filename);
new File:file=fopen(filename,io_write);
for(new item;item<MAX_INV_ITEMS;item++)
{
if(!strlen(_GetItemNamePVar(playerid,item))||!_Get ItemAmountPVar(playerid,item))continue;
format(gItemList,sizeof(gItemList),"%s%s\n%d\n",gI temList,_GetItemNamePVar(playerid,item),_GetItemAm ountPVar(playerid,item));
}
fwrite(file,gItemList);
fclose(file);
GetPlayerName(playerid,filename,24);
}

stock LoadInventory(playerid)
{
new tstring[48];
new tstring2[12];
GetPlayerName(playerid,tstring,4;
format(tstring,48,Inventarios,tstring);
if(!fexist(tstring))return 0;
new File:file=fopen(tstring,io_read);
fread(file,tstring);
while(tstring[0])
{
format(tstring,strlen(tstring),"%s",tstring);
fread(file,tstring2);
AddItem(playerid,tstring,strval(tstring2));
fread(file,tstring);
}
fclose(file);
GetPlayerName(playerid,tstring,24);
return 1;
}

ta assim! so basta eu criar a pasta inventarios?

eu nao curti muito essa GM do Rodrigo, gostei mais dessa sua! tem varias coisas faltando mas ja arrumei bastantes! tou pegando algumas coisas da GM do Rodrigo e colocando nessa tbm!
Reply
#6

Quote:
Originally Posted by PedroH
Посмотреть сообщение
ta assim! so basta eu criar a pasta inventarios?

eu nao curti muito essa GM do Rodrigo, gostei mais dessa sua! tem varias coisas faltando mas ja arrumei bastantes! tou pegando algumas coisas da GM do Rodrigo e colocando nessa tbm!
Essas funзхes ai mesma!, o inventбrio fica salvo em arquivos de texto dentro de uma pasta. Pelo que me lembro o nome da pasta ta definido no topo do GM, sу procurar por #define Inventarios ou algo assim, nгo me lembro muito bem

Fico feliz que gostou do gamemode , espero que consiga terminar
Reply
#7

Quote:
Originally Posted by JPedro
Посмотреть сообщение
Essas funзхes ai mesma!, o inventбrio fica salvo em arquivos de texto dentro de uma pasta. Pelo que me lembro o nome da pasta ta definido no topo do GM, sу procurar por #define Inventarios ou algo assim, nгo me lembro muito bem

Fico feliz que gostou do gamemode , espero que consiga terminar
Nгo achei amigo ;c

as defines que achei ou que tem sao essas:

Quote:

//Dialogs
#define D_Sexo 3
#define D_Inventario 4
#define D_UsarDropar 5
#define D_PegarItem 6

Define do modulo do inventario:

Quote:

#define MAX_ITEM_STACK (99)
#define MAX_INV_ITEMS (99) // Maximo de items no inventario

Reply
#8

PHP код:
stock SaveInventory(playerid)
{
    
gItemList="";
    new 
filename[48];
    
GetPlayerName(playerid,filename,24);
    
format(filename,48,"Inventory/%s.inv",filename);
    new 
File:file=fopen(filename,io_write);
    for(new 
item;item<MAX_INV_ITEMS;item++)
    {
        if(!
strlen(_GetItemNamePVar(playerid,item))||!_Get ItemAmountPVar(playerid,item))continue;
        
format(gItemList,sizeof(gItemList),"%s%s\n%d\n",gI temList,_GetItemNamePVar(playerid,item),_GetItemAm ountPVar(playerid,item));
    }
    
fwrite(file,gItemList);
    
fclose(file);
    
GetPlayerName(playerid,filename,24);
}
stock LoadInventory(playerid)
{
    new 
tstring[48];
    new 
tstring2[12];
    
GetPlayerName(playerid,tstring,4;
    
format(tstring,48,"Inventory/%s.inv",tstring);
    if(!
fexist(tstring))return 0;
    new 
File:file=fopen(tstring,io_read);
    
fread(file,tstring);
    while(
tstring[0])
    {
        
format(tstring,strlen(tstring),"%s",tstring);
        
fread(file,tstring2);
        
AddItem(playerid,tstring,strval(tstring2));
        
fread(file,tstring);
    }
    
fclose(file);
    
GetPlayerName(playerid,tstring,24);
    return 
1;

Lembre-se de criar a pasta Inventory em Scriptfiles.
Reply
#9

Quote:
Originally Posted by Carlos001
Посмотреть сообщение
PHP код:
stock SaveInventory(playerid)
{
    
gItemList="";
    new 
filename[48];
    
GetPlayerName(playerid,filename,24);
    
format(filename,48,"Inventory/%s.inv",filename);
    new 
File:file=fopen(filename,io_write);
    for(new 
item;item<MAX_INV_ITEMS;item++)
    {
        if(!
strlen(_GetItemNamePVar(playerid,item))||!_Get ItemAmountPVar(playerid,item))continue;
        
format(gItemList,sizeof(gItemList),"%s%s\n%d\n",gI temList,_GetItemNamePVar(playerid,item),_GetItemAm ountPVar(playerid,item));
    }
    
fwrite(file,gItemList);
    
fclose(file);
    
GetPlayerName(playerid,filename,24);
}
stock LoadInventory(playerid)
{
    new 
tstring[48];
    new 
tstring2[12];
    
GetPlayerName(playerid,tstring,4;
    
format(tstring,48,"Inventory/%s.inv",tstring);
    if(!
fexist(tstring))return 0;
    new 
File:file=fopen(tstring,io_read);
    
fread(file,tstring);
    while(
tstring[0])
    {
        
format(tstring,strlen(tstring),"%s",tstring);
        
fread(file,tstring2);
        
AddItem(playerid,tstring,strval(tstring2));
        
fread(file,tstring);
    }
    
fclose(file);
    
GetPlayerName(playerid,tstring,24);
    return 
1;

Lembre-se de criar a pasta Inventory em Scriptfiles.
Nao foi ;c

nao criou o arquivo do player!
preciso colocar algo na GM?
Reply
#10

Quote:
Originally Posted by PedroH
Посмотреть сообщение
Nao foi ;c

nao criou o arquivo do player!
preciso colocar algo na GM?
claro, precisa chamar as stocks uй, como vai salvar sem a Utilizar
PHP код:
SaveInventory(playerid); 
//Quando desconnectar(OnPlayerDesconnect)
PHP код:
LoadInventory(playerid); 
// Use quando o player logar
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)