Raised This Month: $32 Target: $400
 8% 

nVault Tutorial


Post New Thread Reply   
 
Thread Tools Display Modes
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-27-2014 , 17:09   Re: nVault
Reply With Quote #51

How much data is stored for each player? I personally would try to keep everything in one vault and group data into a single kv pair. If you are storing a ton of data, or have unique queries, I'd go with SQL.
__________________

Last edited by Bugsy; 07-27-2014 at 17:09.
Bugsy is offline
PreDominance
Member
Join Date: Jul 2014
Old 07-29-2014 , 03:27   Re: nVault
Reply With Quote #52

Quote:
Originally Posted by Bugsy View Post
How much data is stored for each player? I personally would try to keep everything in one vault and group data into a single kv pair. If you are storing a ton of data, or have unique queries, I'd go with SQL.
Well this is for a warcraft mod. Each player needs to have a few small things (BankXp, bankLevel, current race, player total level). For each race, however, a player needs to have:
  • Race XP
  • Race Level
  • Skill1/2/3/4/5/6/7/8 (stored as a string delimited by ",").
I plan on having over 60 races, so each player might have upwards of 350KV pairs.


I don't have the time to try to work with SQL or SQLite, as I've 0 experience with either, and I've already gotten so much work put into using vault.


For reference, here's how I'm getting/storing data:


Code:
//Returns the key of the KV pair. By systematically generating keys, it becomes
//easier to enforce consistency.
vault_getUserKey(id, type[], raceId = 0) 
{
    static szReturn[70];
    static szKeyType[30];
    static szId[30];
    get_user_authid(id, szId, charsmax(szId));
    if (raceId)
    {
        format(szKeyType, charsmax(szKeyType), "%s %i", szKeyType, raceId);
    } else {
        format(szKeyType, charsmax(szKeyType), "%s", type);
    }
    format(szReturn, charsmax(szReturn), "%s %s", szId, szKeyType);
    return szReturn;
}


...constants.inl

#define KEY_CURRACE            "CurRace" //Current race, so server remembers your race upon return
#define KEY_RACE_LEVELS        "RaceLevels" //Levels of skills in a race
#define KEY_RACE_TOTAL        "RaceTotalLevels" //Total level of all skills in a race
#define KEY_RACE_XP            "RaceXp" //Xp in a race
#define KEY_BANKXP            "BankXP" //Xp in gank
#define KEY_BANKLEVEL        "BankLevel" //Levels in bank
#define KEY_NAME            "Name" //Name of user upon first connection

Last edited by PreDominance; 07-29-2014 at 03:31.
PreDominance is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 07-29-2014 , 05:03   Re: nVault
Reply With Quote #53

Quote:
Originally Posted by PreDominance View Post
Well this is for a warcraft mod. Each player needs to have a few small things (BankXp, bankLevel, current race, player total level). For each race, however, a player needs to have:
  • Race XP
  • Race Level
  • Skill1/2/3/4/5/6/7/8 (stored as a string delimited by ",").
I plan on having over 60 races, so each player might have upwards of 350KV pairs.


I don't have the time to try to work with SQL or SQLite, as I've 0 experience with either, and I've already gotten so much work put into using vault.


For reference, here's how I'm getting/storing data:


Code:
//Returns the key of the KV pair. By systematically generating keys, it becomes
//easier to enforce consistency.
vault_getUserKey(id, type[], raceId = 0) 
{
    static szReturn[70];
    static szKeyType[30];
    static szId[30];
    get_user_authid(id, szId, charsmax(szId));
    if (raceId)
    {
        format(szKeyType, charsmax(szKeyType), "%s %i", szKeyType, raceId);
    } else {
        format(szKeyType, charsmax(szKeyType), "%s", type);
    }
    format(szReturn, charsmax(szReturn), "%s %s", szId, szKeyType);
    return szReturn;
}


...constants.inl

#define KEY_CURRACE            "CurRace" //Current race, so server remembers your race upon return
#define KEY_RACE_LEVELS        "RaceLevels" //Levels of skills in a race
#define KEY_RACE_TOTAL        "RaceTotalLevels" //Total level of all skills in a race
#define KEY_RACE_XP            "RaceXp" //Xp in a race
#define KEY_BANKXP            "BankXP" //Xp in gank
#define KEY_BANKLEVEL        "BankLevel" //Levels in bank
#define KEY_NAME            "Name" //Name of user upon first connection
Maybe a vault file for each class, instead for each player? Or maybe, you could change key to
Code:
STEAM_0:1:234567-4
where that "4" would be class id, which means, every player can have up to 60(or whatever your class number is) keys in vault.
klippy is offline
PreDominance
Member
Join Date: Jul 2014
Old 07-29-2014 , 22:14   Re: nVault
Reply With Quote #54

