AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Best way to just save the data from an array (https://forums.alliedmods.net/showthread.php?t=246132)

Flick3rR 08-12-2014 07:31

Best way to just save the data from an array
 
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?

HamletEagle 08-12-2014 07:56

Re: Best way to just save the data from an array
 
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.

Flick3rR 08-12-2014 12:10

Re: Best way to just save the data from an array
 
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.

PreDominance 08-12-2014 14:28

Re: Best way to just save the data from an array
 
Just use nVault. It's so much easier than trying to parse data from a file.

fysiks 08-12-2014 17:01

Re: Best way to just save the data from an array
 
Quote:

Originally Posted by Flick3rR (Post 2182939)
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).

Backstabnoob 08-12-2014 17:51

Re: Best way to just save the data from an array
 
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.

Flick3rR 08-20-2014 05:26

Re: Best way to just save the data from an array
 
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)

    }



klippy 08-20-2014 06:22

Re: Best way to just save the data from an array
 
There should probably be one global Trie, instead of one for each player.

Backstabnoob 08-20-2014 07:05

Re: Best way to just save the data from an array
 
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.


All times are GMT -4. The time now is 13:14.

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