Skip to content

Commit 4fec545

Browse files
committed
Added getting/setting entity key values
1 parent 8068245 commit 4fec545

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

src/core/core/sp_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ InterfaceHelper_t gGameInterfaces[] = {
137137
{INTERFACEVERSION_PLAYERBOTMANAGER, (void **)&botmanager},
138138
{IEFFECTS_INTERFACE_VERSION, (void **)&effects},
139139
{INTERFACEVERSION_SERVERGAMEDLL, (void **)&servergamedll},
140-
#if( SOURCE_ENGINE >= 2 )
140+
#if( SOURCE_ENGINE >= 1 )
141141
{VSERVERTOOLS_INTERFACE_VERSION, (void **)&servertools},
142142
#endif
143143
{NULL, NULL}

src/core/modules/entities/entities_wrap.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ void CEdictExt::SetPropVector( edict_t* pEdict, const char* prop_name, Vector ve
134134
prop.Set<Vector>(vecValue);
135135
}
136136

137+
const char* CEdictExt::GetKeyValue(edict_t* pEdict, const char* szName)
138+
{
139+
char szResult[1024];
140+
CBaseEntity* pEntity = pEdict->GetUnknown()->GetBaseEntity();
141+
servertools->GetKeyValue(pEntity, szName, szResult, 1024);
142+
return szResult;
143+
}
137144

138145
//-----------------------------------------------------------------------------
139146
// CSendProp code.

src/core/modules/entities/entities_wrap.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@
3232
#include "edict.h"
3333
#include "server_class.h"
3434
#include <cstdint>
35+
#include "toolframework/itoolentity.h"
3536

37+
// Externals
38+
extern IServerTools* servertools;
3639

3740
//---------------------------------------------------------------------------------
3841
// edict_t extension
@@ -49,6 +52,15 @@ class CEdictExt
4952
static void SetPropFloat( edict_t* pEdict, const char* prop_name, float flValue );
5053
static void SetPropString( edict_t* pEdict, const char* prop_name, const char* szValue );
5154
static void SetPropVector( edict_t* pEdict, const char* prop_name, Vector vecValue );
55+
56+
static const char* GetKeyValue(edict_t* pEdict, const char* szName);
57+
58+
template<class T>
59+
static void SetKeyValue(edict_t* pEdict, const char* szName, T value)
60+
{
61+
CBaseEntity* pEntity = pEdict->GetUnknown()->GetBaseEntity();
62+
servertools->SetKeyValue(pEntity, szName, value);
63+
}
5264
};
5365

5466
//---------------------------------------------------------------------------------

src/core/modules/entities/entities_wrap_python.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,36 @@ void export_edict()
416416
args("prop_name", "value")
417417
)
418418

419+
.def("get_key_value",
420+
&CEdictExt::GetKeyValue,
421+
"Returns the value of the given field name.",
422+
args("field_name")
423+
)
424+
425+
.def("set_key_value_int",
426+
&CEdictExt::SetKeyValue<int>,
427+
"Sets a field to the given value.",
428+
args("field_name", "value")
429+
)
430+
431+
.def("set_key_value_float",
432+
&CEdictExt::SetKeyValue<float>,
433+
"Sets a field to the given value.",
434+
args("field_name", "value")
435+
)
436+
437+
.def("set_key_value_string",
438+
&CEdictExt::SetKeyValue<const char *>,
439+
"Sets a field to the given value.",
440+
args("field_name", "value")
441+
)
442+
443+
.def("set_key_value_vector",
444+
&CEdictExt::SetKeyValue<Vector>,
445+
"Sets a field to the given value.",
446+
args("field_name", "value")
447+
)
448+
419449
// Class attributes
420450
/*
421451
// TODO: Missing on CS:GO

0 commit comments

Comments
 (0)