Thread: nVault Tutorial
View Single Post
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 09-24-2016 , 05:59   Re: nVault Tutorial
Reply With Quote #85

Quote:
Originally Posted by Bugsy View Post
@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])
}
You're right. I was wrong.

It was my intention to do it that way. i just didn't test it properly.
I do understand that converting it back is no use and in that case it's much better storing the string in the global array.
I would however remove "STEAM_" from it. I'm not saying everyone has to do so.

I used this code and figured it worked but of course the key is interpret in the same way even if it's not supported in that format and the data will be retrieved correctly.
Code:
#include <amxmodx> #include <amxmodx> #include <nvault> public plugin_init() {     register_plugin("Test Plugin 1", "1.0", "[ --{-@ ]");     new key[] = {2147483647, 0};     new val[] = {127, 0};     new nVault = nvault_open("test");     nvault_set(nVault, key, val);     new temp[10];     nvault_get(nVault, key, temp, charsmax(temp));     server_print("key: %d, val: %d", key[0], temp[0]);     nvault_close(nVault); }
Code:
key: 2147483647, val: 127
Works great with SQL though.
__________________

Last edited by Black Rose; 09-24-2016 at 06:02.
Black Rose is offline