mirror of
https://github.com/celisej567/source-sdk-2013.git
synced 2026-09-23 20:09:45 +03:00
Mapbase VScript server/client expansions
This commit is contained in:
@@ -244,7 +244,7 @@ public:
|
||||
pKV->deleteThis();
|
||||
}
|
||||
|
||||
void AddManifestFile( const char *file, bool bDontStore = false )
|
||||
void AddManifestFile( const char *file )
|
||||
{
|
||||
KeyValues *pKV = new KeyValues(file);
|
||||
if ( !pKV->LoadFromFile( filesystem, file ) )
|
||||
@@ -364,6 +364,21 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
void ScriptAddManifestFile( const char *szScript ) { AddManifestFile( szScript ); }
|
||||
|
||||
void LoadSoundscriptFile( const char *szScript ) { LoadFromValue(szScript, MANIFEST_SOUNDSCRIPTS, false); }
|
||||
#ifndef CLIENT_DLL
|
||||
void LoadTalkerFile( const char *szScript ) { LoadFromValue( szScript, MANIFEST_TALKER, false ); }
|
||||
void LoadActbusyFile( const char *szScript ) { LoadFromValue( szScript, MANIFEST_ACTBUSY, false ); }
|
||||
#endif
|
||||
|
||||
virtual void RegisterVScript()
|
||||
{
|
||||
g_pScriptVM->RegisterInstance( this, "Mapbase" );
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
CMapbaseSystem g_MapbaseSystem;
|
||||
@@ -374,6 +389,17 @@ BEGIN_DATADESC_NO_BASE( CMapbaseSystem )
|
||||
|
||||
END_DATADESC()
|
||||
|
||||
#ifdef MAPBASE_VSCRIPT
|
||||
BEGIN_SCRIPTDESC_ROOT( CMapbaseSystem, SCRIPT_SINGLETON "All-purpose Mapbase system primarily used for map-specific files." )
|
||||
DEFINE_SCRIPTFUNC_NAMED( ScriptAddManifestFile, "AddManifestFile", "Loads a manifest file." )
|
||||
DEFINE_SCRIPTFUNC( LoadSoundscriptFile, "Loads a custom soundscript file." )
|
||||
#ifndef CLIENT_DLL
|
||||
DEFINE_SCRIPTFUNC( LoadTalkerFile, "Loads a custom talker file." )
|
||||
DEFINE_SCRIPTFUNC( LoadActbusyFile, "Loads a custom actbusy file." )
|
||||
#endif
|
||||
END_SCRIPTDESC();
|
||||
#endif
|
||||
|
||||
#ifdef GAME_DLL
|
||||
static CUtlVector<MODTITLECOMMENT> g_MapbaseChapterMaps;
|
||||
static CUtlVector<MODCHAPTER> g_MapbaseChapterList;
|
||||
@@ -437,7 +463,7 @@ ThreeState_t Flashlight_GetLegacyVersionKey()
|
||||
|
||||
static void CC_Mapbase_LoadManifestFile( const CCommand& args )
|
||||
{
|
||||
g_MapbaseSystem.AddManifestFile(args[1], args[2]);
|
||||
g_MapbaseSystem.AddManifestFile(args[1]);
|
||||
}
|
||||
|
||||
static ConCommand mapbase_loadmanifestfile("mapbase_loadmanifestfile", CC_Mapbase_LoadManifestFile, "Loads a Mapbase manifest file. If you don't want this to be saved and found when reloaded, type a '1' after the file path." );
|
||||
|
||||
68
sp/src/game/shared/mapbase/vscript_funcs_hl2.cpp
Normal file
68
sp/src/game/shared/mapbase/vscript_funcs_hl2.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: VScript functions for Half-Life 2.
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "cbase.h"
|
||||
|
||||
#include "hl2_gamerules.h"
|
||||
#ifndef CLIENT_DLL
|
||||
#include "eventqueue.h"
|
||||
#endif
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
|
||||
#ifndef CLIENT_DLL
|
||||
extern CBaseEntity *CreatePlayerLoadSave( Vector vOrigin, float flDuration, float flHoldTime, float flLoadTime );
|
||||
|
||||
HSCRIPT ScriptGameOver( const char *pszMessage, float flDelay, float flFadeTime, float flLoadTime, int r, int g, int b )
|
||||
{
|
||||
CBaseEntity *pPlayer = AI_GetSinglePlayer();
|
||||
if (pPlayer)
|
||||
{
|
||||
UTIL_ShowMessage( pszMessage, ToBasePlayer( pPlayer ) );
|
||||
ToBasePlayer( pPlayer )->NotifySinglePlayerGameEnding();
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: How should MP handle this?
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CBaseEntity *pReload = CreatePlayerLoadSave( vec3_origin, flFadeTime, flLoadTime + 1.0f, flLoadTime );
|
||||
if (pReload)
|
||||
{
|
||||
pReload->SetRenderColor( r, g, b, 255 );
|
||||
g_EventQueue.AddEvent( pReload, "Reload", flDelay, pReload, pReload );
|
||||
}
|
||||
|
||||
return ToHScript( pReload );
|
||||
}
|
||||
|
||||
bool ScriptMegaPhyscannonActive()
|
||||
{
|
||||
return HL2GameRules()->MegaPhyscannonActive();
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Returns how much damage the given ammo type should do to the victim
|
||||
// when fired by the attacker.
|
||||
// Input : pAttacker - Dude what shot the gun.
|
||||
// pVictim - Dude what done got shot.
|
||||
// nAmmoType - What been shot out.
|
||||
// Output : How much hurt to put on dude what done got shot (pVictim).
|
||||
//-----------------------------------------------------------------------------
|
||||
void CHalfLife2::RegisterScriptFunctions( void )
|
||||
{
|
||||
BaseClass::RegisterScriptFunctions();
|
||||
|
||||
#ifndef CLIENT_DLL
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptGameOver, "GameOver", "Ends the game and reloads the last save." );
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, ScriptMegaPhyscannonActive, "MegaPhyscannonActive", "Checks if supercharged gravity gun mode is enabled." );
|
||||
#endif
|
||||
}
|
||||
112
sp/src/game/shared/mapbase/vscript_funcs_shared.cpp
Normal file
112
sp/src/game/shared/mapbase/vscript_funcs_shared.cpp
Normal file
@@ -0,0 +1,112 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose: Due to this being a custom integration of VScript based on the Alien Swarm SDK, we don't have access to
|
||||
// some of the code normally available in games like L4D2 or Valve's original VScript DLL.
|
||||
// Instead, that code is recreated here, shared between server and client.
|
||||
//
|
||||
// It also contains other functions unique to Mapbase.
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#include "cbase.h"
|
||||
|
||||
#ifndef CLIENT_DLL
|
||||
#include "globalstate.h"
|
||||
#include "vscript_server.h"
|
||||
#endif
|
||||
|
||||
// memdbgon must be the last include file in a .cpp file!!!
|
||||
#include "tier0/memdbgon.h"
|
||||
|
||||
#ifndef CLIENT_DLL
|
||||
extern ConVar sv_script_think_interval;
|
||||
|
||||
void AddThinkToEnt( HSCRIPT entity, const char *pszFuncName )
|
||||
{
|
||||
CBaseEntity *pEntity = ToEnt( entity );
|
||||
if (!pEntity)
|
||||
return;
|
||||
|
||||
if (pszFuncName == NULL || pszFuncName[0] == '\0')
|
||||
pEntity->m_iszScriptThinkFunction = NULL_STRING;
|
||||
else
|
||||
pEntity->m_iszScriptThinkFunction = AllocPooledString(pszFuncName);
|
||||
|
||||
pEntity->SetContextThink( &CBaseEntity::ScriptThink, gpGlobals->curtime + sv_script_think_interval.GetFloat(), "ScriptThink" );
|
||||
}
|
||||
|
||||
HSCRIPT EntIndexToHScript( int index )
|
||||
{
|
||||
return ToHScript( UTIL_EntityByIndex( index ) );
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Mapbase-specific functions start here
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
#ifndef CLIENT_DLL
|
||||
inline CScriptKeyValues *ToScriptKeyValues( HSCRIPT hKV )
|
||||
{
|
||||
return (hKV) ? (CScriptKeyValues*)g_pScriptVM->GetInstanceValue( hKV, GetScriptDescForClass( CScriptKeyValues ) ) : NULL;
|
||||
}
|
||||
|
||||
// Since IScriptVM::GetKeyValue() is unsupported, Mapbase uses this CScriptKeyValues version
|
||||
HSCRIPT SpawnEntityFromKeyValues( const char *pszClassname, HSCRIPT hKV )
|
||||
{
|
||||
CBaseEntity *pEntity = CreateEntityByName( pszClassname );
|
||||
if ( !pEntity )
|
||||
{
|
||||
Assert( !"SpawnEntityFromTable: only works for CBaseEntities" );
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gEntList.NotifyCreateEntity( pEntity );
|
||||
|
||||
CScriptKeyValues *pScriptKV = ToScriptKeyValues( hKV );
|
||||
if (pScriptKV)
|
||||
{
|
||||
KeyValues *pKV = pScriptKV->m_pKeyValues;
|
||||
for (pKV = pKV->GetFirstSubKey(); pKV != NULL; pKV = pKV->GetNextKey())
|
||||
{
|
||||
//g_pScriptVM->GetKeyValue( hKV, i, &varKey, &varValue );
|
||||
pEntity->KeyValue( pKV->GetName(), pKV->GetString() );
|
||||
}
|
||||
}
|
||||
|
||||
DispatchSpawn( pEntity );
|
||||
|
||||
return ToHScript( pEntity );
|
||||
}
|
||||
#endif
|
||||
|
||||
void RegisterSharedScriptFunctions()
|
||||
{
|
||||
//
|
||||
// Due to this being a custom integration of VScript based on the Alien Swarm SDK, we don't have access to
|
||||
// some of the code normally available in games like L4D2 or Valve's original VScript DLL.
|
||||
// Instead, that code is recreated here, shared between server and client.
|
||||
//
|
||||
ScriptRegisterFunction( g_pScriptVM, RandomFloat, "Generate a random floating point number within a range, inclusive." );
|
||||
ScriptRegisterFunction( g_pScriptVM, RandomInt, "Generate a random integer within a range, inclusive." );
|
||||
|
||||
#ifndef CLIENT_DLL
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, NDebugOverlay::BoxDirection, "DebugDrawBoxDirection", "Draw a debug forward box" );
|
||||
ScriptRegisterFunctionNamed( g_pScriptVM, NDebugOverlay::Text, "DebugDrawText", "Draw a debug overlay text" );
|
||||
|
||||
ScriptRegisterFunction( g_pScriptVM, AddThinkToEnt, "This will put a think function onto an entity, or pass null to remove it. This is NOT chained, so be careful." );
|
||||
ScriptRegisterFunction( g_pScriptVM, EntIndexToHScript, "Returns the script handle for the given entity index." );
|
||||
#endif
|
||||
|
||||
// Functions unique to Mapbase
|
||||
#ifndef CLIENT_DLL
|
||||
ScriptRegisterFunction( g_pScriptVM, SpawnEntityFromKeyValues, "Spawns an entity with the keyvalues in a CScriptKeyValues handle." );
|
||||
#endif
|
||||
|
||||
#ifdef CLIENT_DLL
|
||||
VScriptRunScript( "vscript_client", true );
|
||||
#else
|
||||
VScriptRunScript( "vscript_server", true );
|
||||
#endif
|
||||
}
|
||||
Reference in New Issue
Block a user