Updated NPC and entity script functions, fixed RunScriptQuotable breaking with empty strings

This commit is contained in:
Blixibon 2020-05-24 00:57:23 -05:00
parent 4320ae71e7
commit c06bf1e1c4
4 changed files with 70 additions and 37 deletions

View File

@ -732,6 +732,13 @@ int CAI_BaseNPC::VScriptGetState()
return (int)GetState();
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
HSCRIPT CAI_BaseNPC::VScriptGetHintNode()
{
return ToHScript( GetHintNode() );
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
const char *CAI_BaseNPC::VScriptGetSchedule()
@ -744,6 +751,21 @@ const char *CAI_BaseNPC::VScriptGetSchedule()
return pName;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
int CAI_BaseNPC::VScriptGetScheduleID()
{
int iSched = GetCurSchedule()->GetId();
// Local IDs are needed to correspond with user-friendly enums
if ( AI_IdIsGlobal( iSched ) )
{
iSched = GetClassScheduleIdSpace()->ScheduleGlobalToLocal(iSched);
}
return iSched;
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CAI_BaseNPC::VScriptSetSchedule( const char *szSchedule )
@ -767,23 +789,14 @@ const char *CAI_BaseNPC::VScriptGetTask()
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
bool CAI_BaseNPC::VScriptHasCondition( const char *szCondition )
int CAI_BaseNPC::VScriptGetTaskID()
{
return HasCondition( GetConditionID( szCondition ) );
}
const Task_t *pTask = GetTask();
int iID = -1;
if (pTask)
iID = GetTaskID( TaskName( pTask->iTask ) );
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CAI_BaseNPC::VScriptSetCondition( const char *szCondition )
{
SetCondition( GetConditionID( szCondition ) );
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
void CAI_BaseNPC::VScriptClearCondition( const char *szCondition )
{
ClearCondition( GetConditionID( szCondition ) );
return iID;
}
//-----------------------------------------------------------------------------
@ -11899,7 +11912,7 @@ BEGIN_DATADESC( CAI_BaseNPC )
END_DATADESC()
#ifdef MAPBASE_VSCRIPT
BEGIN_ENT_SCRIPTDESC( CAI_BaseNPC, CBaseCombatCharacter, "The base class shared all NPCs derive from." )
BEGIN_ENT_SCRIPTDESC( CAI_BaseNPC, CBaseCombatCharacter, "The base class all NPCs derive from." )
DEFINE_SCRIPTFUNC_NAMED( VScriptGetEnemy, "GetEnemy", "Get the NPC's current enemy." )
DEFINE_SCRIPTFUNC_NAMED( VScriptSetEnemy, "SetEnemy", "Set the NPC's current enemy." )
@ -11907,20 +11920,28 @@ BEGIN_ENT_SCRIPTDESC( CAI_BaseNPC, CBaseCombatCharacter, "The base class shared
DEFINE_SCRIPTFUNC_NAMED( VScriptFindEnemyMemory, "FindEnemyMemory", "Get information about the NPC's current enemy." )
DEFINE_SCRIPTFUNC_NAMED( VScriptGetHintGroup, "GetHintGroup", "Get the name of the NPC's hint group." )
DEFINE_SCRIPTFUNC_NAMED( VScriptGetState, "GetNPCState", "Get the NPC's current state." )
DEFINE_SCRIPTFUNC_NAMED( VScriptGetHintGroup, "GetHintGroup", "Get the name of the NPC's hint group." )
DEFINE_SCRIPTFUNC_NAMED( VScriptGetHintNode, "GetHintNode", "Get the NPC's current AI hint." )
DEFINE_SCRIPTFUNC( CapabilitiesGet, "Get the capabilities the NPC currently possesses." )
DEFINE_SCRIPTFUNC( CapabilitiesAdd, "Add capabilities to the NPC." )
DEFINE_SCRIPTFUNC( CapabilitiesRemove, "Remove capabilities from the NPC." )
DEFINE_SCRIPTFUNC( CapabilitiesClear, "Clear capabilities for the NPC." )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetActivity, "GetActivity", "Get the NPC's current activity." )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetActivityID, "GetActivityID", "Get the NPC's current activity ID." )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetActivity, "SetActivity", "Set the NPC's current activity." )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetActivityID, "SetActivityID", "Set the NPC's current activity ID." )
DEFINE_SCRIPTFUNC( ResetActivity, "Reset the NPC's current activity." )
DEFINE_SCRIPTFUNC_NAMED( VScriptGetSchedule, "GetSchedule", "Get the NPC's current schedule." )
DEFINE_SCRIPTFUNC_NAMED( VScriptGetScheduleID, "GetScheduleID", "Get the NPC's current schedule ID." )
DEFINE_SCRIPTFUNC_NAMED( VScriptSetSchedule, "SetSchedule", "Set the NPC's current schedule." )
DEFINE_SCRIPTFUNC_NAMED( VScriptSetScheduleID, "SetScheduleID", "Set the NPC's current schedule ID." )
DEFINE_SCRIPTFUNC_NAMED( VScriptGetTask, "GetTask", "Get the NPC's current task." )
DEFINE_SCRIPTFUNC_NAMED( VScriptGetTaskID, "GetTaskID", "Get the NPC's current task ID." )
DEFINE_SCRIPTFUNC( ClearSchedule, "Clear the NPC's current schedule for the specified reason." )
DEFINE_SCRIPTFUNC_NAMED( VScriptHasCondition, "HasCondition", "Get whether the NPC has a condition." )

