Difference between revisions of "KeyValueBuffer"

From Sven Co-op
Jump to navigation Jump to search
m
m
 
Line 9: Line 9:
  
 
These methods are accessible via the [[CEngineFuncs]] class.
 
These methods are accessible via the [[CEngineFuncs]] class.
 
+
<hr/>
 
This sample code uses the KeyValueBuffer to obtain the player's model:
 
This sample code uses the KeyValueBuffer to obtain the player's model:
 
<pre>
 
<pre>

Latest revision as of 21:29, 29 March 2025

KeyValueBuffer is a class that contains key value pairs. The game uses 2 types of keyvalue buffers: an info string and physics string. The info string buffer contains settings sent from the client to the server, such as their current player model, name and more. The physics string buffer contains settings that the physics code accesses. It contains settings such as whether the long jump module (slj) is available, and a player's true player model. You should not maintain a handle to KeyValueBuffer instances. When you are done using it, make sure no references that exist remain.

Two methods return a KeyValueBuffer instance:

KeyValueBuffer@ GetInfoKeyBuffer(edict_t@ pEdict)
KeyValueBuffer@ GetPhysicsKeyBuffer(edict_t@ pEdict)

These methods are accessible via the CEngineFuncs class.


This sample code uses the KeyValueBuffer to obtain the player's model:

string GetPlayerModel(CBasePlayer@ pPlayer)
{
    if( pPlayer !is null && pPlayer.IsPlayer() ) // This only returns the filename of the playermodel, not the full path + extension.
        return g_EngineFuncs.GetInfoKeyBuffer( pPlayer.edict() ).GetValue( "model" );
    else
        return "";
}

Methods

Method Description
edict_t@ GetClient() const Gets the client that this buffer belongs to.
string GetValue(const string& in szKey) const Gets a key value.
void SetValue(const string& in szKey, const string& in szValue) const Sets a key value.
void RemoveValue(const string& in szKey) Removes a key value. If this is a physics key buffer, this will set the key to an empty string instead.