Raised This Month: $ Target: $400
 0% 

Some problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Podarok
BANNED
Join Date: Jan 2011
Location: Narnia
Old 04-18-2013 , 03:21   Some problem
Reply With Quote #1

Hello guys. At first I want to apologise to ALL alliedmodders members, these trollings about layka_lubii werent actually mine and yeah, sorry guys.
So, here is my problem, this is a plugin, which saves users ammo packs, when server crashes - everyone has 0 ammo packs, which is wierd, they should have normal amout of ammo packs...
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <zombieplague>
#include <nvault>

#define PLUGIN    "[ZP] Can Auto Save Ammo"
#define VERSION    "0.1.0"
#define AUTHOR    "cosi"

new g_saveg_ammo[33], g_ammo_can_save[33]
new 
cvar_save_in

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
register_event("DeathMsg","event_deathmsg","a")
    
register_forward(FM_PlayerPreThink"fw_PlayerPreThink")

    
cvar_save_in register_cvar("zp_ammo_save_in""2")            // 0 = name / 1 = ip / 2 = steam id

    
g_save nvault_open("g_ammo_save")
}

// Save Ammo
public zp_user_infected_post(idinfector)
{
    if (
g_ammo_can_save[infector])
        
Save_Ammo_date(infector)
    
    if (
g_ammo_can_save[id])
        
Save_Ammo_date(id)
}

public 
zp_extra_item_selected(iditemid)
{
    if (
g_ammo_can_save[id])
        
Save_Ammo_date(id)
}

public 
event_deathmsg()
{
    new 
killer read_data(1)
    new 
victim read_data(2)

    if (!
killer && !victim)
        return 
PLUGIN_CONTINUE;

    if (
g_ammo_can_save[killer])
        
Save_Ammo_date(killer)
            
    if (
g_ammo_can_save[victim])
        
Save_Ammo_date(victim)

    return 
PLUGIN_CONTINUE;
}

public 
fw_PlayerPreThink(id)
{
    if (
g_ammo_can_save[id])
    {
        new 
ammo_packs zp_get_user_ammo_packs(id)
        
g_ammo[id] = ammo_packs
    
}

    return 
FMRES_IGNORED;
}

public 
client_disconnect(id)
{
    if(
g_ammo_can_save[id])
        
Save_Ammo_date(id)
}

public 
client_putinserver(id)
    
set_task(2.0"now_can_save"id)

public 
now_can_save(id)
{
    
Load_Ammo_date(id)
    
set_task(0.5"can_save_true"id)
}

public 
can_save_true(id)
    
g_ammo_can_save[id] = true

public Save_Ammo_date(id)
{
    new 
vaultkey[64], vaultdata[256]

    switch (
get_pcvar_num(cvar_save_in))
    {
        case 
0:
        {
            new 
name[33];
            
get_user_name(id,name,32)
            
            
format(vaultkey63"%s-/"name)
        }
        case 
1:
        {
            new 
player_ip[33]
            
get_user_ip(idplayer_ip32);

            
format(vaultkey63"%s-/"player_ip)
        }
        case 
2:
        {
            new 
AuthID[33];
            
get_user_authid(idAuthID32);
            
            
formatex(vaultkey64"%s-/"AuthID);
        }
    }

    
format(vaultdata255"%i#"g_ammo[id])
    
    
nvault_set(g_savevaultkeyvaultdata)
    return 
PLUGIN_CONTINUE;
}

public 
Load_Ammo_date(id)
{
    new 
vaultkey[64], vaultdata[256]

    switch (
get_pcvar_num(cvar_save_in))
    {
        case 
0:
        {
            new 
name[33];
            
get_user_name(id,name,32)
            
            
format(vaultkey63"%s-/"name)
        }
        case 
1:
        {
            new 
player_ip[33]
            
get_user_ip(idplayer_ip32);

            
format(vaultkey63"%s-/"player_ip)
        }
        case 
2:
        {
            new 
AuthID[33];
            
get_user_authid(idAuthID32);
            
            
formatex(vaultkey64"%s-/"AuthID);
        }
    }

    
format(vaultdata255"%i#"g_ammo[id])
    
    
nvault_get(g_savevaultkeyvaultdata255)
    
replace_all(vaultdata255"#"" ")
    
    new 
playammo[32]
    
parse(vaultdataplayammo31)
    
g_ammo[id] = str_to_num(playammo)
    
    
set_ammo(id)
    
    return 
PLUGIN_CONTINUE;
}

