AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Nvault (https://forums.alliedmods.net/showthread.php?t=155956)

Groven 04-28-2011 16:57

Nvault
 
Hello,

Why does my plugin reset my rank every new map?

If i got 12/25 points it goes to 0 next map.

PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <nvault>

#define IsPlayer(%1)  (1 <= %1 <= g_players) 
#define TOTALLEVELS 12

//Cash Natives
native cm_get_user_cash(id);

native cm_set_user_cash(idcm);

//Cash Natives end

new const RANK[TOTALLEVELS] = 
{
 
25,
 
50
 
100,
 
200,
 
300,
 
500,
 
750,
 
1000,
 
1250,
 
1500,
 
1750,
 
2000,
}

new const 
CM[TOTALLEVELS] = 
{
 
50
 
100,
 
150,
 
200,
 
300,
 
1000,
 
1200,
 
1300,
 
1400,
 
1500,
 
2500,
 
20000
}

new const 
RANKNAMES[TOTALLEVELS][] =
{
 
"New player",
 
"Beginner",
 
"Learning",
 
"Knifer",
 
"Rambo with knife",
 
"Butcher",
 
"Matrix",
 
"Diiiirrrge",
 
"Freak with Knife",
 
"Chuck Norris",
 
"Kill Bill",
 
"Respected Player"
}

new 
gCM[33], gLevel[33];
new 
points_killpoints_hs;
new 
g_vaultg_players;

public 
plugin_init()
{
    
register_plugin("HideNSeek Rank""1.2""ETTAN");
 
    
register_event("DeathMsg""eDeath""a");
 
    
points_kill register_cvar("hnsrank_kill""1");
    
points_hs register_cvar("hnsrank_hs","1");
    
g_vault nvault_open("HNSRANK");
    
g_players get_maxplayers();
    
    
register_clcmd("say /rank""ShowHud");
    
register_clcmd("say_team /rank""ShowHud");
}

public 
plugin_end()
{
    
nvault_close(g_vault);
}

public 
eDeath() 
{
    new 
killer read_data(1);
    new 
victim read_data(2);
    new 
gpoints_kill get_pcvar_num(points_kill);
    new 
gpoints_hs get_pcvar_num(points_hs);
 
    if( 
IsPlayer(killer) && is_user_connected(killer) )
    {
        if( 
victim != killer )
        {
            if( 
cs_get_user_team(victim) != cs_get_user_team(killer) )
            {
                if( 
is_user_alive(killer) )
                {                    
                    if(!
read_data(3))
                    {
                        
gCM[killer] += gpoints_kill
                        
Print(killer"You gained %d Points!"gpoints_kill );
                    }
                    else if(
read_data(3))
                    {
                        
gCM[killer] += (gpoints_kill gpoints_hs);
                        Print(
killer"You gained %d Points!^x01 (Headshot)", (gpoints_hs gpoints_kill ) );
                    }
    
                    
CheckLevel(killer);
                    
SaveData(killer);
                }
            }
        }
    }
    
    return 
PLUGIN_HANDLED;
}

public 
CheckLevel(id)
{
    if( 
gCM[id] >= RANK[gLevel[id]] )
    {
        
gLevel[id]++;
        new 
szName[33];
        
get_user_name(idszNamecharsmax(szName));
        Print(
0"Congratulations to^3 %s^1! Person is now [Lvl:^3 %i^1/%i] with title^3 %s^1!"szNamegLevel[id], TOTALLEVELSRANKNAMES[gLevel[id]-1]);
        Print(
0"^3%s^1 was rewarded^3 %i^1 Money for leveling up!"szNameCM[gLevel[id]]);
        
cm_set_user_cashidCM[gLevel[id]-1] );
    }
}

public 
ShowHud(id)
{
    new 
iLevelName[100];
    if( 
gLevel[id] > )
    {
        
formatex(iLevelNamecharsmax(iLevelName), "%s"RANKNAMES[gLevel[id]]);
    }
    else 
    {
        
formatex(iLevelNamecharsmax(iLevelName), "Unranked");
    }
    
    new 
szName[33];
    
get_user_name(idszNamecharsmax(szName));
    Print(
0"^3%s^1 has:^3 %d/%d Points^1! Title:^3 %s^1!"szNamegCM[id], RANK[gLevel[id]], iLevelName);
}

public 
client_connect(id)
{
    
LoadData(id);
}

public 
client_disconnect(id)
{
    
SaveData(id);
    
gCM[id] = 0;
    
gLevel[id] = 0;
}

