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

nvault save & loading


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ironskillz1
AlliedModders Donor
Join Date: Jul 2012
Location: Sweden
Old 10-09-2015 , 13:20   nvault save & loading
Reply With Quote #1

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);
}
__________________
I have many private and unique plugins for Jailbreak and Hide'N'Seek. PM me for more info.

Pm me.

Check out my roulette site.
ironskillz1 is offline
Send a message via Skype™ to ironskillz1
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 10-09-2015 , 13:30   Re: nvault save & loading
Reply With Quote #2

What is ColorChat doing inside LoadData? And why? You could've also used a custom value...
redivcram is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 10-09-2015 , 13:42   Re: nvault save & loading
Reply With Quote #3

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 ?
__________________

Last edited by HamletEagle; 10-09-2015 at 13:43.
HamletEagle is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-10-2015 , 11:02   Re: nvault save & loading
Reply With Quote #4

@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.
__________________
Bugsy 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 06:40.


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