Raised This Month: $51 Target: $400
 12% 

Best way to just save the data from an array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 08-12-2014 , 07:31   Best way to just save the data from an array
Reply With Quote #1

Hey, guys! I just want to ask you which is the best way to just save the data from an array and call it like in plugin_init for the maptime. Because arrays are global and they just reset on map change. That's why I just want the most simple and efficient way to save the data from an array. Sql, vault, some other way or?
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 08-12-2014 , 07:56   Re: Best way to just save the data from an array
Reply With Quote #2

It depends on what you want to save. You can create an ini file if you want to store sth like players names, gag time, etc. If you are saving points use nvault/mysql.
__________________

Last edited by HamletEagle; 08-12-2014 at 07:57.
HamletEagle is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 08-12-2014 , 12:10   Re: Best way to just save the data from an array
Reply With Quote #3

Yes, they are mostly strings, one trie and one integer. Different. I don't want to use it anywhere, just to save it for the next map.
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
PreDominance
Member
Join Date: Jul 2014
Old 08-12-2014 , 14:28   Re: Best way to just save the data from an array
Reply With Quote #4

Just use nVault. It's so much easier than trying to parse data from a file.
PreDominance is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-12-2014 , 17:01   Re: Best way to just save the data from an array
Reply With Quote #5

Quote:
Originally Posted by Flick3rR View Post
Yes, they are mostly strings, one trie and one integer. Different. I don't want to use it anywhere, just to save it for the next map.
You can't save a trie. Are you saying that you want to save the string and the integer that the trie consists of? This is very common and is done in many plugins (like every ban plugin that is written correctly).
__________________
fysiks is offline
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 08-12-2014 , 17:51   Re: Best way to just save the data from an array
Reply With Quote #6

https://forums.alliedmods.net/showthread.php?t=244605
This is the widely accepted option, but it requires a different data system than what you're using. If you seriously want to save contents of a trie then you would need to use CellTravTrie so you're able to traverse it. I still suggest changing your data to JSON object because that's like, a million times better.
__________________
Currently busy working on a very large scale anime database project.

Last edited by Backstabnoob; 08-12-2014 at 17:53.
Backstabnoob is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 08-20-2014 , 05:26   Re: Best way to just save the data from an array
Reply With Quote #7

I really didn't try to use that JSON, because I simply can't understand even a bit of it...
So, here is what I though out, but unfortunately it's not working (maybe because it's not properly coded).
What I actually did? Well, I pushed new string into the array enum - it's players ID. After this I save it as a string and used it as a key for retrieving the data from the trie.
Btw, I don't know if it's possible to return a string via nvault, but since all the numbers must be converted to strings, I think it will be okay.
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <nvault>

#define PLUGIN "Save Array With Trie"
#define VERSION "1.0"
#define AUTHOR "Flicker"

enum _:GagInfo
{
    
Trie:Gagged,
    
Reason[64],
    
AdminName[32],
    
Date[32],
    
Len,
    
Systime,
    
ID[32]
    
}

new 
gVault

new Array:g_aGaggedPlayers

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
g_aGaggedPlayers ArrayCreate(GagInfo)
    
    
gVault nvault_open("ArrayData")
    
    
LoadGags()
}

public 
plugin_end()
    
SaveGags()

    
    

new const 
SizeKey[] = "sasasaisajoda"
new g_arraysize

public SaveGags()
{
    new 
aData[GagInfo]
    new 
szKey[64], szData[526
    
    
g_arraysize ArraySize(g_aGaggedPlayers)
    
    new 
szSize[64]
    
num_to_str(g_arraysizeszSizecharsmax(szSize))
    
    
nvault_set(gVaultSizeKeyszSize)
    
    for(new 
ig_arraysizei++)
    {
        
ArrayGetArray(g_aGaggedPlayersiaData)
        
        
formatex(szDatacharsmax(szData), "%s %s %s %d %d %s"aData[Reason], aData[AdminName], aData[Date], aData[Len], aData[Systime], aData[ID])
        
        
num_to_str(iszKeycharsmax(szKey))
        
        
nvault_set(gVaultszKeyszData)
    }
}

public 
LoadGags()
{
    new 
aData[GagInfo]
    new 
szKey[64], szData[526]
    
    new 
szSize[64]
    
nvault_get(gVaultSizeKeyszSize)
    
    
g_arraysize str_to_num(szSize)
    
    for(new 
ig_arraysizei++)
    {
        
formatex(szDatacharsmax(szData), "%s %s %s %d %d %s"aData[Reason], aData[AdminName], aData[Date], aData[Len], aData[Systime], aData[ID])
        
        
num_to_str(iszKeycharsmax(szKey))
        
        
nvault_get(gVaultszKeyszData)
        
        new 
szLen[32], szSys[32]
        
parse(szDataaData[Reason], charsmax(aData[Reason]), aData[AdminName], charsmax(aData[AdminName]), aData[Date], charsmax(aData[Date]), szLencharsmax(szLen), szSyscharsmax(szSys), aData[ID], charsmax(aData[ID]))
        
        
aData[Len] = str_to_num(szLen)
        
aData[Systime] = str_to_num(szSys)
        
aData[Gagged] = _TrieCreate()
        
TrieSetCell(aData[Gagged], aData[ID], 1)
        
        
ArrayPushArray(g_aGaggedPlayersaData)

    }

__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 08-20-2014 , 06:22   Re: Best way to just save the data from an array
Reply With Quote #8

There should probably be one global Trie, instead of one for each player.
klippy is offline
Backstabnoob
Veteran Member
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 08-20-2014 , 07:05   Re: Best way to just save the data from an array
Reply With Quote #9

Well, you're asking for help. I gave you the best solution available, use JSON. Instead of making excuses that you can't use it, why don't you at least try it? It's really not any more difficult than using arrays and tries, plus there are tutorials all over the internet on how to use Jansson. The AMXX version is not that much different.
__________________
Currently busy working on a very large scale anime database project.
Backstabnoob 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 11:30.


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