Added natives for getting output value.

For example: math_counter m_OutValue -> GetOutputValueFloat(entity, "m_OutValue")
This commit is contained in:
BotoX 2017-02-04 17:50:08 +01:00
parent c303af4d9d
commit 6af8b8b1d8
2 changed files with 140 additions and 1 deletions

View File

@ -46,6 +46,22 @@ IGameConfig *g_pGameConf = NULL;
#include <isaverestore.h>
#include <variant_t.h>
struct varianthax_t
{
union
{
bool bVal;
string_t iszVal;
int iVal;
float flVal;
float vecVal[3];
color32 rgbaVal;
};
CHandle<CBaseEntity> eVal; // this can't be in the union because it has a constructor.
fieldtype_t fieldType;
};
class CEventAction
{
public:
@ -99,7 +115,7 @@ void CEventAction::operator delete(void *pMem)
class CBaseEntityOutput
{
public:
variant_t m_Value;
varianthax_t m_Value;
CEventAction *m_ActionList;
DECLARE_SIMPLE_DATADESC();
@ -333,6 +349,116 @@ cell_t GetOutputFormatted(IPluginContext *pContext, const cell_t *params)
return Length;
}
cell_t GetOutputValue(IPluginContext *pContext, const cell_t *params)
{
char *pOutput;
pContext->LocalToString(params[2], &pOutput);
CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(gamehelpers->IndexToReference(params[1]));
CBaseEntityOutput *pEntityOutput = GetOutput(pEntity, pOutput);
if(pEntityOutput == NULL)
return -1;
switch(pEntityOutput->m_Value.fieldType)
{
case FIELD_TICK:
case FIELD_MODELINDEX:
case FIELD_MATERIALINDEX:
case FIELD_INTEGER:
case FIELD_COLOR32:
case FIELD_SHORT:
case FIELD_CHARACTER:
case FIELD_BOOLEAN:
break;
default:
return pContext->ThrowNativeError("%s value is not an integer (%d)", pOutput, pEntityOutput->m_Value.fieldType);
}
return (cell_t)pEntityOutput->m_Value.iVal;
}
cell_t GetOutputValueFloat(IPluginContext *pContext, const cell_t *params)
{
char *pOutput;
pContext->LocalToString(params[2], &pOutput);
CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(gamehelpers->IndexToReference(params[1]));
CBaseEntityOutput *pEntityOutput = GetOutput(pEntity, pOutput);
if(pEntityOutput == NULL)
return -1;
switch(pEntityOutput->m_Value.fieldType)
{
case FIELD_FLOAT:
case FIELD_TIME:
break;
default:
return pContext->ThrowNativeError("%s value is not a float (%d)", pOutput, pEntityOutput->m_Value.fieldType);
}
return sp_ftoc((cell_t)pEntityOutput->m_Value.flVal);
}
cell_t GetOutputValueString(IPluginContext *pContext, const cell_t *params)
{
char *pOutput;
pContext->LocalToString(params[2], &pOutput);
CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(gamehelpers->IndexToReference(params[1]));
CBaseEntityOutput *pEntityOutput = GetOutput(pEntity, pOutput);
if(pEntityOutput == NULL)
return -1;
switch(pEntityOutput->m_Value.fieldType)
{
case FIELD_CHARACTER:
case FIELD_STRING:
case FIELD_MODELNAME:
case FIELD_SOUNDNAME:
break;
default:
return pContext->ThrowNativeError("%s value is not a string (%d)", pOutput, pEntityOutput->m_Value.fieldType);
}
size_t len;
pContext->StringToLocalUTF8(params[3], params[4], pEntityOutput->m_Value.iszVal.ToCStr(), &len);
return len;
}
cell_t GetOutputValueVector(IPluginContext *pContext, const cell_t *params)
{
char *pOutput;
pContext->LocalToString(params[2], &pOutput);
CBaseEntity *pEntity = gamehelpers->ReferenceToEntity(gamehelpers->IndexToReference(params[1]));
CBaseEntityOutput *pEntityOutput = GetOutput(pEntity, pOutput);
if(pEntityOutput == NULL)
return -1;
switch(pEntityOutput->m_Value.fieldType)
{
case FIELD_FLOAT:
case FIELD_TIME:
break;
default:
return pContext->ThrowNativeError("%s value is not a float (%d)", pOutput, pEntityOutput->m_Value.fieldType);
}
cell_t *vec;
pContext->LocalToPhysAddr(params[3], &vec);
vec[0] = sp_ftoc(pEntityOutput->m_Value.vecVal[0]);
vec[1] = sp_ftoc(pEntityOutput->m_Value.vecVal[1]);
vec[2] = sp_ftoc(pEntityOutput->m_Value.vecVal[2]);
return 1;
}
cell_t FindOutput(IPluginContext *pContext, const cell_t *params)
{
char *pOutput;
@ -422,6 +548,10 @@ const sp_nativeinfo_t MyNatives[] =
{ "GetOutputParameter", GetOutputParameter },
{ "GetOutputDelay", GetOutputDelay },
{ "GetOutputFormatted", GetOutputFormatted },
{ "GetOutputValue", GetOutputValue },
{ "GetOutputValueFloat", GetOutputValueFloat },
{ "GetOutputValueString", GetOutputValueString },
{ "GetOutputValueVector", GetOutputValueVector },
{ "FindOutput", FindOutput },
{ "DeleteOutput", DeleteOutput },
{ "DeleteAllOutputs", DeleteAllOutputs },

View File

@ -4,11 +4,19 @@
#define _OutputInfo_Included
native int GetOutputCount(int Entity, const char[] sOutput);
native int GetOutputTarget(int Entity, const char[] sOutput, int Index, char[] sTarget, int MaxLen);
native int GetOutputTargetInput(int Entity, const char[] sOutput, int Index, char[] sTargetInput, int MaxLen);
native int GetOutputParameter(int Entity, const char[] sOutput, int Index, char[] sParameter, int MaxLen);
native float GetOutputDelay(int Entity, const char[] sOutput, int Index);
native int GetOutputFormatted(int Entity, const char[] sOutput, int Index, char[] sFormatted, int MaxLen);
native int GetOutputValue(int Entity, const char[] sOutput);
native float GetOutputValueFloat(int Entity, const char[] sOutput);
native int GetOutputValueString(int Entity, const char[] sOutput, char[] sValue, int MaxLen);
native bool GetOutputValueVector(int Entity, const char[] sOutput, float afVec[3]);
native int FindOutput(int Entity, const char[] sOutput, int StartIndex,
const char[] sTarget = NULL_STRING, // or NULL_STRING to ignore
const char[] sTargetInput = NULL_STRING, // or NULL_STRING to ignore
@ -16,6 +24,7 @@ native int FindOutput(int Entity, const char[] sOutput, int StartIndex,
float fDelay = -1.0, // or -1.0 to ignore
int TimesToFire = 0 // or 0 to ignore
);
native int DeleteOutput(int Entity, const char[] sOutput, int Index);
native int DeleteAllOutputs(int Entity, const char[] sOutput);