Raised This Month: $ Target: $400
 0% 

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-20-2014 , 05:26   Re: Best way to just save the data from an array
Reply With Quote #1

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
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 13:14.


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