Two questions
#1

Hey there. I have two questions and if I get the answer I'm looking for then this will help me alot. I allways had problems with the codes like
pawn Код:
for (new d = 0; d < INV_MAX_SLOTS; d++)
{
 //blahblahblah
}
Not really scripting problems cuz I use them sometimes when it comes to MAX_PLAYERS but I can say that I use them "blindly" like I don't really know how to use them more "profesionally" to let my imagination "float around".

Anyway, skipping the bullcrap Here's my question...


I made this saving and removing system and my inventory got like 20 slots... so far I have to call the Remove or Add function 20 times to fill the inv with the items the player had before he logged out or to remove all the inventory items.

First question!


It's a easy one...

When the player dies it's called this

pawn Код:
for (new d = 0; d < INV_MAX_SLOTS; d++)
{
    RemoveItemFromInventory(playerid, d);
}
Anyway, only ONE item it's deleted and not just all of them.

RemoveItemFromInventory works like

pawn Код:
RemoveItemFromInventory(playerid, slot);
and INV_MAX_SLOTS it's defined 20

That being that here comes my

Second question!

I'd like to do the same thing with the saving system but it works with Y_INI

so far I only had 4 slots so I made 4 enums like Slot1, Slot2, Slot3, Slot4 and used 4 WriteInt to save them. Anyway I don't want to make 20 WriteInt to save all the items ... so how can I make this shorter?

I'll show ya parts of the code.

pawn Код:
enum yInfo
{
    Slot0,
    Slot1,
    Slot2,
    Slot3
}

new InvInfo[MAX_PLAYERS][yInfo];
Saving the items
pawn Код:
INI_WriteInt(File, "Slot0", GetItemType(GetInventorySlotItem(playerid, 0)));
INI_WriteInt(File, "Slot1", GetItemType(GetInventorySlotItem(playerid, 1)));
INI_WriteInt(File, "Slot2", GetItemType(GetInventorySlotItem(playerid, 2)));
INI_WriteInt(File, "Slot3", GetItemType(GetInventorySlotItem(playerid, 3)));
pawn Код:
GetInventorySlotItem(playerid, slot); //returns the id of an item
GetItemType(itemid); //Well ... it gets the type of an item...
Loading the data (This part beated me ...)

pawn Код:
INI_Int("Slot0",InvInfo[playerid][Slot0]);
INI_Int("Slot1",InvInfo[playerid][Slot1]);
INI_Int("Slot2",InvInfo[playerid][Slot2]);
INI_Int("Slot3",InvInfo[playerid][Slot3]);
And OnPlayerSpawn adding them back to the player inventory

pawn Код:
AddItemToInventory(playerid, CreateItem(InvInfo[playerid][Slot0]), 1);
AddItemToInventory(playerid, CreateItem(InvInfo[playerid][Slot1]), 1);
AddItemToInventory(playerid, CreateItem(InvInfo[playerid][Slot2]), 1);
AddItemToInventory(playerid, CreateItem(InvInfo[playerid][Slot3]), 1);

If you got more question or need more parts of the code please tell me. Thank you
Reply
#2

pawn Код:
#define INV_MAX_SLOTS   4

enum yInfo
{
    Slot[INV_MAX_SLOTS] // 4 slots
}

new InvInfo[MAX_PLAYERS][yInfo];

Writting:
pawn Код:
new str[10];
for(new slot = 0; slot != INV_MAX_SLOTS; slot++)
{
    format(str,sizeof(str),"Slot%d",slot);
    INI_WriteInt(File, str, GetItemType(GetInventorySlotItem(playerid, slot)));
}

Reading:
pawn Код:
new str[10];
for(new slot = 0; slot != INV_MAX_SLOTS; slot++)
{
    format(str,sizeof(str),"Slot%d",slot);
    INI_Int(str, InvInfo[playerid][Slot][slot]);
}

Spawn:
pawn Код:
for(new slot = 0; slot != INV_MAX_SLOTS; slot++)
    AddItemToInventory(playerid, CreateItem(InvInfo[playerid][Slot][slot]), 1);
Reply
#3

Quote:
Originally Posted by Jefff
Посмотреть сообщение
pawn Код:
#define INV_MAX_SLOTS   4

enum yInfo
{
    Slot[INV_MAX_SLOTS] // 4 slots
}

new InvInfo[MAX_PLAYERS][yInfo];

Writting:
pawn Код:
new str[10];
for(new slot = 0; slot != INV_MAX_SLOTS; slot++)
{
    format(str,sizeof(str),"Slot%d",slot);
    INI_WriteInt(File, str, GetItemType(GetInventorySlotItem(playerid, slot)));
}

Reading:
pawn Код:
new str[10];
for(new slot = 0; slot != INV_MAX_SLOTS; slot++)
{
    format(str,sizeof(str),"Slot%d",slot);
    INI_Int(str, InvInfo[playerid][Slot][slot]);
}

Spawn:
pawn Код:
for(new slot = 0; slot != INV_MAX_SLOTS; slot++)
    AddItemToInventory(playerid, CreateItem(InvInfo[playerid][Slot][slot]), 1);
Complied it and got no error. I'm going to test it and tell post what I get. Thank you for the fast answer. By the way the define has to be 20 cuz I need it for a 20 slot inv.

Could you also tell me what's wrong with this? It only deletes ONE item and not all of them ...

pawn Код:
for (new d = 0; d < INV_MAX_SLOTS; d++)
{
    RemoveItemFromInventory(playerid, d);
}


Works like charm so far! The only problem is that it's also saving the empty slots with itemid -1 and when I join it tries to create them but since there's no item I get this

pawn Код:
[04:30:57] ERROR: Item creation with undefined typeid (-1) failed.
[04:30:57] ERROR: Item creation with undefined typeid (-1) failed.
[04:30:57] ERROR: Item creation with undefined typeid (-1) failed.
[04:30:57] ERROR: Item creation with undefined typeid (-1) failed.
[04:30:57] ERROR: Item creation with undefined typeid (-1) failed.
[04:30:57] ERROR: Item creation with undefined typeid (-1) failed.
[04:30:57] ERROR: Item creation with undefined typeid (-1) failed.
[04:30:57] ERROR: Item creation with undefined typeid (-1) failed.
[04:30:57] ERROR: Item creation with undefined typeid (-1) failed.
[04:30:57] ERROR: Item creation with undefined typeid (-1) failed.
[04:30:57] ERROR: Item creation with undefined typeid (-1) failed.
[04:30:57] ERROR: Item creation with undefined typeid (-1) failed.
[04:30:57] ERROR: Item creation with undefined typeid (-1) failed.
[04:30:57] ERROR: Item creation with undefined typeid (-1) failed.
[04:30:57] ERROR: Item creation with undefined typeid (-1) failed.
[04:30:57] ERROR: Item creation with undefined typeid (-1) failed.

But I think I can fix this myself.

And i don't know what happened but now the RemoveItemFromInventory works.
Reply
#4

Show that stock RemoveItemFromInventory
Reply
#5

Yup, still beats me ... anyway I have this one. Could you create something magically with it please?

Something like If(ItemType == INVALID_ITEM_TYPE) then skip creating it...

pawn Код:
#define INVALID_ITEM_TYPE   (ItemType:-1)
Reply
#6

pawn Код:
for(new slot = 0; slot != INV_MAX_SLOTS; slot++)
    if(InvInfo[playerid][Slot][slot] != INVALID_ITEM_TYPE)
        AddItemToInventory(playerid, CreateItem(InvInfo[playerid][Slot][slot]), 1);
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)