AlliedModders

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

ironskillz1 10-15-2015 10:30

nvault problems
 
Hello i got some nvault problems.
So i been working on this plugin which makes so you can marry other people on the server.

The saving works great it saves the users SteamID and the user steamid + name he is married. The thing that is not working is the loading part. It works whenever you are alone in the server or with other people you are not married to.

But when the guy/girl you are married to joins the server the plugin will loads my marriage + theirs marriage information. I just want it just to load their marriage information.
When it loads my marriage information too it messes up the names. How could i solve this?


This is the nvault code im currently using.
Code:


When someone gets married i save it like this
        SaveData( id, g_iPlayer[id]);
        SaveData( g_iPlayer[id], id );

public client_disconnect(id)
{
        if(g_iMarriedSteamID[id] != 0 )
                UpdateName(id)
}
       
public client_putinserver(id)
        LoadData(id)


public UpdateName(id)
{       
        new szSteamID[32], szName[32]
        get_user_authid(id, szSteamID, charsmax(szSteamID))
        get_user_name(id, szName, charsmax(szName))
       
        formatex(g_VaultData, charsmax(g_VaultData), "%s %s", szSteamID, szName)
        nvault_set(g_Vault, g_iMarriedSteamID[id], g_VaultData)

        return PLUGIN_HANDLED
}
public SaveData(id, id2)
{
        new szSteamID[32], szName[32], szName2[32], szSteamID2[32]
        get_user_authid(id, szSteamID, charsmax(szSteamID))
        get_user_authid(id2, szSteamID2, charsmax(szSteamID2))
       
        get_user_name(id, szName, charsmax(szName))
        get_user_name(id2, szName2, charsmax(szName2))
       
        copy(g_iMarriedSteamID[id2], 32, szSteamID)
        copy(g_iMarriedName[id2], 32, szName)
       
        copy(g_iMarriedSteamID[id], 32, szSteamID2)
        copy(g_iMarriedName[id], 32, szName2)

        formatex(g_VaultData, charsmax(g_VaultData), "%s %s", szSteamID2, szName2)
        nvault_set(g_Vault, szSteamID, g_VaultData)
       
        server_print("SAVE steamid: %s. Marriedsteamid: %s marriedname: %s", szSteamID, g_iMarriedSteamID[id], g_iMarriedName[id])
}
public LoadData(id)
{
        new szSteamID[32]
        get_user_authid(id, szSteamID, charsmax(szSteamID))
       
        new iTimeStamp
        if(!nvault_lookup(g_Vault, szSteamID, g_VaultData, charsmax(g_VaultData), iTimeStamp) )
                return PLUGIN_HANDLED

        new MarriedSteamID[32], MarriedName[32]
        nvault_get(g_Vault, szSteamID, g_VaultData, charsmax(g_VaultData))
        parse(g_VaultData, MarriedSteamID, charsmax(MarriedSteamID), MarriedName, charsmax(MarriedName))
       
        copy(g_iMarriedSteamID[id], 32, MarriedSteamID)
        copy(g_iMarriedName[id], 32, MarriedName)
       
        server_print("LOAD steamid: %s. Marriedsteamid: %s marriedname: %s", szSteamID, g_iMarriedSteamID[id], g_iMarriedName[id])
       
        return PLUGIN_HANDLED
}

Ps. I dont want to switch to SQL

Bugsy 10-15-2015 20:46

Re: nvault problems
 
Is this along the lines of what you're trying to do?
Code:

key="STEAM_0:0:12345"  data="STEAM_0:0:98765 bugsy"
key="STEAM_0:0:98765"  data="STEAM_0:0:12345 bugsys wife"


ironskillz1 10-16-2015 01:09

Re: nvault problems
 
Quote:

Originally Posted by Bugsy (Post 2353480)
Is this along the lines of what you're trying to do?
Code:

key="STEAM_0:0:12345"  data="STEAM_0:0:98765 bugsy"
key="STEAM_0:0:98765"  data="STEAM_0:0:12345 bugsys wife"


Yes

Bugsy 10-16-2015 18:55

Re: nvault problems
 
Quote:

Originally Posted by ironskillz1 (Post 2353522)
Yes

You should cache the players steamid in a global variable @ client_authorized(). I would also organize the data using an enum, something like the below, for example.
PHP Code:

enum MarriedData
{
    
szSteamID34 ],
    
szSpouseSteamID34 ],
    
szSpouseName33 ]
}
new 
g_mdDataMAX_PLAYERS ][ MarriedData 

I didn't look through your entire plugin, but I can tell that your loading/saving was wrong. Hopefully this solves it.

Untested:
PHP Code:

public UpdateNameid )
{
    new 
szName33 ] , szAuthID34 ] , szBuffer66 ];
    
    
get_user_nameid szName charsmaxszName ) );
    
