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.801112.6495002902);
    
DropItem(2159.5239, -1789.530812.6495002902);
    
DropItem(2158.1540, -1807.387512.4795002902);
    
DropItem(2166.3779, -1800.720412.4695002902);
        
//
stock DropItem(Float:XFloat:YFloat:Zworld,interior,modelid)
{
        for(new 
0sizeof(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,Z5.0,world0);
                
Item[i] = CreateDynamicObject(modelidXYZ,272,0,0world);
                return 
1;
            }
        }
        return 
1;

Items will be dropped using this:
PHP код:
                new Float:XFloat:YFloat:Z;
        
GetPlayerPos(playeridXYZ);
        
DropItemXYZ-0.85GetPlayerVirtualWorld(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)