AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [HELP]How can I save. (https://forums.alliedmods.net/showthread.php?t=233014)

ShLuMieL 01-08-2014 11:40

[HELP]How can I save.
 
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.

YamiKaitou 01-08-2014 11:51

Re: [HELP]How can I save.
 
Use client_disconnect and tell it to save in there.

ShLuMieL 01-08-2014 12:45

Re: [HELP]How can I save.
 
Quote:

Originally Posted by YamiKaitou (Post 2083015)
Use client_disconnect and tell it to save in there.

Uh ?

fysiks 01-08-2014 14:16

Re: [HELP]How can I save.
 
Quote:

Originally Posted by ShLuMieL (Post 2083032)
Uh ?

What don't you understand?

waza123a 01-09-2014 04:23

Re: [HELP]How can I save.
 
PHP Code:

public client_disconnect(id){
   
SaveHealth(id);



ShLuMieL 01-09-2014 04:39

Re: [HELP]How can I save.
 
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

waza123a 01-09-2014 04:46

Re: [HELP]How can I save.
 
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);




All times are GMT -4. The time now is 10:13.

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