mirror of
https://github.com/mapbase-source/source-sdk-2013.git
synced 2025-01-13 23:37:58 +03:00
Exposed more things to VScript, including vehicles, AI goal entities, and convars
This commit is contained in:
parent
c12418e1ce
commit
eb63b7b6a6
@ -38,6 +38,15 @@ BEGIN_DATADESC( CAI_GoalEntity )
|
||||
|
||||
END_DATADESC()
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
BEGIN_ENT_SCRIPTDESC( CAI_GoalEntity, CBaseEntity, "The base class for goal entities used to control NPC behavior." )
|
||||
|
||||
DEFINE_SCRIPTFUNC( IsActive, "Check if the goal entity is active." )
|
||||
DEFINE_SCRIPTFUNC( NumActors, "Get the number of actors using this goal entity." )
|
||||
|
||||
END_SCRIPTDESC();
|
||||
#endif
|
||||
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
|
@ -27,6 +27,9 @@ class CAI_GoalEntity : public CBaseEntity,
|
||||
public IEntityListener
|
||||
{
|
||||
DECLARE_CLASS( CAI_GoalEntity, CBaseEntity );
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
DECLARE_ENT_SCRIPTDESC();
|
||||
#endif
|
||||
public:
|
||||
CAI_GoalEntity()
|
||||
: m_iszActor(NULL_STRING),
|
||||
|
@ -160,6 +160,7 @@ BEGIN_ENT_SCRIPTDESC( CBaseCombatCharacter, CBaseFlex, "The base class shared by
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( Weapon_ShootPosition, "ShootPosition", "Get the character's shoot position." )
|
||||
DEFINE_SCRIPTFUNC_NAMED( Weapon_DropAll, "DropAllWeapons", "Make the character drop all of its weapons." )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptEquipWeapon, "EquipWeapon", "Make the character equip the specified weapon entity. If they don't already own the weapon, they will acquire it instantly." )
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetAmmoCount, "GetAmmoCount", "Get the ammo count of the specified ammo type." )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptSetAmmoCount, "SetAmmoCount", "Set the ammo count of the specified ammo type." )
|
||||
@ -4376,6 +4377,42 @@ HSCRIPT CBaseCombatCharacter::GetScriptWeaponByType( const char *pszWeapon, int
|
||||
return ToHScript( Weapon_OwnsThisType( pszWeapon, iSubType ) );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
void CBaseCombatCharacter::ScriptEquipWeapon( HSCRIPT hWeapon )
|
||||
{
|
||||
CBaseEntity *pEntity = ToEnt( hWeapon );
|
||||
CBaseCombatWeapon *pWeapon = pEntity->MyCombatWeaponPointer();
|
||||
if (!pEntity || !pWeapon)
|
||||
return;
|
||||
|
||||
if (pWeapon->GetOwner() == this)
|
||||
{
|
||||
// Switch to this weapon
|
||||
Weapon_Switch( pWeapon );
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CBaseCombatWeapon *pExistingWeapon = Weapon_OwnsThisType( pWeapon->GetClassname() ))
|
||||
{
|
||||
// Drop our existing weapon then!
|
||||
Weapon_Drop( pExistingWeapon );
|
||||
}
|
||||
|
||||
if (IsNPC())
|
||||
{
|
||||
Weapon_Equip( pWeapon );
|
||||
MyNPCPointer()->OnGivenWeapon( pWeapon );
|
||||
}
|
||||
else
|
||||
{
|
||||
Weapon_Equip( pWeapon );
|
||||
}
|
||||
|
||||
pWeapon->OnPickedUp( this );
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
int CBaseCombatCharacter::ScriptGetAmmoCount( const char *szName ) const
|
||||
|
@ -415,6 +415,8 @@ public:
|
||||
HSCRIPT GetScriptWeaponIndex( int i );
|
||||
HSCRIPT GetScriptWeaponByType( const char *pszWeapon, int iSubType = 0 );
|
||||
|
||||
void ScriptEquipWeapon( HSCRIPT hWeapon );
|
||||
|
||||
int ScriptGetAmmoCount( const char *szName ) const;
|
||||
void ScriptSetAmmoCount( const char *szName, int iCount );
|
||||
|
||||
|
@ -148,6 +148,39 @@ BEGIN_DATADESC_NO_BASE( CFourWheelVehiclePhysics )
|
||||
DEFINE_FIELD( m_bLastSkid, FIELD_BOOLEAN ),
|
||||
END_DATADESC()
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
BEGIN_SCRIPTDESC_ROOT( CFourWheelVehiclePhysics, "Handler for four-wheel vehicle physics." )
|
||||
|
||||
DEFINE_SCRIPTFUNC( SetThrottle, "Sets the throttle." )
|
||||
DEFINE_SCRIPTFUNC( SetMaxThrottle, "Sets the max throttle." )
|
||||
DEFINE_SCRIPTFUNC( SetMaxReverseThrottle, "Sets the max reverse throttle." )
|
||||
DEFINE_SCRIPTFUNC( SetSteering, "Sets the steering." )
|
||||
DEFINE_SCRIPTFUNC( SetSteeringDegrees, "Sets the degrees of steering." )
|
||||
DEFINE_SCRIPTFUNC( SetAction, "Sets the action." )
|
||||
DEFINE_SCRIPTFUNC( SetHandbrake, "Sets the handbrake." )
|
||||
DEFINE_SCRIPTFUNC( SetBoost, "Sets the boost." )
|
||||
DEFINE_SCRIPTFUNC( SetHasBrakePedal, "Sets whether a handbrake pedal exists." )
|
||||
|
||||
DEFINE_SCRIPTFUNC( SetDisableEngine, "Sets whether the engine is disabled." )
|
||||
DEFINE_SCRIPTFUNC( IsEngineDisabled, "Checks whether the engine is disabled." )
|
||||
|
||||
DEFINE_SCRIPTFUNC( EnableMotion, "Enables vehicle motion." )
|
||||
DEFINE_SCRIPTFUNC( DisableMotion, "Disables vehicle motion." )
|
||||
|
||||
DEFINE_SCRIPTFUNC( GetSpeed, "Gets the speed." )
|
||||
DEFINE_SCRIPTFUNC( GetMaxSpeed, "Gets the max speed." )
|
||||
DEFINE_SCRIPTFUNC( GetRPM, "Gets the RPM." )
|
||||
DEFINE_SCRIPTFUNC( GetThrottle, "Gets the throttle." )
|
||||
DEFINE_SCRIPTFUNC( HasBoost, "Checks if the vehicle has the ability to boost." )
|
||||
DEFINE_SCRIPTFUNC( BoostTimeLeft, "Gets how much time is left in any current boost." )
|
||||
DEFINE_SCRIPTFUNC( IsBoosting, "Checks if the vehicle is boosting." )
|
||||
DEFINE_SCRIPTFUNC( GetHLSpeed, "Gets HL speed." )
|
||||
DEFINE_SCRIPTFUNC( GetSteering, "Gets the steeering." )
|
||||
DEFINE_SCRIPTFUNC( GetSteeringDegrees, "Gets the degrees of steeering." )
|
||||
|
||||
END_SCRIPTDESC();
|
||||
#endif
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Constructor
|
||||
|
@ -2457,6 +2457,16 @@ BEGIN_DATADESC( CAI_ActBusyGoal )
|
||||
DEFINE_OUTPUT( m_OnNPCSeeEnemy, "OnNPCSeeEnemy" ),
|
||||
END_DATADESC()
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
BEGIN_ENT_SCRIPTDESC( CAI_ActBusyGoal, CAI_GoalEntity, "A goal entity which makes NPCs act busy." )
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptForceBusy, "ForceBusy", "Force a NPC to act busy." )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptForceBusyComplex, "ForceBusyComplex", "Force a NPC to act busy with additional parameters." )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptStopBusy, "StopBusy", "Force a NPC to stop busying." )
|
||||
|
||||
END_SCRIPTDESC();
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -2824,6 +2834,46 @@ interval_t &CAI_ActBusyGoal::NextBusySearchInterval()
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
void CAI_ActBusyGoal::ScriptForceBusy( HSCRIPT hNPC, HSCRIPT hHint, bool bTeleportOnly )
|
||||
{
|
||||
CAI_ActBusyBehavior *pBehavior = GetBusyBehaviorForNPC( ToEnt( hNPC ), "ForceBusy (vscript)" );
|
||||
if ( !pBehavior )
|
||||
return;
|
||||
|
||||
// Tell the NPC to immediately act busy
|
||||
pBehavior->SetBusySearchRange( m_flBusySearchRange );
|
||||
pBehavior->ForceActBusy( this, dynamic_cast<CAI_Hint*>(ToEnt( hHint )), NO_MAX_TIME, false, bTeleportOnly );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
void CAI_ActBusyGoal::ScriptForceBusyComplex( HSCRIPT hNPC, HSCRIPT hHint, bool bTeleportOnly, bool bVisibleOnly, bool bUseNearestBusy, float flMaxTime, int activity, HSCRIPT pSeeEntity )
|
||||
{
|
||||
CAI_ActBusyBehavior *pBehavior = GetBusyBehaviorForNPC( ToEnt( hNPC ), "ForceBusyComplex (vscript)" );
|
||||
if ( !pBehavior )
|
||||
return;
|
||||
|
||||
// Tell the NPC to immediately act busy
|
||||
pBehavior->SetBusySearchRange( m_flBusySearchRange );
|
||||
pBehavior->ForceActBusy( this, dynamic_cast<CAI_Hint*>(ToEnt( hHint )), flMaxTime, bVisibleOnly, bTeleportOnly, bUseNearestBusy, ToEnt( pSeeEntity ), (Activity)activity );
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------------
|
||||
void CAI_ActBusyGoal::ScriptStopBusy( HSCRIPT hNPC )
|
||||
{
|
||||
CAI_ActBusyBehavior *pBehavior = GetBusyBehaviorForNPC( ToEnt( hNPC ), "StopBusy (vscript)" );
|
||||
if ( !pBehavior )
|
||||
return;
|
||||
|
||||
// Just stop busying
|
||||
pBehavior->StopBusying();
|
||||
}
|
||||
#endif
|
||||
|
||||
//==========================================================================================================
|
||||
// ACT BUSY QUEUE
|
||||
//==========================================================================================================
|
||||
|
@ -239,6 +239,12 @@ public:
|
||||
interval_t &NextBusySearchInterval();
|
||||
#endif
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
void ScriptForceBusy( HSCRIPT hNPC, HSCRIPT hHint, bool bTeleportOnly );
|
||||
void ScriptForceBusyComplex( HSCRIPT hNPC, HSCRIPT hHint, bool bTeleportOnly, bool bVisibleOnly, bool bUseNearestBusy, float flMaxTime, int activity, HSCRIPT pSeeEntity );
|
||||
void ScriptStopBusy( HSCRIPT hNPC );
|
||||
#endif
|
||||
|
||||
protected:
|
||||
CAI_ActBusyBehavior *GetBusyBehaviorForNPC( const char *pszActorName, CBaseEntity *pActivator, CBaseEntity *pCaller, const char *sInputName );
|
||||
CAI_ActBusyBehavior *GetBusyBehaviorForNPC( CBaseEntity *pEntity, const char *sInputName );
|
||||
@ -257,6 +263,9 @@ protected:
|
||||
#endif
|
||||
|
||||
DECLARE_DATADESC();
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
DECLARE_ENT_SCRIPTDESC();
|
||||
#endif
|
||||
|
||||
protected:
|
||||
float m_flBusySearchRange;
|
||||
|
@ -3799,7 +3799,8 @@ BEGIN_DATADESC( CLogicConsole )
|
||||
|
||||
END_DATADESC()
|
||||
|
||||
ConVar sv_allow_logic_convar("sv_allow_logic_convar", "1");
|
||||
ConVar sv_allow_logic_convar( "sv_allow_logic_convar", "1", FCVAR_NOT_CONNECTED );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Gets console variables for the evil mapper.
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -91,8 +91,9 @@ void CV_InitMod()
|
||||
|
||||
void CVEnt_Precache(CMapbaseCVarModEntity *modent)
|
||||
{
|
||||
if (Q_strstr(STRING(modent->m_target), "sv_allow_logic_convar"))
|
||||
return;
|
||||
// Now protected by FCVAR_NOT_CONNECTED
|
||||
//if (Q_strstr(STRING(modent->m_target), "sv_allow_logic_convar"))
|
||||
// return;
|
||||
|
||||
#ifdef MAPBASE_MP
|
||||
if (gpGlobals->maxClients > 1 && !modent->m_bUseServer)
|
||||
|
@ -66,6 +66,15 @@ BEGIN_DATADESC( CPropVehicle )
|
||||
|
||||
END_DATADESC()
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
BEGIN_ENT_SCRIPTDESC( CPropVehicle, CBaseAnimating, "The base class for four-wheel physics vehicles." )
|
||||
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetVehicleType, "GetVehicleType", "Get a vehicle's type." )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetPhysics, "GetPhysics", "Get a vehicle's physics." )
|
||||
|
||||
END_SCRIPTDESC();
|
||||
#endif
|
||||
|
||||
LINK_ENTITY_TO_CLASS( prop_vehicle, CPropVehicle );
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -226,6 +235,23 @@ void CPropVehicle::InputHandBrakeOff( inputdata_t &inputdata )
|
||||
m_VehiclePhysics.ReleaseHandbrake();
|
||||
}
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
HSCRIPT CPropVehicle::ScriptGetPhysics()
|
||||
{
|
||||
HSCRIPT hScript = NULL;
|
||||
CFourWheelVehiclePhysics *pPhysics = GetPhysics();
|
||||
if (pPhysics)
|
||||
{
|
||||
hScript = g_pScriptVM->RegisterInstance( pPhysics );
|
||||
}
|
||||
|
||||
return hScript;
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -379,6 +405,19 @@ BEGIN_DATADESC( CPropVehicleDriveable )
|
||||
|
||||
END_DATADESC()
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
BEGIN_ENT_SCRIPTDESC( CPropVehicleDriveable, CPropVehicle, "The base class for driveable vehicles." )
|
||||
|
||||
DEFINE_SCRIPTFUNC( IsOverturned, "Check if the vehicle is overturned." )
|
||||
DEFINE_SCRIPTFUNC( IsVehicleBodyInWater, "Check if the vehicle's body is submerged in water." )
|
||||
DEFINE_SCRIPTFUNC( StartEngine, "Start the engine." )
|
||||
DEFINE_SCRIPTFUNC( StopEngine, "Stop the engine." )
|
||||
DEFINE_SCRIPTFUNC( IsEngineOn, "Check if the engine is on." )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptGetDriver, "GetDriver", "Get a vehicle's driver, which could be either a player or a npc_vehicledriver." )
|
||||
|
||||
END_SCRIPTDESC();
|
||||
#endif
|
||||
|
||||
|
||||
LINK_ENTITY_TO_CLASS( prop_vehicle_driveable, CPropVehicleDriveable );
|
||||
|
||||
|
@ -109,6 +109,12 @@ public:
|
||||
void InputHandBrakeOff( inputdata_t &inputdata );
|
||||
|
||||
DECLARE_DATADESC();
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
DECLARE_ENT_SCRIPTDESC();
|
||||
|
||||
HSCRIPT ScriptGetPhysics();
|
||||
int ScriptGetVehicleType() { return GetVehicleType(); }
|
||||
#endif
|
||||
|
||||
#ifdef HL2_EPISODIC
|
||||
void AddPhysicsChild( CBaseEntity *pChild );
|
||||
@ -166,6 +172,9 @@ class CPropVehicleDriveable : public CPropVehicle, public IDrivableVehicle, publ
|
||||
DECLARE_CLASS( CPropVehicleDriveable, CPropVehicle );
|
||||
DECLARE_SERVERCLASS();
|
||||
DECLARE_DATADESC();
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
DECLARE_ENT_SCRIPTDESC();
|
||||
#endif
|
||||
public:
|
||||
CPropVehicleDriveable( void );
|
||||
~CPropVehicleDriveable( void );
|
||||
@ -238,6 +247,10 @@ public:
|
||||
// If this is a vehicle, returns the vehicle interface
|
||||
virtual IServerVehicle *GetServerVehicle() { return m_pServerVehicle; }
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
HSCRIPT ScriptGetDriver() { return ToHScript( GetDriver() ); }
|
||||
#endif
|
||||
|
||||
protected:
|
||||
|
||||
virtual bool ShouldThink() { return ( GetDriver() != NULL ); }
|
||||
|
@ -19,6 +19,57 @@
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
class CScriptConvarLookup
|
||||
{
|
||||
public:
|
||||
|
||||
#ifndef CLIENT_DLL
|
||||
const char *GetClientConvarValue( const char *pszConVar, int entindex )
|
||||
{
|
||||
return engine->GetClientConVarValue( entindex, pszConVar );
|
||||
}
|
||||
#endif
|
||||
|
||||
const char *GetStr( const char *pszConVar )
|
||||
{
|
||||
ConVarRef cvar( pszConVar );
|
||||
return cvar.GetString();
|
||||
}
|
||||
|
||||
float GetFloat( const char *pszConVar )
|
||||
{
|
||||
ConVarRef cvar( pszConVar );
|
||||
return cvar.GetFloat();
|
||||
}
|
||||
|
||||
void SetValue( const char *pszConVar, const char *pszValue )
|
||||
{
|
||||
ConVarRef cvar( pszConVar );
|
||||
if (!cvar.IsValid())
|
||||
return;
|
||||
|
||||
// FCVAR_NOT_CONNECTED can be used to protect specific convars from nefarious interference
|
||||
if (cvar.IsFlagSet(FCVAR_NOT_CONNECTED))
|
||||
return;
|
||||
|
||||
cvar.SetValue( pszValue );
|
||||
}
|
||||
|
||||
private:
|
||||
} g_ScriptConvarLookup;
|
||||
|
||||
BEGIN_SCRIPTDESC_ROOT_NAMED( CScriptConvarLookup, "Convars", SCRIPT_SINGLETON "Provides an interface for getting and setting convars." )
|
||||
#ifndef CLIENT_DLL
|
||||
DEFINE_SCRIPTFUNC( GetClientConvarValue, "Returns the convar value for the entindex as a string. Only works with client convars with the FCVAR_USERINFO flag." )
|
||||
#endif
|
||||
DEFINE_SCRIPTFUNC( GetStr, "Returns the convar as a string. May return null if no such convar." )
|
||||
DEFINE_SCRIPTFUNC( GetFloat, "Returns the convar as a float. May return null if no such convar." )
|
||||
DEFINE_SCRIPTFUNC( SetValue, "Sets the value of the convar. Supported types are bool, int, float, string." )
|
||||
END_SCRIPTDESC();
|
||||
|
||||
#ifndef CLIENT_DLL
|
||||
extern ConVar sv_script_think_interval;
|
||||
|
||||
@ -180,6 +231,8 @@ void RegisterSharedScriptFunctions()
|
||||
ScriptRegisterFunction( g_pScriptVM, SpawnEntityFromTable, "Native function for entity spawning." );
|
||||
#endif
|
||||
|
||||
g_pScriptVM->RegisterInstance( &g_ScriptConvarLookup, "Convars" );
|
||||
|
||||
// Functions unique to Mapbase
|
||||
#ifndef CLIENT_DLL
|
||||
ScriptRegisterFunction( g_pScriptVM, SpawnEntityFromKeyValues, "Spawns an entity with the keyvalues in a CScriptKeyValues handle." );
|
||||
|
Loading…
x
Reference in New Issue
Block a user