AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   nvault save & loading (https://forums.alliedmods.net/showthread.php?t=272928)

ironskillz1 10-09-2015 13:20

nvault save & loading
 
Okay so i made this saving & loading but it seems to cut off the first letter in both steamid and name.
Anyone knows why?

Code:

SnusMumrikeN :  /load

nusMumrikeN TEAM_0:0:38415370

Code:

#include <amxmodx>
#include <nvault>
#include <colorchat>

#define PLUGIN "test save & load"
#define VERSION "1.0"
#define AUTHOR "ironskillz1"

new g_vault

public plugin_init() {
        register_plugin(PLUGIN, VERSION, AUTHOR)
       
        register_clcmd("say /save", "SaveData")
        register_clcmd("say /load", "LoadData")
        g_vault = nvault_open("test")
}

public SaveData(id)
{
        new vaultkey[33], name[33]
        get_user_authid(id, vaultkey, charsmax(vaultkey))
        get_user_name(id, name, charsmax(name))

        new vaultdata[256]
        formatex(vaultdata, charsmax(vaultdata), "%s %s", name[id], vaultkey[id])
        nvault_set(g_vault, vaultkey, vaultdata)
}

public LoadData(id)
{
        new vaultkey[33]
        get_user_authid(id, vaultkey, charsmax(vaultkey))

        new vaultdata[256]
        nvault_get(g_vault, vaultkey, vaultdata, charsmax(vaultdata))

        new name[33], steamid[33]
        parse(vaultdata, name, charsmax(name), steamid, charsmax(steamid))

        ColorChat( 0, GREY, "%s %s", name, steamid);
}


redivcram 10-09-2015 13:30

Re: nvault save & loading
 
What is ColorChat doing inside LoadData? And why? You could've also used a custom value...

HamletEagle 10-09-2015 13:42

Re: nvault save & loading
 
Code:

new vaultkey[32], name[32]
formatex(vaultdata, charsmax(vaultdata), "%s %s", name, vaultkey)

The problem was that you were using [id], this specifies the cell from where to start, but you want to start from the beginning. Here using "id" is wrong, you don't have a bi-dimensional array. Probably you were testing alone, so your index was 1, and it become name[1], which cut the first char.
Also instead of 33 you can use 32, that's the max chars a name can have.

@redivcram, why do you keep posting if you can't help ?

Bugsy 10-10-2015 11:02

Re: nvault save & loading
 
@ironskillz1, it appears your plugin is just for testing purposes but I want to throw this out there anyway just in case: you want to avoid saving data linked to a persons name as this can change. Use only the steam id, and if you need to have multiple vault entries for a single player you can add data to the key, ie. STEAM_0:0:12345_MONEY, STEAM_0:0:12345_XP, etc. You can also try the new nvault utility functions that allow saving arrays.


All times are GMT -4. The time now is 22:14.

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