Raised This Month: $ Target: $400
 0% 

Pro's vs. Con's of storing player data in variables?


Post New Thread Reply   
 
Thread Tools Display Modes
Miu
Veteran Member
Join Date: Nov 2013
Old 12-28-2015 , 11:54   Re: Pro's vs. Con's of storing player data in variables?
Reply With Quote #11

just swap the arrays around when they reconnect? o.o
Miu is offline
aexi0n
AlliedModders Donor
Join Date: Nov 2014
Location: bhop_deluxe
Old 12-28-2015 , 12:52   Re: Pro's vs. Con's of storing player data in variables?
Reply With Quote #12

Alright threw together some semi-psuedo code as to implementing the ADT Trie things. Am I using them correctly?

PHP Code:
//Example Player Data Variables
enum Player
{
    
Level,
    
XP
}

new 
g_info[MAXPLAYERS+1][Player];
new 
g_mapchange[MAXPLAYERS+1][Player];

// Handle to my trie. 
new Handle:MapChangeTrie;

//Hook Scoreboard Event To Save Data Prior To Mapchange
HookEvent("cs_win_panel_match"event_endmapEventHookMode_Pre);

//Create Trie
OnPluginStart()
{
    
MapChangeTrie CreateTrie();
}

//Map Is About To Change, Store Player Data In Trie
public Action:event_endmap(Handle:event, const String:name[], bool:dontBroadcast)
{
    
decl String:steamid[64];
    
    for(new 
1<= MaxClientsi++)
    {
        if(!
IsFakeClient(i))
        {
            
//Get Player SteamID for Trie Name
            
GetClientAuthString(isteamidsizeof(steamid));
            
            
//Store Player Data
            
g_mapchange[i][Level] = g_info[client][Level];
            
g_mapchange[i][XP] = g_info[client][XP];
            
            
//Save Name To Index
            
SetTrieValue(MapChangeTriesteamidi);
        }
    }
}

//Client Re-Connecting From Map Change, Restore Data From Trie
public OnClientPostAdminCheck(client)
{
    new 
TrieIndex = -1;
    
    
decl String:steamid[64];
    
    
GetTrieValue(MapChangeTriesteamidTrieIndex);
    
    if(
TrieIndex >= 0)
    {
        
g_info[client][Level] = g_mapchange[TrieIndex][Level];
        
g_info[client][XP] = g_mapchange[TrieIndex][XP];
    }
    else
    {
        
LoadPlayerData(client);
    }

aexi0n is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 12-28-2015 , 13:16   Re: Pro's vs. Con's of storing player data in variables?
Reply With Quote #13

Quote:
Originally Posted by aexi0n View Post
Alright threw together some semi-psuedo code as to implementing the ADT Trie things. Am I using them correctly?

PHP Code:
//Example Player Data Variables
enum Player
{
    
Level,
    
XP
}

new 
g_info[MAXPLAYERS+1][Player];
new 
g_mapchange[MAXPLAYERS+1][Player];

// Handle to my trie. 
new Handle:MapChangeTrie;

//Hook Scoreboard Event To Save Data Prior To Mapchange
HookEvent("cs_win_panel_match"event_endmapEventHookMode_Pre);

//Create Trie
OnPluginStart()
{
    
MapChangeTrie CreateTrie();
}

//Map Is About To Change, Store Player Data In Trie
public Action:event_endmap(Handle:event, const String:name[], bool:dontBroadcast)
{
    
decl String:steamid[64];
    
    for(new 
1<= MaxClientsi++)
    {
        if(!
IsFakeClient(i))
        {
            
//Get Player SteamID for Trie Name
            
GetClientAuthString(isteamidsizeof(steamid));
            
            
//Store Player Data
            
g_mapchange[i][Level] = g_info[client][Level];
            
g_mapchange[i][XP] = g_info[client][XP];
            
            
//Save Name To Index
            
SetTrieValue(MapChangeTriesteamidi);
        }
    }
}

//Client Re-Connecting From Map Change, Restore Data From Trie
public OnClientPostAdminCheck(client)
{
    new 
TrieIndex = -1;
    
    
decl String:steamid[64];
    
    
GetTrieValue(MapChangeTriesteamidTrieIndex);
    
    if(
TrieIndex >= 0)
    {
        
g_info[client][Level] = g_mapchange[TrieIndex][Level];
        
g_info[client][XP] = g_mapchange[TrieIndex][XP];
    }
    else
    {
        
LoadPlayerData(client);
    }

Your forgetting to get the client's steamid before calling GetTrieValue. Also GetTrieValue returns a bool(true on success, false if key isn't found/value at key is a string or an array).
WildCard65 is offline
dilalmon
AlliedModders Donor
Join Date: Apr 2013
Old 12-29-2015 , 16:18   Re: Pro's vs. Con's of storing player data in variables?
Reply With Quote #14

asherkin mentioned the client indexes can change before, but I have never experienced this.

I made a little fail-safe measure where it would store client's SteamID in a cache (string) and check after every map change (OnPostAdminCheck) if their current SteamID is the same as the cache.
The cache is only cleared at player_disconnect.
If the check ever fails, it would log in a specified log file. I never got this.

So if client indexes ever change, I think it still fires player_disconnect.
dilalmon is offline
psychonic

BAFFLED
Join Date: May 2008
Old 12-29-2015 , 16:26   Re: Pro's vs. Con's of storing player data in variables?
Reply With Quote #15

Do not rely on client indexes not changing. Them staying the same is not an API guarantee and there are indeed cases where they can change.

Additionally, don't rely on the player_disconnect event being available, as not only are there corner cases in the engine where it will not fire, but plugin can also completely block other plugins from seeing it (by returning Plugin_Stop in a pre-hook on the event).
psychonic is offline
dilalmon
AlliedModders Donor
Join Date: Apr 2013
Old 12-29-2015 , 16:32   Re: Pro's vs. Con's of storing player data in variables?
Reply With Quote #16

Any example cases where they could change?
dilalmon is offline
Disowned
Member
Join Date: Oct 2015
Old 12-29-2015 , 16:51   Re: Pro's vs. Con's of storing player data in variables?
Reply With Quote #17

Quote:
Originally Posted by asherkin View Post
It doesn't any more. That entire section was very wrong.
Any possibility we could get accurate information on this then? I thought that a userid will stay consistent across maps, as you will find servers well into the hundreds of userid numbers. Or is this only accurate per map?
Disowned is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 12-29-2015 , 17:02   Re: Pro's vs. Con's of storing player data in variables?
Reply With Quote #18

Quote:
Originally Posted by Disowned View Post
Any possibility we could get accurate information on this then? I thought that a userid will stay consistent across maps, as you will find servers well into the hundreds of userid numbers. Or is this only accurate per map?
userids don't change until a client disconnects.

userids can repeat if your server is up long enough without rebooting. This is because they are stored as a 16-bit number, meaning they go from 0 (never used) to 65535... and then repeat.

I do vaguely remember hearing that they only went up to 32767 rather than 65535, but I've never tested that to check.
__________________
Not currently working on SourceMod plugin development.
Powerlord 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 05:14.


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