Saving dropped items(CreateDynamicObject)
#1

Hello,

I am working on an inventory system which allows players to drop and pickup items.
My question is, how can i save and load the dropped objects after server restart?



Does anyone have an example for me?
Thanks in advance!

Code:

PHP код:

enum ItemData
{
    
Float:ItemPosX,
    
Float:ItemPosY,
    
Float:ItemPosZ,
    
ItemVWorld,
    
ItemInterior,
    
ItemModelID,
    
Toggled,
};
        
//Pickupable items that respawn after a certain time
        
DropItem(2173.8154, -1790.8011, 12.6495, 0, 0, 2902);
    
DropItem(2159.5239, -1789.5308, 12.6495, 0, 0, 2902);
    
DropItem(2158.1540, -1807.3875, 12.4795, 0, 0, 2902);
    
DropItem(2166.3779, -1800.7204, 12.4695, 0, 0, 2902);
        
//
stock DropItem(Float:X, Float:Y, Float:Z, world,interior,modelid)
{
        for(new 
i = 0; i < sizeof(ItemInfo); i++)
        {
            if(
ItemInfo[i][ItemPosX] == 0.0 && ItemInfo[i][ItemPosY] == 0.0 && ItemInfo[i][ItemPosZ] == 0.0)
            {
                
ItemInfo[i][ItemPosX] = X;
                
ItemInfo[i][ItemPosY] = Y;
                
ItemInfo[i][ItemPosZ] = Z;
                
ItemInfo[i][ItemVWorld] = world;
                
ItemInfo[i][ItemInterior] = interior;
                
ItemInfo[i][ItemModelID] = modelid;
                
Label2[i] = Create3DTextLabel("Item (Press 'C')", COLOR_YELLOW,X,Y,Z, 5.0,world, 0);
                
Item[i] = CreateDynamicObject(modelid, X, Y, Z,272,0,0, world);
                return 
1;
            }
        }
        return 
1;
} 
Items will be dropped using this:
PHP код:
                new Float:X, Float:Y, Float:Z;
        
GetPlayerPos(playerid, X, Y, Z);
        
DropItem( X, Y, Z-0.85, GetPlayerVirtualWorld(playerid),GetPlayerInterior(playerid),modelid); 
Reply
#2

You need to decide first whether you want to save them in files or in a SQL database.
Reply
#3

I prefer saving them in files.
Reply
#4

Download the YSI libraries: https://sampforum.blast.hk/showthread.php?tid=570883

Then #include <YSI\y_ini>

Then you'll have to learn how to use it.
Reply
#5

Quote:
Originally Posted by [eLg]elite
Посмотреть сообщение
Download the YSI libraries: https://sampforum.blast.hk/showthread.php?tid=570883

Then #include <YSI\y_ini>

Then you'll have to learn how to use it.
Hello Mr. Post Hunter, why do you think i ask for an example? I know how to use Y_Ini but i do not know how i do it if all dropped items are stored in 1 enum. And how to load em all afterwards.
Reply
#6

Quote:
Originally Posted by jasperschellekens
Посмотреть сообщение
Hello Mr. Post Hunter, why do you think i ask for an example? I know how to use Y_Ini but i do not know how i do it if all dropped items are stored in 1 enum. And how to load em all afterwards.
You don't store them in a enum, you're storing them in a multi-dimensional array.

Here is the official tutorial where you can learn how to write (save), read (load) and manage files using y_ini. All you have to do is save the cells enumerated by ItemData of a certain item id. (ItemInfo[itemid][ItemPosX], ItemInfo[i][ItemPosY], ...)
Reply
#7

Here is a problem.

- You are using == on floats which is a bad idea since they are not precise. Use ( <= >=)

You have some issues to work out before you are even ready to save anything.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)