AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   nVault weird saving (https://forums.alliedmods.net/showthread.php?t=322376)

Shadows Adi 03-25-2020 08:39

nVault weird saving
 
Hello,
I made a plugin which is supposed to saving/loading players data from nVault (name saving data).
Code for saving data:
PHP Code:

SaveDATAid 

    new 
szName32 
    
get_user_nameidszNamecharsmaxszName ) ) 
    
    new 
szVaultKey128 ], szVaultData512 
    
    
formatexszVaultKey127"%s-/"szName 
    
formatexszVaultData511"%i %i %i %i %i %i %i %i"Data[id],Kills[id],Deaths[id],Shots[id],Damage[id],Hits[id],Rank[id], Skill[id]) 
    
nvault_setg_nVaultszVaultKeyszVaultData 


Code for loading data:
PHP Code:

LoadDATAid 

    new 
szName32 
    
get_user_nameidszNamecharsmaxszName ) ) 

    new 
szVaultKey128 ], szVaultData512 

    
formatexszVaultKey127"%s-/"szName 
    
formatexszVaultData511"%i %i %i %i %i %i %i %i"Data[id],Kills[id],Deaths[id],Shots[id],Damage[id],Hits[id],Rank[id], Skill[id]) 

    
nvault_getg_nVaultszVaultKeyszVaultData511 

    new 
did[32],dkills[32],ddeaths[32],dshots[32],ddamage[32],dhits[32],drank[32],dskill[32]

    
parseszVaultDatadid31,dkills31,ddeaths31dshots31ddamage31dhits31 ,drank31dskill31

    
Dataid ] = str_to_numdid)
    
Killsid ] = str_to_numdkills
    
Deaths[id] = str_to_numddeaths)
    
Shots[id] = str_to_numdshots)
    
Damage[id] = str_to_numddamage)
    
Hits[id] = str_to_numdhits)
    
Rank[id] = str_to_numdrank)
    
Skill[id] = str_to_numdskill)
    


The problem is that these data keep switching between players.
If I make saving on authid, it's everything ok, but I want to keep this name saving.

OciXCrom 03-25-2020 08:42

Re: nVault weird saving
 
What's the point of the "%s-/" ?

What do you mean by "switching between players"? If it doesn't save them correctly, you're passing in the wrong id. Show the full function calls.

Shadows Adi 03-25-2020 10:08

Re: nVault weird saving
 
Quote:

Originally Posted by OciXCrom (Post 2688477)
What's the point of the "%s-/" ?

What do you mean by "switching between players"? If it doesn't save them correctly, you're passing in the wrong id. Show the full function calls.

The "%s-/" is the name stored in the vault.
The data is stored correctly for about 4 days, then it is going crazy.
Ex:
Player Adi has 5 kills and 3 deaths.
Player Random has 2 kills and 10 deaths.
After about 4 days, the player Adi have 2 kills and 10 deaths, and the player Random have 5 kills and 3 deaths.

JusTGo 03-25-2020 10:16

Re: nVault weird saving
 
Quote:

Originally Posted by Shadows Adi (Post 2688495)
The "%s-/" is the name stored in the vault.
The data is stored correctly for about 4 days, then it is going crazy.
Ex:
Player Adi has 5 kills and 3 deaths.
Player Random has 2 kills and 10 deaths.
After about 4 days, the player Adi have 2 kills and 10 deaths, and the player Random have 5 kills and 3 deaths.

show the full code

Napoleon_be 03-25-2020 11:52

Re: nVault weird saving
 
This is a working example i made a few months ago, this has been posted before on the forums by myself and could easily been searched for. Here's the example you can use

PHP Code:

public client_disconnect(id)
{
    new 
szAuth[35], szTemp[60]; 
    
get_user_authid(idszAuthcharsmax(szAuth));
    
    
formatex(szTempcharsmax(szTemp), "%i %i %i"iPoints[id], iTsKilled[id], iCtKilled[id]);
    
    
nvault_set(szVaultNameszAuthszTemp);
}

public 
client_authorized(id)
{
    new 
szAuth[35], szTemp[20], szTsKills[5], szCtKills[5], szPoints[10];
    
get_user_authid(idszAuthcharsmax(szAuth));
    
    
nvault_get(szVaultNameszAuthszTempcharsmax(szTemp));
    
    
parse(szTempszPointscharsmax(szPoints), szTsKillscharsmax(szTsKills), szCtKillscharsmax(szCtKills));
    
    
iPoints[id] = str_to_num(szPoints);
    
iTsKilled[id] = str_to_num(szTsKills);
    
iCtKilled[id] = str_to_num(szCtKills);



iceeedr 03-25-2020 12:50

Re: nVault weird saving
 
PHP Code:

enum _:enData
{
    
Data,
    
Kills,
    
Deaths,
    
Shots,
    
Damage,
    
Hits,
    
Rank,
    
Skill
    PlayerName
[MAX_NAME_LENGTH],
}
new 
szVault
new GetAuth[MAX_PLAYERS 1][MAX_AUTHID_LENGTH]
new 
iData[MAX_PLAYERS 1][enData]

public 
plugin_init()
{
    
register_forward(FM_ClientUserInfoChanged"ClientUserInfoChanged")
}

public 
plugin_cfg()
{
    
szVault nvault_open("Mission_VAULT")
}

public 
plugin_end()
{
    
nvault_close(szVault)
}

public 
ClientUserInfoChanged(id)
{
    new 
szOldName[MAX_PLAYERS]
    
get_user_name(idszOldNamecharsmax(szOldName))

    if(
szOldName[0])
    {                   
        new 
szNewName[MAX_PLAYERS]
        
get_user_info(id"name"szNewNamecharsmax(szNewName))

        
set_user_info(id"name"szNewName)

        
copy(iData[id][PlayerName], charsmax(iData[]), szNewName)
        
SaveData(id)
    }
    
    return 
FMRES_SUPERCEDE
}

public 
client_authorized(id, const authid[])
{
    
get_user_authid(idGetAuth[id], MAX_AUTHID_LENGTH 1)
    
get_user_name(idiData[id][PlayerName], MAX_NAME_LENGTH 1)
    
LoadData(id)
}

public 
client_disconnected(id)
{
    
SaveData(id)
}

public 
example(id)
{
    
iData[id][Kills]++
}

public 
SaveData(const index)
{
    
nvault_set_array(szVault GetAuth[index], iDataindex ][enData:0], sizeofiData[] ) )
}

public 
LoadData(const index)
{
    
nvault_get_arrayszVault GetAuth[index] , iDataindex ][enData:0] , sizeofiData[] ))



Shadows Adi 03-25-2020 13:04

Re: nVault weird saving
 
I got it, but on authid it is working very well, when I change Vaul saving / loading on name it get bugged.

iceeedr 03-25-2020 13:06

Re: nVault weird saving
 
Quote:

Originally Posted by Shadows Adi (Post 2688520)
I got it, but on authid it is working very well, when I change Vaul saving / loading on name it get bugged.

It's a simple problem, use authid.

Shadows Adi 03-25-2020 13:48

Re: nVault weird saving
 
Quote:

Originally Posted by iceeedr (Post 2688521)
It's a simple problem, use authid.

I want to make it saving on name, because it's a top plugin, and players uses different names on the server.

iceeedr 03-25-2020 13:56

Re: nVault weird saving
 
Updated previous script, not tested.


All times are GMT -4. The time now is 00:45.

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