Raised This Month: $ Target: $400
 0% 

How can i save and load a string?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Zezima14
Member
Join Date: Feb 2010
Old 06-07-2010 , 15:01   How can i save and load a string?
Reply With Quote #1

How can i save and load a string?

Example.

PHP Code:
new Var1[32], Var2[32

Var1[id] = // is a string... 
Var2[id] = // too is a string...  

// Save... 
public Save(id)

    
fvault_set_data(g_fvaultVar1[id], Var2[id]) 


// Load... 
public Load(id)

     
// how can i here load the string? i will try with parse and copy, but i cant :'( 

ty all ;)
Zezima14 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 06-07-2010 , 17:23   Re: How can i save and load a string?
Reply With Quote #2

Var1[id] and Var2[id] are NOT strings.

Read this thread: http://forums.alliedmods.net/showthread.php?t=91207
__________________
fysiks is offline
Zezima14
Member
Join Date: Feb 2010
Old 06-11-2010 , 00:51   Re: How can i save and load a string?
Reply With Quote #3

Quote:
Originally Posted by fysiks View Post
Var1[id] and Var2[id] are NOT strings.

Read this thread: http://forums.alliedmods.net/showthread.php?t=91207
I know, I said the result of var1 is a string.

@thanks all.
Zezima14 is offline
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 06-07-2010 , 17:39   Re: How can i save and load a string?
Reply With Quote #4

Quote:
/**
* Retrieves data specified by a key
*
* @param vaultname Vault name to look in
* @param key Key name to look for the data
* @param data String which data will be copied to
* @param len Length of data
* @param timestamp The unix time of when the data was last set ( -1 if permanent data, 0 if old fvault version ) ( optional param )
* @return Returns 1 on success, 0 on failue.
*/
stock fvault_get_data(const vaultname[], const key[], data[], len, &timestamp=0)
PHP Code:
fvault_get_data(g_fvaultKEYNAMESTRINGSTRINGLEN
edit: I should probably do more than just post some copy-pasta, basically, STRING, is a variable with a length of STRINGLEN, so define a variable wherever you need this string (globally?) new string[128], then use fvault_get_data and STRING = string, and STRINGLEN = 128, there you go, that sum it up for ya?
__________________
+|- KARMA Respectively

HLM is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-07-2010 , 19:36   Re: How can i save and load a string?
Reply With Quote #5

I recommend reading the String section in the thread posted by fysiks.

Accessing a string within an array of strings and accessing a sub-string can look identical. It all depends on how the variable is defined.

Referencing a string with a supplied index ( Var1[ X ] ) can mean either:
1. You want to reference a full string within an array of strings
-- Works if the var is defined as Var1[ 33 ][ 50 ]
2. You want to access a sub-string within a single string.
-- Works if the var is defined as Var1[ 33 ]

Since you are specifying 'id' as your index I assume you are trying to store data on a per-player basis. To solve your problem, create an array of strings so each player has his own string to store info.

PHP Code:
new Var133 ][ 35 ]

//copy users name to the string array element 'id'
get_user_nameid Var1id ] , charsmaxVar1[] ) );
client_print( [...] , "hello %s" Var1id ] );

//copy "hello there" to the string array element 'id'
copyVar1id ] , charsmaxVar1[] ) , "hello there" ); 
__________________
Bugsy is offline
Alucard^
AMXX Moderator: Others
Join Date: Sep 2007
Location: Street
Old 06-07-2010 , 19:40   Re: How can i save and load a string?
Reply With Quote #6

Code:
#include <amxmodx> #define PLUGIN  "New Plugin" #define AUTHOR  "Alucard" #define VERSION "0.0.1" new String1[] = "hey yo, whats up"; new String2[] = "i am a little turtle"; public plugin_init() {     register_plugin(PLUGIN, VERSION, AUTHOR);         register_clcmd("say /save", "HookCmdSave");     register_clcmd("say /load", "HookCmdLoad"); } public HookCmdSave(id) {     new szText[192];     formatex(szText, 191, "^"%s^" ^"%s^"", String1, String2);         write_file(file[], szText);     return PLUGIN_HANDLED; } public HookCmdLoad(id) {     new szText[192], var1[64], var2[64], iLine, iLen;         while(read_file(file[], iLine++, szText, 191, iLen) )     {         parse(szText, var1, 63, var2, 63);         break;     }         client_print(id, print_chat, "%s", var1);     client_print(id, print_chat, "%s", var2);         return PLUGIN_HANDLED; }

Is just an example, need more code...

Sry for not use fvault, nvault or whatever, i never read nothing about that things.
__________________
Approved Plugins - Steam Profile

Public non-terminated projects:
All Admins Menu, HLTV parameters, Subnick,
Second Password (cool style), InfoZone,
Binary C4 plant/defuse, and more...

Private projects:
NoSpec (+menu), NV Surf Management,
PM Adanved System, KZ longjump2, and more...
Alucard^ is offline
Send a message via Skype™ to Alucard^
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 05:15.


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