Raised This Month: $ Target: $400
 0% 

Solved Data storage


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 07-25-2018 , 14:14   Re: Data storage
Reply With Quote #1

PHP Code:
eDataItemType ][ MAX_ENTS ][ ItemInfo 
=>

PHP Code:
eDataItemInfo 
And to access an entry inside it:

PHP Code:
if(eData[Item_Type] == ITEM_POULET
PHP Code:
if(eData[Item_Id] == 999
__________________

Last edited by OciXCrom; 07-25-2018 at 14:16.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 07-25-2018 , 14:23   Re: Data storage
Reply With Quote #2

Quote:
Originally Posted by OciXCrom View Post
And to access an entry inside it:

PHP Code:
if(eData[Item_Type] == ITEM_POULET
PHP Code:
if(eData[Item_Id] == 999
What if I have to do this?
PHP Code:
eDataiType ][ iNum ][ Item_Name ][ ] = EOS
__________________

Last edited by edon1337; 07-25-2018 at 14:24.
edon1337 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 07-25-2018 , 14:24   Re: Data storage
Reply With Quote #3

What is that code supposed to do? It makes no sense.
__________________

Last edited by OciXCrom; 07-25-2018 at 14:24.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 07-25-2018 , 14:25   Re: Data storage
Reply With Quote #4

Quote:
Originally Posted by OciXCrom View Post
What is that code supposed to do? It makes no sense.
PHP Code:
public @HamSpawn_Postid )
{
    if( 
is_user_aliveid ) )
    {
        new 
eDataItemInfo ];
        
        for( new 
iArraySizeg_aItemsid ] ) - 1i++ )
        {
            for( new 
iType=ITEM_POULETiType <= ITEM_SNACKiType++ )
            {
                for( new 
iNumiNum MAX_ENTSiNum++ )
                {
                    
eDataiType ][ iNum ][ Item_Id ] = 0;
                    
eDataiType ][ iNum ][ Item_Name ][ ] = EOS;
                    
                    
ArraySetArrayg_aItemsid ], ieData );
                }
            }
        }
    }

__________________

Last edited by edon1337; 07-25-2018 at 14:25.
edon1337 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 07-25-2018 , 14:27   Re: Data storage
Reply With Quote #5

I was talking about that, but you changed the post later. Is that part of the code supposed to remove all items from the player? If yes - ArrayClear?!
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 07-25-2018 , 14:30   Re: Data storage
Reply With Quote #6

Quote:
Originally Posted by OciXCrom View Post
I was talking about that, but you changed the post later. Is that part of the code supposed to remove all items from the player? If yes - ArrayClear?!
Well, yeah, I randomly wrote all that to get used to the usage of clearing the entire array.

Here's a better example:

PHP Code:
for( new iMAX_ENTSi++ )
        {
            if( ! 
eDataItem_Type ][ ][ Item_Id ] )
            {
                
eDataItem_Type ][ ][ Item_Id ] = iEnt;
                
eDataItem_Type ][ ][ Item_Name ] = iEnt;
                
                
ArrayPushArrayg_aItemsid ], eData );
                
                break;
            }
        } 
It goes loops through MAX_ENTS (maximum number of entities that a player can hold), checks if the entity in slot i doesn't exist, so we create it and then push the data into array.
__________________
edon1337 is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 07-25-2018 , 14:35   Re: Data storage
Reply With Quote #7

That still doesn't make sense. Maybe if you explain how the entire item system works it will be easier for us to understand. From what I understood so far - you need to use simply ArrayPushArray to add the item and ArrayDeleteItem to remove an item (or ArrayClear to remove all of them).
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 07-25-2018 , 14:37   Re: Data storage
Reply With Quote #8

Quote:
Originally Posted by OciXCrom View Post
That still doesn't make sense. Maybe if you explain how the entire item system works it will be easier for us to understand. From what I understood so far - you need to use simply ArrayPushArray to add the item and ArrayDeleteItem to remove an item (or ArrayClear to remove all of them).
I guess your method doesn't fit what I'm trying to do.

The plugin first of all creates entities that are inside an .ini file (healings), they spawn all around the map and you can grab a max of 3 of each type, for later usage, when you type /backpack your list of healings appear. After you use a healing, it is removed completely.

There are 2 types of healings currently: item_poulet and item_snack.
- item_poulet gives user 100 HP (max).
- item_snack gives user 25 HP
__________________

Last edited by edon1337; 07-25-2018 at 14:39.
edon1337 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 07-25-2018 , 15:06   Re: Data storage
Reply With Quote #9

Flatten your data, there's no need to nest so deep.
To be honest you only need
PHP Code:
new g_items[MAX_ITEMS_THAT_CAN_EXIST][SomeItemInfoEnumIGuess]; // I guess you are reading these ones from a file
//Each element in g_playerItems[id] is an ID into the g_items array.
new g_playerItems[MAX_PLAYERS 1][MAX_ITEMS_A_PLAYER_CAN_CARRY]; 
I also stopped using enum-structs to structure data a long time ago. I figured they are a bad hack for structures and they bring more headaches than simply having multiple arrays for each property of a desired structure. By splitting each feature in a file (item system is a feature for example) and hiding all variables behind functions it's really easy to deal with them from other parts of the code.
__________________

Last edited by klippy; 07-25-2018 at 15:11.
klippy is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 07-25-2018 , 15:12   Re: Data storage
Reply With Quote #10

Quote:
Originally Posted by KliPPy View Post
PHP Code:
//Each element in g_playerItems[id] is an ID into the g_items array.
new g_playerItems[MAX_PLAYERS 1][MAX_ITEMS_A_PLAYER_CAN_CARRY]; 
With that I'm only able to store player IDs and max number of entities, what about the entity type and entity id&name?
__________________
edon1337 is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 12:23.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode