Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/game/server/baseentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2404,6 +2404,23 @@ BEGIN_ENT_SCRIPTDESC_ROOT( CBaseEntity, "Root class of all server-side entities"

DEFINE_SCRIPTFUNC_NAMED( ScriptGetSolid, "GetSolid", "" )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetSolid, "SetSolid", "" )

DEFINE_SCRIPTFUNC_NAMED( ScriptCreatePhysics, "CreatePhysics", "Create the entity Physics." )
DEFINE_SCRIPTFUNC_NAMED( ScriptDestroyPhysics, "DestroyPhysics", "Destroy the entity Physics." )
DEFINE_SCRIPTFUNC_NAMED( ScriptHasPhysics, "HasPhysics", "Do we have Physics?")
DEFINE_SCRIPTFUNC_NAMED( ScriptGetSurfaceProperty, "GetSurfaceProperty", "Get the surface property id of the Physics Object.")
DEFINE_SCRIPTFUNC_NAMED( ScriptGetSurfacePropertyName, "GetSurfacePropertyName", "Get the surface property id by name on the Physics Object.")
DEFINE_SCRIPTFUNC_NAMED( ScriptSetSurfaceProperty, "SetSurfaceProperty", "Set a surface property id of the Physics Object.")
DEFINE_SCRIPTFUNC_NAMED( ScriptSetSurfacePropertyByName, "SetSurfacePropertyByName", "Set a surface property id by name on the Physics Object.")
DEFINE_SCRIPTFUNC_NAMED( ScriptSetMass, "SetMass", "Set the entity's Mass." )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetMass, "GetMass", "Get the entity's Mass." )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetBuoyancy, "SetBuoyancy", "Set the entity's Bouyancy, 0-1 ratio." )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetElasticity, "SetElasticity", "Set the entity's Elasticity." )
DEFINE_SCRIPTFUNC_NAMED( ScriptGetElasticity, "GetElasticity", "Get the entity's Elasticity." )
DEFINE_SCRIPTFUNC_NAMED( ScriptToggleCollisionsOn, "ToggleCollisionsOn", "Toggle Collisions between two physical entities." )
DEFINE_SCRIPTFUNC_NAMED( ScriptSetPhysicsFlag, "SetPhysicsFlag", "Set a physics flag for the entity." )
DEFINE_SCRIPTFUNC_NAMED( ScriptRemovePhysicsFlag, "RemovePhysicsFlag", "Remove a physics flag for the entity." )
DEFINE_SCRIPTFUNC_NAMED( ScriptHasPhysicsFlag, "HasPhysicsFlag", "Check if the entity has a specific physics flag." )

DEFINE_SCRIPTFUNC( TerminateScriptScope, "Clear the current script scope for this entity" )

Expand Down
179 changes: 179 additions & 0 deletions src/game/server/baseentity.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "vscript/ivscript.h"
#include "vscript_server.h"


class CDamageModifier;
class CDmgAccumulator;

Expand Down Expand Up @@ -102,6 +103,10 @@ class IHasAttributes;

typedef CUtlVector< CBaseEntity* > EntityList_t;

extern IPhysicsSurfaceProps *physprops;
void PhysDisableEntityCollisions( IPhysicsObject *pObject0, IPhysicsObject *pObject1 );
void PhysEnableEntityCollisions( IPhysicsObject *pObject0, IPhysicsObject *pObject1 );

#if defined( HL2_DLL )

// For CLASSIFY
Expand Down Expand Up @@ -1340,6 +1345,180 @@ class CBaseEntity : public IServerEntity
return (int)GetSolid();
}

void ScriptCreatePhysics( int nSolidType, int nSolidFlags, bool asleep )
{
VPhysicsInitNormal( (SolidType_t) nSolidType, nSolidFlags, asleep );
}

void ScriptDestroyPhysics( void )
{
VPhysicsDestroyObject();
}

bool ScriptHasPhysics( void )
{
if ( VPhysicsGetObject() )
return true;

return false;
}

int ScriptGetSurfaceProperty( void ) const
{
IPhysicsObject * vPhys = VPhysicsGetObject();
if ( vPhys )
{
return vPhys->GetMaterialIndex();
}
else
{
Log_Warning( LOG_VScript, "Entity (%s) has no VPhysics, make sure it does, or use the CreatePhysics function\n" );
return -1;
}
}

const char* ScriptGetSurfacePropertyName( int nIndex ) const
{
if ( !physprops )
return "default";

return physprops->GetPropName( nIndex );
}

void ScriptSetSurfaceProperty( int materialIndex )
{
IPhysicsObject * vPhys = VPhysicsGetObject();
if ( vPhys )
{
vPhys->SetMaterialIndex( materialIndex );
}
else
{
Log_Warning( LOG_VScript, "Entity (%s) has no VPhysics, make sure it does, or use the CreatePhysics function\n", GetDebugName() );
}
}
void ScriptSetSurfacePropertyByName( const char *name )
{
IPhysicsObject * vPhys = VPhysicsGetObject();
if ( vPhys )
{
vPhys->SetMaterialIndex( physprops->GetSurfaceIndex( name ) );
}
else
{
Log_Warning( LOG_VScript, "Entity (%s) has no VPhysics, make sure it does, or use the CreatePhysics function\n", GetDebugName() );
}
}