public 
SaveData(id)
{
    new 
AuthID[35];
    
get_user_authid(id,AuthID,34);

    new 
vaultkey[64],vaultdata[256];
    
format(vaultkey,63,"%s-EG"AuthID);
    
format(vaultdata,255,"%i#%i#",gCM[id],gLevel[id]);
    
nvault_set(g_vault,vaultkey,vaultdata);
    return 
PLUGIN_CONTINUE;
}

LoadData(id)
{
    new 
AuthID[35];
    
get_user_authid(id,AuthID,34);

    new 
vaultkey[64],vaultdata[256];
    
format(vaultkey,63,"%s-EG",AuthID);
    
format(vaultdata,255,"%i#%i#",gCM[id],gLevel[id]);
    
nvault_get(g_vault,vaultkey,vaultdata,255);

    
replace_all(vaultdata255"#"" ");

    new 
playercm[32], playerlevel[32];

    
parse(vaultdataplayercm31playerlevel31);

    
gCM[id] = str_to_num(playercm);
    
gLevel[id] = str_to_num(playerlevel);

    return 
PLUGIN_CONTINUE;

}

Print(
iPlayer, const sMsg[], any:...)
{
    static 
iiPlayer iPlayer get_Player();
    if ( !
) return;
    
    new 
sMessage[256];
    new 
len formatex(sMessagesizeof(sMessage) - 1"^x04[Cool-Gaming] HideNSeek Rank:^x03 ");
    
vformat(sMessage[len], sizeof(sMessage) - lensMsg3);
    
sMessage[192] = '^0';
        
    static 
msgid_SayText;
    if ( !
msgid_SayText msgid_SayText get_user_msgid("SayText");
    
    new const 
team_Names[][] =
    {
        
"",
        
"TERRORIST",
        
"CT",
        
"SPECTATOR"
    
};
        
    new 
sTeam get_user_team(i);
    
    
team_Info(iiPlayerteam_Names[0]);
        
    
message_begin(iPlayer MSG_ONE_UNRELIABLE MSG_BROADCASTmsgid_SayText_iPlayer);
    
write_byte(i);
    
write_string(sMessage);
    
message_end();
        
    
team_Info(iiPlayerteam_Names[sTeam]);
}

team_Info(receiversendersTeam[])
{
    static 
msgid_TeamInfo;
    if ( !
msgid_TeamInfo msgid_TeamInfo get_user_msgid("TeamInfo");
    
    
message_begin(sender MSG_ONE_UNRELIABLE MSG_BROADCASTmsgid_TeamInfo_sender);
    
write_byte(receiver);
    
write_string(sTeam);
    
message_end();
}

get_Player()
{
    for ( new 
iPlayer 1iPlayer <= get_maxplayers(); iPlayer++ )
    {
        return 
iPlayer;
    }
    
    return 
0;



Nyuszy 04-28-2011 17:38

Re: Nvault
 
client_disconnect is called when the player was left the server, sou you can't get his authid. but you can save data in eDeath()

Groven 04-28-2011 17:42

Re: Nvault
 
Thanks!

Can you fix it for me?

This is not my code.

Exolent[jNr] 04-28-2011 21:48

Re: Nvault
 
Quote:

Originally Posted by Nyuszy (Post 1459775)
client_disconnect is called when the player was left the server, sou you can't get his authid. but you can save data in eDeath()

That's not true. You can still get player's authid in that forward.
However, saving the data in eDeath() (and anywhere else that the saved data changes) should be sufficient.

Bugsy 04-28-2011 23:29

Re: Nvault
 
Quote:

Originally Posted by Exolent[jNr] (Post 1459858)
That's not true. You can still get player's authid in that forward.
However, saving the data in eDeath() (and anywhere else that the saved data changes) should be sufficient.

I've had mixed results with retrieving player data at client_disconnect. It will usually work while you test things yourself but when the plugin is left running I would get occasional errors, I assume because it sometimes gets called after the player is gone. Because of this I no longer call anything on a player at client_disconnect.

kNowo 04-29-2011 06:52

Re: Nvault
 
i had an error when a plugin tried to retrieve player data on client_disconnect and during mapchange. is this normal?

Groven 04-29-2011 07:55

Re: Nvault
 
The plugin saves now.

But i am using CashMod so when i reach a level my cash reset to 0 when it is supposed to give me 50 cash more for level 1.

Why?

StepZeN 03-02-2012 19:46

Re: Nvault
 
Quote:

Originally Posted by Groven (Post 1460024)
The plugin saves now.

But i am using CashMod so when i reach a level my cash reset to 0 when it is supposed to give me 50 cash more for level 1.

Why?

yeah.... you have wrong natives....


All times are GMT -4. The time now is 04:17.

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