Added CreateProp() function for VScript, allowing the creation of exclusively client-side dynamic props

This commit is contained in:
Blixibon 2020-12-26 00:00:25 -06:00
parent 4861893235
commit 55cbdf49aa
2 changed files with 37 additions and 0 deletions

View File

@ -24,6 +24,11 @@ BEGIN_NETWORK_TABLE( CDynamicProp, DT_DynamicProp )
RecvPropBool(RECVINFO(m_bUseHitboxesForRenderBox)),
END_NETWORK_TABLE()
#ifdef MAPBASE_VSCRIPT
// Allows client-side VScript to create dynamic props via CreateProp()
LINK_ENTITY_TO_CLASS( prop_dynamic, C_DynamicProp );
#endif
C_DynamicProp::C_DynamicProp( void )
{
m_iCachedFrameCount = -1;

View File

@ -431,6 +431,35 @@ bool DoIncludeScript( const char *pszScript, HSCRIPT hScope )
return true;
}
#ifdef MAPBASE_VSCRIPT
// Creates a client-side prop
HSCRIPT CreateProp( const char *pszEntityName, const Vector &vOrigin, const char *pszModelName, int iAnim )
{
C_BaseAnimating *pBaseEntity = (C_BaseAnimating *)CreateEntityByName( pszEntityName );
if (!pBaseEntity)
return NULL;
pBaseEntity->SetAbsOrigin( vOrigin );
pBaseEntity->SetModelName( pszModelName );
if (!pBaseEntity->InitializeAsClientEntity( pszModelName, RENDER_GROUP_OPAQUE_ENTITY ))
{
Warning("Can't initialize %s as client entity\n", pszEntityName);
return NULL;
}
pBaseEntity->SetPlaybackRate( 1.0f );
int iSequence = pBaseEntity->SelectWeightedSequence( (Activity)iAnim );
if ( iSequence != -1 )
{
pBaseEntity->SetSequence( iSequence );
}
return ToHScript( pBaseEntity );
}
#endif
bool VScriptClientInit()
{
VMPROF_START
@ -494,6 +523,9 @@ bool VScriptClientInit()
ScriptRegisterFunction( g_pScriptVM, GetMapName, "Get the name of the map.");
ScriptRegisterFunction( g_pScriptVM, Time, "Get the current server time" );
ScriptRegisterFunction( g_pScriptVM, DoIncludeScript, "Execute a script (internal)" );
#ifdef MAPBASE_VSCRIPT
ScriptRegisterFunction( g_pScriptVM, CreateProp, "Create an animating prop" );
#endif
if ( GameRules() )
{