public 
set_ammo(id)
{
    
zp_set_user_ammo_packs(idg_ammo[id])
    

Podarok is offline
EpicMonkey
buttmonkey
Join Date: Feb 2012
Old 04-18-2013 , 03:51   Re: Some problem
Reply With Quote #2

Read: https://forums.alliedmods.net/showthread.php?t=180342
EpicMonkey is offline
Podarok
BANNED
Join Date: Jan 2011
Location: Narnia
Old 04-18-2013 , 03:54   Re: Some problem
Reply With Quote #3

Thanks i have got it, but how can I close nvault. Could u please provide an example to my code?
Podarok is offline
EpicMonkey
buttmonkey
Join Date: Feb 2012
Old 04-18-2013 , 04:08   Re: Some problem
Reply With Quote #4

Take a look at the saving and loading part: https://forums.alliedmods.net/showpo...02&postcount=6
EpicMonkey is offline
Podarok
BANNED
Join Date: Jan 2011
Location: Narnia
Old 04-18-2013 , 09:09   Re: Some problem
Reply With Quote #5

Ammos not saving now and im getting an error...
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <zombieplague>
#include <nvault>

#define PLUGIN    "[ZP] Can Auto Save Ammo"
#define VERSION    "0.1.0"
#define AUTHOR    "cosi"

new g_saveg_ammo[33], g_ammo_can_save[33]
new 
cvar_save_in

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)

    
register_event("DeathMsg","event_deathmsg","a")
    
register_forward(FM_PlayerPreThink"fw_PlayerPreThink")

    
cvar_save_in register_cvar("zp_ammo_save_in""2")            // 0 = name / 1 = ip / 2 = steam id

    
g_save nvault_open("g_ammo_save")
}

// Save Ammo
public zp_user_infected_post(idinfector)
{
    if (
g_ammo_can_save[infector])
        
Save_Ammo_date(infector)
    
    if (
g_ammo_can_save[id])
        
Save_Ammo_date(id)
}

public 
zp_extra_item_selected(iditemid)
{
    if (
g_ammo_can_save[id])
        
Save_Ammo_date(id)
}

public 
event_deathmsg()
{
    new 
killer read_data(1)
    new 
victim read_data(2)

    if (!
killer && !victim)
        return 
PLUGIN_CONTINUE;

    if (
g_ammo_can_save[killer])
        
Save_Ammo_date(killer)
            
    if (
g_ammo_can_save[victim])
        
Save_Ammo_date(victim)

    return 
PLUGIN_CONTINUE;
}

public 
fw_PlayerPreThink(id)
{
    if (
g_ammo_can_save[id])
    {
        new 
ammo_packs zp_get_user_ammo_packs(id)
        
g_ammo[id] = ammo_packs
    
}

    return 
FMRES_IGNORED;
}

public 
client_disconnect(id)
{
    if(
g_ammo_can_save[id])
        
Save_Ammo_date(id)
}

public 
client_putinserver(id)
    
set_task(2.0"now_can_save"id)

public 
now_can_save(id)
{
    
Load_Ammo_date(id)
    
set_task(0.5"can_save_true"id)
}

public 
can_save_true(id)
    
g_ammo_can_save[id] = true

public Save_Ammo_date(id)
{
    new 
vaultkey[64], vaultdata[256]

    switch (
get_pcvar_num(cvar_save_in))
    {
        case 
0:
        {
            new 
name[33];
            
get_user_name(id,name,32)
            
            
format(vaultkey63"%s-/"name)
        }
        case 
1:
        {
            new 
player_ip[33]
            
get_user_ip(idplayer_ip32);

            
format(vaultkey63"%s-/"player_ip)
        }
        case 
2:
        {
            new 
AuthID[33];
            
get_user_authid(idAuthID32);
            
            
formatex(vaultkey64"%s-/"AuthID);
        }
    }

    
format(vaultdata255"%i#"g_ammo[id])
    
    
nvault_set(g_savevaultkeyvaultdata)
    
nvault_close(g_save)
    return 
PLUGIN_CONTINUE;
}

