Raised This Month: $51 Target: $400
 12% 

[HELP]How can I save.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ShLuMieL
Senior Member
Join Date: Jul 2010
Old 01-08-2014 , 11:40   [HELP]How can I save.
Reply With Quote #1

Hello to all.
I want to maker some plugin but I ain't got any idea how can I save fuction for player even he logs off.

I Helped with Exeloet tutorial about save&load (fvault).

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <fvault>

#define PLUGIN "New Plug-In"
#define VERSION "1.0"
#define AUTHOR "AUTHOR"

new const g_vault_name[] = "Health-Saver";

new 
gXP[33];

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
// Add your code here...
    
register_clcmd("say /heal""Menu")
}

public 
Menu(id)
{
    new 
szItem[256]
    
    
formatex(szItemcharsmax(szItem), "\w[ \rMenu \w] \yMain Menu:")
    new 
menu menu_create(szItem"Menu_Handler"
    
    
menu_additem(menu"Item1"""0);
    
menu_display(idmenu0);
    
    return 
PLUGIN_HANDLED;
}

public 
Menu_Handler(iditem)
{
    switch(
item)
    {
        case 
0:
        {
            
set_user_health(id155)
        }
    }
    
    return 
PLUGIN_HANDLED;
}

// Save & Load.
public LoadHealth(id)
{
    new 
authid[35];
    
get_user_authid(idauthidsizeof(authid) - 1);
    
    new 
data[16];
    if( 
fvault_get_data(g_vault_nameauthiddatasizeof(data) - 1) )
    {
        
gXP[id] = str_to_num(data);
    }
    else
    {
        
gXP[id] = 0;
    }
}

public 
SaveHealth(id)
{
    new 
authid[35];
    
get_user_authid(idauthidsizeof(authid) - 1);
    
    new 
data[16];
    
num_to_str(gXP[id], datasizeof(data) - 1);
    
    
fvault_set_data(g_vault_nameauthiddata);

if I want to save the 'Health' for someplayer, if he take 'Item 1' his health allway will stay 155, how can I add it in fvault? can it possible?

Thank's.

Last edited by ShLuMieL; 01-08-2014 at 11:41.
ShLuMieL is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 01-08-2014 , 11:51   Re: [HELP]How can I save.
Reply With Quote #2

Use client_disconnect and tell it to save in there.
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
ShLuMieL
Senior Member
Join Date: Jul 2010
Old 01-08-2014 , 12:45   Re: [HELP]How can I save.
Reply With Quote #3

Quote:
Originally Posted by YamiKaitou View Post
Use client_disconnect and tell it to save in there.
Uh ?
ShLuMieL is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 01-08-2014 , 14:16   Re: [HELP]How can I save.
Reply With Quote #4

Quote:
Originally Posted by ShLuMieL View Post
Uh ?
What don't you understand?
__________________
fysiks is offline
waza123a
Member
Join Date: Mar 2010
Old 01-09-2014 , 04:23   Re: [HELP]How can I save.
Reply With Quote #5

PHP Code:
public client_disconnect(id){
   
SaveHealth(id);


Last edited by waza123a; 01-09-2014 at 04:25.
waza123a is offline
ShLuMieL
Senior Member
Join Date: Jul 2010
Old 01-09-2014 , 04:39   Re: [HELP]How can I save.
Reply With Quote #6

But how can I save the set_user_health
Even the server crash and return he will get his same health as like the plugin
ShLuMieL is offline
waza123a
Member
Join Date: Mar 2010
Old 01-09-2014 , 04:46   Re: [HELP]How can I save.
Reply With Quote #7

PHP Code:

// in plugin init
RegisterHamHam_Spawn"player""FwdHamPlayerSpawn");


public 
FwdHamPlayerSpawn( const id ) {
    if(
is_user_alive(id)) {
  
LoadHealth(id);
}
}


    public 
client_putinserverid )
    {
        
set_task(1.0"SaveHealth"6767+id);
    }

public 
client_disconnect(id){
    
remove_task(6767 id);
}


public 
SaveHealth(id)
{
    if(!
is_user_alive(id)) return PLUGIN_HANDLED;

    new 
authid[35];
    
get_user_authid(idauthidsizeof(authid) - 1);
    
    new 
data[16];
    
num_to_str(gXP[id], datasizeof(data) - 1);
    
    
fvault_set_data(g_vault_nameauthiddata);

__________________
Life is good, sometimes...

Last edited by waza123a; 01-09-2014 at 04:55.
waza123a 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 17:21.


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