Thread: nVault Tutorial
View Single Post
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 09-22-2016 , 20:52   Re: nVault Tutorial
Reply With Quote #74

@Black Rose -- I don't see the advantage of converting the steam id to an integer when using nvault. You would then need to convert it back to a string to use it as a key when saving and loading data since nvault only allows string keys. I like where your head is at with this but with nvault I don't see the point. Yes, it saves memory, but as you said a few posts ago, memory is not much of a concern anymore, it's CPU that is expensive. Plus, you realize he's trying to learn, I don't understand why you're trying to confuse him even more with code that has moot benefit over using a string -- on top of that, it doesn't even work like I think you're expecting it to. You are trying to store this unique value into a 2 cell array/string -- 1 cell will do for an integer and 2 for a string doesn't make sense. If I misinterpreted anything, please correct me. I'm not trying to ruffle anyone's feathers here.

Code:
//Each player gets a 2 cell array/string? Why?
//If your plan was to store only an integer here,
//you only need a single dimension array.
new giSteamID[33][2];
stock GetUseriSteamID(id) {     new szSteamID[21];     get_user_authid(id, szSteamID, charsmax(szSteamID));     return str_to_num(szSteamID[10]) | '0' - szSteamID[8] << 31; } public client_authorized( id ) {     giSteamID[id][0] = GetUseriSteamID(id);
    //nVault needs a string as the key, here you are
    //passing it a 1 character string which I do not think
    //is your intention. You should convert it back to a string
    //using num_to_str() but then you defeat the purpose of
    //using an integer instead of a string so you may as well
    //just store the full steam id in a string.
    gPoints[id] = nvault_get(gnVault, giSteamID[id])
}

@Craxor

Quote:
Originally Posted by Craxor View Post
Yes, but if i will use you examples also for Saving data i willl need to call more times get_user_authid, i'm wrong?
I know about if i use just for taking data from nvault and is logic if i'm using only once ) what about retrieving?

Anyway i need to read more times what you write, you write tooo much for me ) i wil re-read more times

Btw: if a make something like: new szAuthid[32+1]; will change resize automatcly when new index is needed?
You should ever only call get_user_authid() once at client_authorized() and store the value globally. You can then use it again when the user disconnects to save their data as well as anywhere else in your plugin that the steam id may be needed.

You cannot and do not ever need to change/resize the array once it's defined (talking regular arrays here). You should always size your arrays at the max possible size you will need, so in the case of CS 1.6, the highest possible player id value that can exist is 32. This is why you see arrays for players defined at 33 because the array index begins at 0 (0 to 32, total of 33 cells). The rules are different when working with dynamic arrays since you can resize on the fly.

Your code isn't terrible, I only changed a few things. Some of it was just for readability/organization.
Spoiler
__________________

Last edited by Bugsy; 09-22-2016 at 21:12.
Bugsy is offline