public 
Load_Ammo_date(id)
{
    new 
vaultkey[64], vaultdata[256]

    switch (
get_pcvar_num(cvar_save_in))
    {
        case 
0:
        {
            new 
name[33];
            
get_user_name(id,name,32)
            
            
format(vaultkey63"%s-/"name)
        }
        case 
1:
        {
            new 
player_ip[33]
            
get_user_ip(idplayer_ip32);

            
format(vaultkey63"%s-/"player_ip)
        }
        case 
2:
        {
            new 
AuthID[33];
            
get_user_authid(idAuthID32);
            
            
formatex(vaultkey64"%s-/"AuthID);
        }
    }

    
format(vaultdata255"%i#"g_ammo[id])
    
    
nvault_get(g_savevaultkeyvaultdata255)
    
replace_all(vaultdata255"#"" ")
    
    new 
playammo[32]
    
parse(vaultdataplayammo31)
    
g_ammo[id] = str_to_num(playammo)
    
    
set_ammo(id)
    
    
nvault_close(g_save)
    
    return 
PLUGIN_CONTINUE;
}

public 
set_ammo(id)
{
    
zp_set_user_ammo_packs(idg_ammo[id])
    

Error :
Code:
L 04/18/2013 - 16:07:40: [AMXX] Displaying debug trace (plugin "zp_save_ammo.amxx") L 04/18/2013 - 16:07:40: [AMXX] Run time error 10: native error (native "nvault_set") L 04/18/2013 - 16:07:40: [AMXX]    [0] zp_save_ammo.sma::Save_Ammo_date (line 118) L 04/18/2013 - 16:07:40: [AMXX]    [1] zp_save_ammo.sma::event_deathmsg (line 50) L 04/18/2013 - 16:08:22: [CSTRIKE] Player out of range (0) L 04/18/2013 - 16:08:22: [AMXX] Run time error 10 (plugin "zp50_admin_commands.amxx") (native "cs_get_user_team") - debug not enabled! L 04/18/2013 - 16:08:22: [AMXX] To enable debug mode, add "debug" after the plugin name in plugins.ini (without quotes). L 04/18/2013 - 16:09:02: [nVault] Invalid vault id: 0 L 04/18/2013 - 16:09:02: [AMXX] Displaying debug trace (plugin "zp_save_ammo.amxx") L 04/18/2013 - 16:09:02: [AMXX] Run time error 10: native error (native "nvault_get") L 04/18/2013 - 16:09:02: [AMXX]    [0] zp_save_ammo.sma::Load_Ammo_date (line 154) L 04/18/2013 - 16:09:02: [AMXX]    [1] zp_save_ammo.sma::now_can_save (line 80)

Last edited by Podarok; 04-18-2013 at 09:44.
Podarok is offline
EpicMonkey
buttmonkey
Join Date: Feb 2012
Old 04-18-2013 , 11:01   Re: Some problem
Reply With Quote #6

Open 'AND' close it while saving / loading

PHP Code:
public plugin_init() 

    
register_plugin(PLUGINVERSIONAUTHOR

    
register_event("DeathMsg","event_deathmsg","a"
    
register_forward(FM_PlayerPreThink"fw_PlayerPreThink"

    
cvar_save_in register_cvar("zp_ammo_save_in""2")            // 0 = name / 1 = ip / 2 = steam id 

    //g_save = nvault_open("g_ammo_save") <<--- No


Last edited by EpicMonkey; 04-18-2013 at 11:01.
EpicMonkey is offline
Podarok
BANNED
Join Date: Jan 2011
Location: Narnia
Old 04-18-2013 , 14:35   Re: Some problem
Reply With Quote #7

Thanks a lot. Havent tested its functionality on server crashes, hope it works.
Podarok 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 10:45.


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