get_user_authidid szAuthID charsmaxszAuthID ) );
    
    
formatexszBuffer charsmaxszBuffer ) , "%s ^"%s^"" szAuthID szName );
    
nvault_setg_Vault g_iMarriedSteamIDid ] , szBuffer ); 
}

public 
SaveDataid1 id2 )
{
    
//ID1 : KEY=[ID1_STEAMID] DATA=[ID2_STEAMID "ID2_NAME"]
    //ID2 : KEY=[ID2_STEAMID] DATA=[ID1_STEAMID "ID1_NAME"]
    
    
new szName][ 32 ] , szAuthID][ 34 ] , szBuffer66 ];
    
    
get_user_nameid1 szName] , charsmaxszName[] ) );
    
get_user_nameid2 szName] , charsmaxszName[] ) );
    
    
get_user_authidid1 szAuthID] , charsmaxszAuthID[] ) );
    
get_user_authidid2 szAuthID] , charsmaxszAuthID[] ) );
    
    
formatexszBuffer charsmaxszBuffer ) , "%s ^"%s^"" szAuthID] , szName] );
    
nvault_setg_Vault szAuthID] , szBuffer );

    
formatexszBuffer charsmaxszBuffer ) , "%s ^"%s^"" szAuthID] , szName] );
    
nvault_setg_Vault szAuthID] , szBuffer );
}

public 
LoadDataid )
{
    new 
szAuthID34 ] , szBuffer66 ] , iTS;
    
    
get_user_authidid szAuthID charsmaxszAuthID ) );
    
    if ( 
nvault_lookupg_Vault szAuthID szBuffer charsmaxszBuffer ) , iTS ) )
    {
        
parseszBuffer g_iMarriedSteamIDid ] , charsmaxg_iMarriedSteamID[] ) , g_iMarriedNameid ] , charsmaxg_iMarriedName[] ) );
    }
    



ironskillz1 10-17-2015 09:26

Re: nvault problems
 
Thanks a lot man. I really appreciate that you have spent time fixing this for me. I will return with the results if it worked or not :)

Bugsy 10-17-2015 12:24

Re: nvault problems
 
I found one minor mistake in my above code which resulted in only the first letter of each players name to be saved in the vault. I edited the above code to fix this.

ironskillz1 10-17-2015 17:37

Re: nvault problems
 
Quote:

Originally Posted by Bugsy (Post 2353984)
I found one minor mistake in my above code which resulted in only the first letter of each players name to be saved in the vault. I edited the above code to fix this.

With the new loading code it wont load at all. The saving are working great tho.

It wont load anything.

Code:

public LoadData( id )
{
        new szBuffer[ 66 ] , iTS;
       
        if ( nvault_lookup( g_Vault , g_szAuthID[id] , szBuffer , charsmax( szBuffer ) , iTS ) )
        {
                parse( szBuffer , g_iMarriedSteamID[ id ] , charsmax( g_iMarriedSteamID[] ) , g_iMarriedName[ id ] , charsmax( g_iMarriedName[] ) );

                server_print("LOAD steamid: %s. Marriedsteamid: %s marriedname: %s", g_szAuthID[id], g_iMarriedSteamID[id], g_iMarriedName[id])
        }

}

The server print is blank at marriedsteamid and steamname.
So i guess something is wrong.

Bugsy 10-17-2015 18:05

Re: nvault problems
 
Quote:

Originally Posted by ironskillz1 (Post 2354089)
With the new loading code it wont load at all. The saving are working great tho.

It wont load anything.

Code:

public LoadData( id )
{
        new szBuffer[ 66 ] , iTS;
       
        if ( nvault_lookup( g_Vault , g_szAuthID[id] , szBuffer , charsmax( szBuffer ) , iTS ) )
        {
                parse( szBuffer , g_iMarriedSteamID[ id ] , charsmax( g_iMarriedSteamID[] ) , g_iMarriedName[ id ] , charsmax( g_iMarriedName[] ) );

                server_print("LOAD steamid: %s. Marriedsteamid: %s marriedname: %s", g_szAuthID[id], g_iMarriedSteamID[id], g_iMarriedName[id])
        }

}

The server print is blank at marriedsteamid and steamname.
So i guess something is wrong.

Are you reading player authid into g_szAuthID[id] at client_authorized()?

ironskillz1 10-17-2015 18:36

Re: nvault problems
 
Quote:

Originally Posted by Bugsy (Post 2354094)
Are you reading player authid into g_szAuthID[id] at client_authorized()?

Code:

g_szAuthID[ 33 ][ 34 ];

public client_putinserver(id)
{
        LoadData(id)
        get_user_authid( id , g_szAuthID[ id ] , charsmax( g_szAuthID[] ) );
}

Yes

Bugsy 10-17-2015 18:50

Re: nvault problems
 
Try the copy of the plugin I PM'd you

And make sure you read the authid before calling the load function


All times are GMT -4. The time now is 18:09.

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