Saving variable per variable
Hello there,
I add items to a menu using an API using sub-plugins. Now, I want to save the time when someone clicked on a menu item and remove that entry after e.g. 1 hour. Time should be saved per player and per item and removed per time per item, means I need to save a dynamic amount of variables which get removed dynamically and independent of each other. Any suggestions on how to realize that? |
Re: Saving variable per variable
That's not enough info. You obviously need some sort of 2-D array.
|
Re: Saving variable per variable
Okay, I will try to explain.
I have a Shop (menu) which content is added by sub-plugins. When a player buys one of the items, the item is added into his "list" of saved items. This bought item should expire after a certain time. |
Re: Saving variable per variable
You already said that. How do you identify items? By a generated integer? The simple answer would be new g_ItemBuyTimestamp[ MaxPlayers ][ MaxItems ]. When a player buys an item you just do g_ItemBuyTimestamp[ Id ][ ItemId ] = get_systime(). Then on menu display/callback you check if g_ItemByTimestamp[ id ][ ItemId ] + 3600 < get_systime() and disable the item accordingly.
Since you want it to last this long you somehow need to save the time stamp. Although this is really simple so I'm unsure if that's what you want. |
Re: Saving variable per variable
Each item has it's own index yes, but how do I save that array efficiently?
|
Re: Saving variable per variable
SQL would be your best bet in this case. Or JSON string, but there's no efficient way to deal with JSON in amxx unless someone ports SMJansson.
|
Re: Saving variable per variable
Wouldn't I need a table for each item?
Or how do you handle arrays in SQL? |
Re: Saving variable per variable
No, why? Just create a table such as:
Code:
CREATE TABLE table_itemlist ( Code:
+------------------+--------+---------------+ |
Re: Saving variable per variable
Quote:
Code:
+------------------+--------+---------------+ |
Re: Saving variable per variable
What don't you understand? In the post I showed the player with steam ID STEAM_0:1:12345 has items 1, 2, 3 and 5 at the same time (until get_systime( ) is higher than unixtime from the table)
Anyway, using numbered indexes for items is not the best idea because if the plugin order changes, items will also have different identifiers, so you should think about some sort of unique string identifiers. |
| All times are GMT -4. The time now is 09:47. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.