View File

@ -1220,18 +1220,26 @@ public:
HSCRIPT VScriptFindEnemyMemory( HSCRIPT pEnemy );
int VScriptGetState();
const char* VScriptGetHintGroup() { return STRING( GetHintGroup() ); }
const char *VScriptGetSchedule();
int VScriptGetScheduleID() { return GetCurSchedule()->GetId(); }
const char* VScriptGetHintGroup() { return STRING( GetHintGroup() ); }
HSCRIPT VScriptGetHintNode();
const char* ScriptGetActivity() { return GetActivityName( GetActivity() ); }
int ScriptGetActivityID() { return GetActivity(); }
void ScriptSetActivity( const char *szActivity ) { SetActivity( (Activity)GetActivityID( szActivity ) ); }
void ScriptSetActivityID( int iActivity ) { SetActivity((Activity)iActivity); }
const char* VScriptGetSchedule();
int VScriptGetScheduleID();
void VScriptSetSchedule( const char *szSchedule );
void VScriptSetScheduleID( int iSched ) { SetSchedule( iSched ); }
const char *VScriptGetTask();
const char* VScriptGetTask();
int VScriptGetTaskID();
bool VScriptHasCondition( const char *szCondition );
bool VScriptHasCondition( const char *szCondition ) { return HasCondition( GetConditionID( szCondition ) ); }
bool VScriptHasConditionID( int iCondition ) { return HasCondition( iCondition ); }
void VScriptSetCondition( const char *szCondition );
void VScriptClearCondition( const char *szCondition );
void VScriptSetCondition( const char *szCondition ) { SetCondition( GetConditionID( szCondition ) ); }
void VScriptClearCondition( const char *szCondition ) { ClearCondition( GetConditionID( szCondition ) ); }
HSCRIPT VScriptGetExpresser();
#endif

View File

@ -401,7 +401,7 @@ CAI_Schedule *CAI_BaseNPC::GetScheduleOfType( int scheduleType )
}
g_pScriptVM->SetValue( "schedule", GetSchedulingSymbols()->ScheduleIdToSymbol( newSchedule ) );
g_pScriptVM->SetValue( "schedule_id", newSchedule );
g_pScriptVM->SetValue( "schedule_id", scheduleType ); // Use the local ID
ScriptVariant_t functionReturn;
m_ScriptScope.Call( hFunc, &functionReturn );

View File

@ -2203,6 +2203,19 @@ BEGIN_ENT_SCRIPTDESC_ROOT( CBaseEntity, "Root class of all server-side entities"
DEFINE_SCRIPTFUNC_NAMED( ScriptAddContext, "AddContext", "Add a response context value" )
DEFINE_SCRIPTFUNC_NAMED( ScriptClassify, "Classify", "Get Class_T class ID" )
DEFINE_SCRIPTFUNC( GetSpawnFlags, "Get spawnflags" )
DEFINE_SCRIPTFUNC( AddSpawnFlags, "Add spawnflag(s)" )
DEFINE_SCRIPTFUNC( RemoveSpawnFlags, "Remove spawnflag(s)" )
DEFINE_SCRIPTFUNC( ClearSpawnFlags, "Clear spawnflag(s)" )
DEFINE_SCRIPTFUNC( HasSpawnFlags, "Check if the entity has specific spawnflag(s) ticked" )
DEFINE_SCRIPTFUNC( GetEffects, "Get effects" )
DEFINE_SCRIPTFUNC( AddEffects, "Add effect(s)" )
DEFINE_SCRIPTFUNC( RemoveEffects, "Remove effect(s)" )
DEFINE_SCRIPTFUNC( ClearEffects, "Clear effect(s)" )
DEFINE_SCRIPTFUNC( SetEffects, "Set effect(s)" )
DEFINE_SCRIPTFUNC( IsEffectActive, "Check if an effect is active" )
#endif
DEFINE_SCRIPTFUNC( ValidateScriptScope, "Ensure that an entity's script scope has been created" )
@ -8034,18 +8047,9 @@ void CBaseEntity::InputCallScriptFunction(inputdata_t& inputdata)
//---------------------------------------------------------
void CBaseEntity::InputRunScriptQuotable(inputdata_t& inputdata)
{
CUtlStringList vecStrings;
V_SplitString( inputdata.value.String(), "''", vecStrings );
if (vecStrings.Count() > 1)
{
char szQuotableCode[1024];
Q_strncpy( szQuotableCode, vecStrings[0], sizeof( szQuotableCode ) );
for ( int i = 1; i < vecStrings.Count(); i++ )
if (V_StrSubst( inputdata.value.String(), "''", "\"", szQuotableCode, sizeof( szQuotableCode ), false ))
{
Q_snprintf( szQuotableCode, sizeof( szQuotableCode ), "%s\"%s", szQuotableCode, vecStrings[i] );
}
RunScript( szQuotableCode, "InputRunScriptQuotable" );
}
else