void ScriptToggleCollisionsOn( HSCRIPT pEntity, bool bEnable )
{
IPhysicsObject * vPhysObj1 = VPhysicsGetObject();

CBaseEntity *hTarget = ToEnt( pEntity );
IPhysicsObject* vPhysObj2 = hTarget->VPhysicsGetObject();

if ( !vPhysObj2 && !vPhysObj1 )
return;

if ( vPhysObj1 && vPhysObj2 && vPhysObj1 != vPhysObj2 )
{
if ( bEnable )
{
PhysEnableEntityCollisions( vPhysObj1, vPhysObj2 );
}
else
{
PhysDisableEntityCollisions( vPhysObj1, vPhysObj2 );
}
}
}

void ScriptSetPhysicsFlag( int PhysFlag )
{
IPhysicsObject * vPhys = VPhysicsGetObject();
if ( vPhys )
{
unsigned short flags = vPhys->GetGameFlags();
flags |= PhysFlag;
vPhys->SetGameFlags( flags );
}
}

void ScriptRemovePhysicsFlag( int PhysFlag )
{
IPhysicsObject * vPhys = VPhysicsGetObject();
if ( vPhys )
{
unsigned short flags = vPhys->GetGameFlags();
flags &= ~PhysFlag;
vPhys->SetGameFlags( flags );
}
}

bool ScriptHasPhysicsFlag( int PhysFlag ) const
{
IPhysicsObject *vPhys = VPhysicsGetObject();
if ( vPhys )
{
return ( vPhys->GetGameFlags() & PhysFlag ) != 0;
}
return false;
}

void ScriptSetMass( float flMass )
{
IPhysicsObject * vPhys = VPhysicsGetObject();
if ( vPhys )
{
Assert(flMass > 0);
vPhys->SetMass( flMass );
}
else
{
Log_Warning( LOG_VScript, "Entity (%s) has no VPhysics, make sure it does, or use the CreatePhysics function\n", GetDebugName() );
}
}


float ScriptGetMass( void ) const
{
IPhysicsObject *vPhys = VPhysicsGetObject();
if ( vPhys )
{
return vPhys->GetMass();
}
else
{
Log_Warning( LOG_VScript, "Entity (%s) has no VPhysics, make sure it does, or use the CreatePhysics function\n" );
return -1;
}
}


void ScriptSetBuoyancy( float flBuoyancy )
{
IPhysicsObject *vPhys = VPhysicsGetObject();
if ( vPhys )
{
return vPhys->SetBuoyancyRatio( flBuoyancy );
}
else
{
Log_Warning( LOG_VScript, "Entity (%s) has no VPhysics, make sure it does, or use the CreatePhysics function\n", GetDebugName() );
}
}


void ScriptSetElasticity( float flElasticity )
{
SetElasticity( flElasticity );
}

float ScriptGetElasticity ( void ) const
{
return m_flElasticity;
}

Comment on lines +1512 to +1521
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it is fine but you don't really need to make an wrapper for GetElasticity and SetElasticity since you can just directly define them as VScript functions. Just saying.

HSCRIPT ScriptGetModelKeyValues( void );

void ScriptPrecacheModel( const char *name );
Expand Down
16 changes: 16 additions & 0 deletions src/game/server/vscript_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2996,6 +2996,22 @@ DECLARE_SCRIPT_CONST( FDmgType, DMG_DIRECT )
DECLARE_SCRIPT_CONST( FDmgType, DMG_BUCKSHOT )
REGISTER_SCRIPT_CONST_TABLE( FDmgType )

DECLARE_SCRIPT_CONST_TABLE( PhysFlag )
DECLARE_SCRIPT_CONST( PhysFlag, FVPHYSICS_DMG_SLICE )
DECLARE_SCRIPT_CONST( PhysFlag, FVPHYSICS_CONSTRAINT_STATIC )
DECLARE_SCRIPT_CONST( PhysFlag, FVPHYSICS_PLAYER_HELD )
DECLARE_SCRIPT_CONST( PhysFlag, FVPHYSICS_PART_OF_RAGDOLL )
DECLARE_SCRIPT_CONST( PhysFlag, FVPHYSICS_MULTIOBJECT_ENTITY )
DECLARE_SCRIPT_CONST( PhysFlag, FVPHYSICS_HEAVY_OBJECT )
DECLARE_SCRIPT_CONST( PhysFlag, FVPHYSICS_PENETRATING )
DECLARE_SCRIPT_CONST( PhysFlag, FVPHYSICS_NO_PLAYER_PICKUP )
DECLARE_SCRIPT_CONST( PhysFlag, FVPHYSICS_WAS_THROWN )
DECLARE_SCRIPT_CONST( PhysFlag, FVPHYSICS_DMG_DISSOLVE )
DECLARE_SCRIPT_CONST( PhysFlag, FVPHYSICS_NO_IMPACT_DMG )
DECLARE_SCRIPT_CONST( PhysFlag, FVPHYSICS_NO_NPC_IMPACT_DMG )
DECLARE_SCRIPT_CONST( PhysFlag, FVPHYSICS_NO_SELF_COLLISIONS )
REGISTER_SCRIPT_CONST_TABLE( PhysFlag )

DECLARE_SCRIPT_CONST_TABLE( ESpectatorMode )
DECLARE_SCRIPT_CONST( ESpectatorMode, OBS_MODE_NONE )
DECLARE_SCRIPT_CONST( ESpectatorMode, OBS_MODE_DEATHCAM )
Expand Down