Difference between revisions of "KeyValueBuffer"

From Sven Co-op
Jump to navigation Jump to search
(Created page with "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...")
 
m
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
KeyValueBuffer is a class that contains key value pairs. The game uses 2 types of keyvalue buffers: an info string and physics string.
 
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 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 is available.
+
The physics string buffer contains settings that the physics code accesses. It contains settings such as whether the long jump module (<code>slj</code>) 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 exist remain.
+
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:
 
Two methods return a KeyValueBuffer instance:
  
<code>[[CEngineFuncs#GetInfoKeyBuffer|KeyValueBuffer@ GetInfoKeyBuffer(edict_t@ pEdict)]]<br>[[CEngineFuncs#GetPhysicsKeyBuffer|KeyValueBuffer@ GetPhysicsKeyBuffer(edict_t@ pEdict)]]</code>
+
<code>[[CEngineFuncs#GetInfoKeyBuffer|KeyValueBuffer@ GetInfoKeyBuffer(edict_t@ pEdict)]]</code><br><code>[[CEngineFuncs#GetPhysicsKeyBuffer|KeyValueBuffer@ GetPhysicsKeyBuffer(edict_t@ pEdict)]]</code>
 +
 
 
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:
 +
<pre>
 +
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 "";
 +
}
 +
</pre>
 
== Methods ==
 
== Methods ==
 
{| class="wikitable" style="vertical-align:middle;"
 
{| class="wikitable" style="vertical-align:middle;"

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.