diff --git a/sp/src/game/client/c_baseentity.cpp b/sp/src/game/client/c_baseentity.cpp index 0c9060b9..a4a29ea1 100644 --- a/sp/src/game/client/c_baseentity.cpp +++ b/sp/src/game/client/c_baseentity.cpp @@ -442,6 +442,7 @@ BEGIN_ENT_SCRIPTDESC_ROOT( C_BaseEntity, "Root class of all client-side entities #ifdef MAPBASE_VSCRIPT DEFINE_SCRIPTFUNC( ValidateScriptScope, "Ensure that an entity's script scope has been created" ) + DEFINE_SCRIPTFUNC( GetOrCreatePrivateScriptScope, "Create and retrieve the script-side data associated with an entity" ) DEFINE_SCRIPTFUNC( GetScriptScope, "Retrieve the script-side data associated with an entity" ) DEFINE_SCRIPTFUNC( GetHealth, "" ) @@ -479,6 +480,7 @@ BEGIN_ENT_SCRIPTDESC_ROOT( C_BaseEntity, "Root class of all client-side entities DEFINE_SCRIPTFUNC( GetWaterLevel, "Get current level of water submergence" ) + DEFINE_SCRIPTFUNC_NAMED( ScriptSetParent, "SetParent", "" ) DEFINE_SCRIPTFUNC_NAMED( ScriptGetMoveParent, "GetMoveParent", "If in hierarchy, retrieves the entity's parent" ) DEFINE_SCRIPTFUNC_NAMED( ScriptGetRootMoveParent, "GetRootMoveParent", "If in hierarchy, walks up the hierarchy to find the root parent" ) DEFINE_SCRIPTFUNC_NAMED( ScriptFirstMoveChild, "FirstMoveChild", "" ) @@ -489,6 +491,9 @@ BEGIN_ENT_SCRIPTDESC_ROOT( C_BaseEntity, "Root class of all client-side entities DEFINE_SCRIPTFUNC( IsFollowingEntity, "Returns true if this entity is following another entity." ) DEFINE_SCRIPTFUNC_NAMED( ScriptGetFollowedEntity, "GetFollowedEntity", "Get the entity we're following." ) + DEFINE_SCRIPTFUNC_NAMED( GetScriptOwnerEntity, "GetOwner", "Gets this entity's owner" ) + DEFINE_SCRIPTFUNC_NAMED( SetScriptOwnerEntity, "SetOwner", "Sets this entity's owner" ) + DEFINE_SCRIPTFUNC_NAMED( ScriptGetColorVector, "GetRenderColorVector", "Get the render color as a vector" ) DEFINE_SCRIPTFUNC_NAMED( ScriptGetColorR, "GetRenderColorR", "Get the render color's R value" ) DEFINE_SCRIPTFUNC_NAMED( ScriptGetColorG, "GetRenderColorG", "Get the render color's G value" ) @@ -537,6 +542,7 @@ BEGIN_ENT_SCRIPTDESC_ROOT( C_BaseEntity, "Root class of all client-side entities DEFINE_SCRIPTFUNC_NAMED( GetEntityIndex, "entindex", "" ) #endif + END_SCRIPTDESC(); #ifndef NO_ENTITY_PREDICTION diff --git a/sp/src/game/client/c_baseentity.h b/sp/src/game/client/c_baseentity.h index de40c28e..598b88c7 100644 --- a/sp/src/game/client/c_baseentity.h +++ b/sp/src/game/client/c_baseentity.h @@ -266,6 +266,7 @@ public: bool ValidateScriptScope(); bool CallScriptFunction( const char* pFunctionName, ScriptVariant_t* pFunctionReturn ); + HSCRIPT GetOrCreatePrivateScriptScope(); HSCRIPT GetScriptScope() { return m_ScriptScope; } HSCRIPT LookupScriptFunction(const char* pFunctionName); @@ -275,6 +276,9 @@ public: bool RunScript( const char* pScriptText, const char* pDebugFilename = "C_BaseEntity::RunScript" ); #endif + HSCRIPT GetScriptOwnerEntity(); + virtual void SetScriptOwnerEntity(HSCRIPT pOwner); + HSCRIPT GetScriptInstance(); HSCRIPT m_hScriptInstance; @@ -1185,6 +1189,7 @@ public: HSCRIPT ScriptGetPhysicsObject( void ); + void ScriptSetParent( HSCRIPT hParent, const char *szAttachment ); HSCRIPT ScriptGetMoveParent( void ); HSCRIPT ScriptGetRootMoveParent(); HSCRIPT ScriptFirstMoveChild( void ); diff --git a/sp/src/game/server/baseentity.cpp b/sp/src/game/server/baseentity.cpp index 6d36d1de..05c81eae 100644 --- a/sp/src/game/server/baseentity.cpp +++ b/sp/src/game/server/baseentity.cpp @@ -8725,51 +8725,6 @@ HSCRIPT CBaseEntity::GetScriptScope() return m_ScriptScope; } -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -#ifdef MAPBASE_VSCRIPT -HSCRIPT CBaseEntity::GetOrCreatePrivateScriptScope() -{ - ValidateScriptScope(); - return m_ScriptScope; -} - -//----------------------------------------------------------------------------- -//----------------------------------------------------------------------------- -void CBaseEntity::ScriptSetParent(HSCRIPT hParent, const char *szAttachment) -{ - CBaseEntity *pParent = ToEnt(hParent); - if ( !pParent ) - { - SetParent(NULL); - return; - } - - // if an attachment is specified, the parent needs to be CBaseAnimating - if ( szAttachment && szAttachment[0] != '\0' ) - { - CBaseAnimating *pAnimating = pParent->GetBaseAnimating(); - if ( !pAnimating ) - { - Warning("ERROR: Tried to set parent for entity %s (%s), but its parent has no model.\n", GetClassname(), GetDebugName()); - return; - } - - int iAttachment = pAnimating->LookupAttachment(szAttachment); - if ( iAttachment <= 0 ) - { - Warning("ERROR: Tried to set parent for entity %s (%s), but it has no attachment named %s.\n", GetClassname(), GetDebugName(), szAttachment); - return; - } - - SetParent(pParent, iAttachment); - SetMoveType(MOVETYPE_NONE); - return; - } - - SetParent(pParent); -} -#endif //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- HSCRIPT CBaseEntity::ScriptGetMoveParent(void) @@ -10019,6 +9974,7 @@ void CBaseEntity::RunOnPostSpawnScripts(void) } } +#ifndef MAPBASE_VSCRIPT // This is shared now HSCRIPT CBaseEntity::GetScriptOwnerEntity() { return ToHScript(GetOwnerEntity()); @@ -10028,6 +9984,7 @@ void CBaseEntity::SetScriptOwnerEntity(HSCRIPT pOwner) { SetOwnerEntity(ToEnt(pOwner)); } +#endif //----------------------------------------------------------------------------- // VScript access to model's key values diff --git a/sp/src/game/shared/baseentity_shared.cpp b/sp/src/game/shared/baseentity_shared.cpp index 886d12e0..f07f3775 100644 --- a/sp/src/game/shared/baseentity_shared.cpp +++ b/sp/src/game/shared/baseentity_shared.cpp @@ -2621,6 +2621,58 @@ bool CBaseEntity::IsToolRecording() const #endif #ifdef MAPBASE_VSCRIPT +HSCRIPT CBaseEntity::GetOrCreatePrivateScriptScope() +{ + ValidateScriptScope(); + return m_ScriptScope; +} + +//----------------------------------------------------------------------------- +//----------------------------------------------------------------------------- +void CBaseEntity::ScriptSetParent(HSCRIPT hParent, const char *szAttachment) +{ + CBaseEntity *pParent = ToEnt(hParent); + if ( !pParent ) + { + SetParent(NULL); + return; + } + + // if an attachment is specified, the parent needs to be CBaseAnimating + if ( szAttachment && szAttachment[0] != '\0' ) + { + CBaseAnimating *pAnimating = pParent->GetBaseAnimating(); + if ( !pAnimating ) + { + Warning("ERROR: Tried to set parent for entity %s (%s), but its parent has no model.\n", GetClassname(), GetDebugName()); + return; + } + + int iAttachment = pAnimating->LookupAttachment(szAttachment); + if ( iAttachment <= 0 ) + { + Warning("ERROR: Tried to set parent for entity %s (%s), but it has no attachment named %s.\n", GetClassname(), GetDebugName(), szAttachment); + return; + } + + SetParent(pParent, iAttachment); + SetMoveType(MOVETYPE_NONE); + return; + } + + SetParent(pParent); +} + +HSCRIPT CBaseEntity::GetScriptOwnerEntity() +{ + return ToHScript(GetOwnerEntity()); +} + +void CBaseEntity::SetScriptOwnerEntity(HSCRIPT pOwner) +{ + SetOwnerEntity(ToEnt(pOwner)); +} + //----------------------------------------------------------------------------- //----------------------------------------------------------------------------- const Vector& CBaseEntity::ScriptGetColorVector()