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 02-07-2016 , 12:57   Re: nVault Tutorial
Reply With Quote #61

Quote:
Originally Posted by Corabika View Post
Bugsy
Please How To Found Rank Pos And Thanks
You can't directly. You need to use nvault utility to read all entries into an array and then sort the array. You are better off using SQL in terms of ease and performance.
__________________
Bugsy is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 02-12-2016 , 08:52   Re: nVault Tutorial
Reply With Quote #62

Bugsy,opinion about this Save functions ?

Code:
public SaveGravity( id ) {     new szKey[40] , szGravity[11] , szAuthID[35];     get_user_authid( id, szAuthID, charsmax( szAuthID ) );     formatex( szKey , charsmax( szKey ) , "%s-Grav" , szAuthID );     formatex( szGravity , charsmax( szGravity ) , "%d" , g_iUserGravity[id] );     nvault_set( g_nVault, szKey, szGravity ); } public LoadGravity( id ) {     new szKey[40] , szAuthID[35] , szGravity[11];     get_user_authid( id, szAuthID, charsmax( szAuthID ) );     formatex( szKey , charsmax( szKey ) , "%s-Grav" , szAuthID );     formatex( szGravity , charsmax( szGravity ) , "%d" , g_iUserGravity[id] );     new iGravity = nvault_get( g_nVault, szKey );     SetGravity(id, iGravity); }
Craxor is offline
Send a message via ICQ to Craxor
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-12-2016 , 20:01   Re: nVault Tutorial
Reply With Quote #63

Code:
public SaveGravity( id ) {     new szKey[40] , szGravity[11] , szAuthID[35];
    get_user_authid( id, szAuthID, charsmax( szAuthID ) );
    //You should store all player id's in a global array so it can be used     //in all places without re-calling the native.     formatex( szKey , charsmax( szKey ) , "%s-Grav" , szAuthID );
    formatex( szGravity , charsmax( szGravity ) , "%d" , g_iUserGravity[id] );
    //Since you are not formatting, use num_to_str() instead.     nvault_set( g_nVault, szKey, szGravity ); } public LoadGravity( id ) {     new szKey[40] , szAuthID[35] , szGravity[11];     get_user_authid( id, szAuthID, charsmax( szAuthID ) );     formatex( szKey , charsmax( szKey ) , "%s-Grav" , szAuthID );
    formatex( szGravity , charsmax( szGravity ) , "%d" , g_iUserGravity[id] );
    //You do not need the szGravity variable or the above formatex(). In this     //function you are loading data, there is no need to format a variable that     //you would just overwrite (though you're not doing this) with data being loaded.    
    new iGravity = nvault_get( g_nVault, szKey );
    //I recommend using nvault_lookup() here so you can tell if data     //was found in the vault. nvault_get() will return 0 if a 0 exists as     //the data, or no data was found. If you prefer to use nvault_get(),     //which is ok, you should check that it's an acceptable value (>= X)     //before passing it to SetGravity().         SetGravity(id, iGravity); }
__________________
Bugsy is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 09-21-2016 , 03:28   Re: nVault Tutorial
Reply With Quote #64

What about my small example:

Click
__________________
Project: Among Us

Last edited by Craxor; 09-21-2016 at 03:49.
Craxor is offline
Send a message via ICQ to Craxor
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 09-21-2016 , 08:29   Re: nVault Tutorial
Reply With Quote #65

Why you wait for 1.5 seconds?
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-21-2016 , 12:18   Re: nVault Tutorial
Reply With Quote #66

Quote:
Originally Posted by Craxor View Post
What about my small example:

Click
What about it?

Arrays using player id as index should have the size of 33 for ease of use and avoid conflicts when using non-dedicated.

new iPlayerPoints = nvault_get( gNv, szAuthId[id][0] )
This points towards the first character in the string, the result is the same though because of the way that pawn terminates and reads strings. Still, if this is the example to be used it should be correct.

new szPoints[9];
This makes room for 8 characters + null. The maximum possible number of this is 99 999 999.
Max integer: 2 147 483 647, only 2 characters longer. Useless optimization of saving temporary memory.


This example is wrong as pointed out by Bugsy, the key is handled as char and the individual cells can therefor be no higher than 127.
My personal preference is to mash the SteamID into an integer and use it as a key instead of saving strings globally. (Can't do that with names, so non-steamers have to think which we know they are incapable of...)
For example:

Code:
I'm bad code, don't use me.
I do love integers though.
__________________

Last edited by Black Rose; 09-24-2016 at 11:54.
Black Rose is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 09-21-2016 , 14:44   Re: nVault Tutorial
Reply With Quote #67

@prostetamoto: Just for safety, 'maybe' player is not fully connected so i make a little delay, is not big deal but just to be sure( and in my past i was having problems some times so this should be there ).

It's you preferences rose, but bugsy said to make a global var gAuthId to avoid calling get_user_authid more times, even if you make it in a stock calls are maded more times but that's about preferences.


About szPoints should be [11] sorry i did not know about max integers

Oo, about '33' as i know:

32 - the container wich hold the the arrays:

31 - id 32
30 - id 31
29 - id 30
28 - id 29
27 - 28
..... bla bla bla...
4 - id 5
3 - id 4
2 - id 3
2 - id 3
1 - id 2
0 - id 1.

So why using 33 ?
__________________
Project: Among Us
Craxor is offline
Send a message via ICQ to Craxor
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 09-21-2016 , 14:54   Re: nVault Tutorial
Reply With Quote #68

client_authorized() is called once the player gets authenticated (gets the Steam ID), so you can already safely retrieve their Steam ID.

Last edited by klippy; 09-21-2016 at 14:54.
klippy is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 09-21-2016 , 15:03   Re: nVault Tutorial
Reply With Quote #69

I know man.

Sometimes when server works slowly and more players connect in the same times it can appears problems, so for safety i'm using a task. ( Anyway players not even observe ) and i don't will ruin the whole code, it should be used that's my op.
__________________
Project: Among Us
Craxor is offline
Send a message via ICQ to Craxor
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 09-21-2016 , 15:06   Re: nVault Tutorial
Reply With Quote #70

There can be no problems with multiple players connecting "at the same time" because the game loop is completely single threaded. But whatever, do as you like.
klippy 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 08:31.


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