Your 2'nd description is more closer to the one I currently use. With it, the KV Pairs should look like:

  • STEAM_0:1;37003168 CurRace 32
  • STEAM_0:1;37003168 RaceLevels 0,1,2,3,4,5,6,7
  • STEAM_0:1;37003168 Name PreDominance
etc.

Maybe later on once I become more comfortable with the way this language works I'll do something like..

  • STEAM_0:1;37003168 RaceInfo 32 64 128 2,5,6,5,1,2,1,0
Where each player has one key per race. <id> KEY_RACE_INFO <raceId> <level> <xp> <skill levels>

Last edited by PreDominance; 07-29-2014 at 22:16.
PreDominance is offline
Catastrophe
Veteran Member
Join Date: Jul 2012
Location: somewhere between narnia
Old 11-02-2014 , 09:53   Re: nVault
Reply With Quote #55

How do i save/load a cellarray using nvault ? suppose i have a BUFFER array (i.e array that i change whenever needed) containing steam ids and i get its size using arraysize for saving but then how do i load it into another or the same array in plugin_init or precache ?
__________________
You will find everything u need :-
Catastrophe is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-04-2015 , 21:25   Re: nVault Tutorial
Reply With Quote #56

Quote:
Originally Posted by PreDominance View Post
Your 2'nd description is more closer to the one I currently use. With it, the KV Pairs should look like:

  • STEAM_0:1;37003168 CurRace 32
  • STEAM_0:1;37003168 RaceLevels 0,1,2,3,4,5,6,7
  • STEAM_0:1;37003168 Name PreDominance
etc.

Maybe later on once I become more comfortable with the way this language works I'll do something like..

  • STEAM_0:1;37003168 RaceInfo 32 64 128 2,5,6,5,1,2,1,0
Where each player has one key per race. <id> KEY_RACE_INFO <raceId> <level> <xp> <skill levels>
This would be an easy scenario to handle with the Array to String include I recently posted. Take a look at that thread, I posted an example for saving player data using an enum to size the array. No parsing needed, simple 2 lines to save and retrieve data into your array.

Quote:
Originally Posted by Catastrophe View Post
How do i save/load a cellarray using nvault ? suppose i have a BUFFER array (i.e array that i change whenever needed) containing steam ids and i get its size using arraysize for saving but then how do i load it into another or the same array in plugin_init or precache ?
You can save\load data to\from nvault into a normal array with ease with array to string include.
__________________
Bugsy is offline
yokomo
Surprise Ascot!
Join Date: May 2010
Location: Malaysia
Old 03-27-2015 , 12:04   Re: nVault Tutorial
Reply With Quote #57

Bugsy can you modify this code so i can show:
Playername rank is 'position' out of 'total entries'.

The code above is to show top10 entries only, I want to show rank. Thanks.
__________________
Team-MMG CS1.6 Servers:
✅ MultiMod -- 103.179.44.152:27016
✅ Zombie Plague -- 103.179.44.152:27015
✅ Zombie Escape -- 103.179.44.152:27017
✅ Klassik Kombat -- 103.179.44.152:27018
✅ Boss-Battle -- 103.179.44.152:27019
yokomo is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 04-04-2015 , 12:23   Re: nVault Tutorial
Reply With Quote #58

Increase the below to accommodate your max.
PHP Code:
const MAX_ENTRIES 10
Then modify this line to show what you want:
PHP Code:
server_print("%d. %-20.20s %d", (1), data[VD_Key], data[VD_Value]); 
__________________
Bugsy is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-09-2015 , 18:08   Re: nVault Tutorial
Reply With Quote #59

Added nvault_remove() which I somehow forgot and added return values for each function.
__________________
Bugsy is offline
Corabika
Junior Member
Join Date: Aug 2015
Location: Morocco
Old 02-07-2016 , 11:03   Re: nVault Tutorial
Reply With Quote #60

Bugsy
Please How To Found Rank Pos And Thanks
__________________
Corabika is offline
Reply


Thread Tools
Display Modes

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 16:34.


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