Added VScript utility functions + loosened VScript EntFire(ByHandle) restrictions

This commit is contained in:
Blixibon 2020-06-13 12:44:40 -05:00
parent 03632df565
commit ea0c830a62
5 changed files with 79 additions and 5 deletions

View File

@ -4355,7 +4355,7 @@ void CBaseCombatCharacter::DoMuzzleFlash()
}
}
#ifdef MAPBASE_VSCRIPT // DO NOT COMMIT; WAIT UNTIL FULL MERGE (5/15/2020)
#ifdef MAPBASE_VSCRIPT
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
HSCRIPT CBaseCombatCharacter::GetScriptActiveWeapon()

View File

@ -547,9 +547,12 @@ bool VScriptServerInit()
#ifdef MAPBASE_VSCRIPT
ScriptRegisterFunction( g_pScriptVM, MaxPlayers, "Get the maximum number of players allowed on this server" );
ScriptRegisterFunction( g_pScriptVM, IntervalPerTick, "Get the interval used between each tick" );
#endif
ScriptRegisterFunction( g_pScriptVM, DoEntFire, SCRIPT_ALIAS( "EntFire", "Generate an entity i/o event" ) );
ScriptRegisterFunction( g_pScriptVM, DoEntFireByInstanceHandle, SCRIPT_ALIAS( "EntFireByHandle", "Generate an entity i/o event. First parameter is an entity instance." ) );
#else
ScriptRegisterFunction( g_pScriptVM, DoEntFire, SCRIPT_ALIAS( "EntFire", "Generate and entity i/o event" ) );
ScriptRegisterFunctionNamed( g_pScriptVM, DoEntFireByInstanceHandle, "EntFireByHandle", "Generate and entity i/o event. First parameter is an entity instance." );
#endif
ScriptRegisterFunction( g_pScriptVM, DoUniqueString, SCRIPT_ALIAS( "UniqueString", "Generate a string guaranteed to be unique across the life of the script VM, with an optional root string. Useful for adding data to tables when not sure what keys are already in use in that table." ) );
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptCreateSceneEntity, "CreateSceneEntity", "Create a scene entity to play the specified scene." );
ScriptRegisterFunctionNamed( g_pScriptVM, NDebugOverlay::Box, "DebugDrawBox", "Draw a debug overlay box" );

View File

@ -10,17 +10,20 @@ function UniqueString( string = "" )
return DoUniqueString( string.tostring() );
}
function EntFire( target, action, value = null, delay = 0.0, activator = null )
function EntFire( target, action, value = null, delay = 0.0, activator = null, caller = null )
{
if ( !value )
{
value = "";
}
local caller = null;
if ( "self" in this )
{
caller = self;
if ( !caller )
{
caller = self;
}
if ( !activator )
{
activator = self;
@ -30,6 +33,29 @@ function EntFire( target, action, value = null, delay = 0.0, activator = null )
DoEntFire( target.tostring(), action.tostring(), value.tostring(), delay, activator, caller );
}
function EntFireByHandle( target, action, value = null, delay = 0.0, activator = null, caller = null )
{
if ( !value )
{
value = "";
}
if ( "self" in this )
{
if ( !caller )
{
caller = self;
}
if ( !activator )
{
activator = self;
}
}
DoEntFireByInstanceHandle( target, action.tostring(), value.tostring(), delay, activator, caller );
}
function __ReplaceClosures( script, scope )
{
if ( !scope )

View File

@ -374,6 +374,9 @@ public:
void LoadActbusyFile( const char *szScript ) { LoadFromValue( szScript, MANIFEST_ACTBUSY, false ); }
#endif
const char *GetModName() { return g_iszGameName; }
bool IsCoreMapbase() { return g_bMapbaseCore; }
virtual void RegisterVScript()
{
g_pScriptVM->RegisterInstance( this, "Mapbase" );
@ -397,6 +400,8 @@ BEGIN_SCRIPTDESC_ROOT( CMapbaseSystem, SCRIPT_SINGLETON "All-purpose Mapbase sys
DEFINE_SCRIPTFUNC( LoadTalkerFile, "Loads a custom talker file." )
DEFINE_SCRIPTFUNC( LoadActbusyFile, "Loads a custom actbusy file." )
#endif
DEFINE_SCRIPTFUNC( GetModName, "Gets the name of the mod. This is the name which shows up on Steam, RPC, etc." )
DEFINE_SCRIPTFUNC( IsCoreMapbase, "Indicates whether this is one of the original Mapbase mods or just a separate mod using its code." )
END_SCRIPTDESC();
#endif

View File

@ -752,6 +752,42 @@ FireBulletsInfo_t *GetFireBulletsInfoFromInfo( HSCRIPT hBulletsInfo )
//=============================================================================
//=============================================================================
static void ScriptEntitiesInBox( HSCRIPT hTable, int listMax, const Vector &hullMin, const Vector &hullMax, int iMask )
{
CBaseEntity *list[1024];
int count = UTIL_EntitiesInBox( list, listMax, hullMin, hullMax, iMask );
for ( int i = 0; i < count; i++ )
{
g_pScriptVM->SetValue( hTable, STRING(list[i]->GetEntityName()), ToHScript( list[i] ) );
}
}
static void ScriptEntitiesAtPoint( HSCRIPT hTable, int listMax, const Vector &point, int iMask )
{
CBaseEntity *list[1024];
int count = UTIL_EntitiesAtPoint( list, listMax, point, iMask );
for ( int i = 0; i < count; i++ )
{
g_pScriptVM->SetValue( hTable, STRING(list[i]->GetEntityName()), ToHScript( list[i] ) );
}
}
static void ScriptEntitiesInSphere( HSCRIPT hTable, int listMax, const Vector &center, float radius, int iMask )
{
CBaseEntity *list[1024];
int count = UTIL_EntitiesInSphere( list, listMax, center, radius, iMask );
for ( int i = 0; i < count; i++ )
{
g_pScriptVM->SetValue( hTable, STRING(list[i]->GetEntityName()), ToHScript( list[i] ) );
}
}
//=============================================================================
//=============================================================================
bool ScriptMatcherMatch( const char *pszQuery, const char *szValue ) { return Matcher_Match( pszQuery, szValue ); }
//=============================================================================
@ -803,6 +839,10 @@ void RegisterSharedScriptFunctions()
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptTraceLineComplex, "TraceLineComplex", "Complex version of TraceLine which takes 2 points, an ent to ignore, a trace mask, and a collision group. Returns a handle which can access all trace info." );
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptTraceHullComplex, "TraceHullComplex", "Takes 2 points, min/max hull bounds, an ent to ignore, a trace mask, and a collision group to trace to a point using a hull. Returns a handle which can access all trace info." );
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptEntitiesInBox, "EntitiesInBox", "Gets all entities which are within a worldspace box." );
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptEntitiesAtPoint, "EntitiesAtPoint", "Gets all entities which are intersecting a point in space." );
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptEntitiesInSphere, "EntitiesInSphere", "Gets all entities which are within a sphere." );
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptMatcherMatch, "Matcher_Match", "Compares a string to a query using Mapbase's matcher system, supporting wildcards, RS matchers, etc." );
ScriptRegisterFunction( g_pScriptVM, Matcher_NamesMatch, "Compares a string to a query using Mapbase's matcher system using wildcards only." );
ScriptRegisterFunction( g_pScriptVM, AppearsToBeANumber, "Checks if the given string appears to be a number." );