Added logic_script_client entity and a user message for calling a client-side function

This commit is contained in:
Blixibon
2020-12-24 23:55:19 -06:00
parent 6ba3cd4c03
commit 6f0781b5b8
3 changed files with 236 additions and 0 deletions

View File

@@ -16,10 +16,12 @@
#include "saverestore_utlvector.h"
#include "props_shared.h"
#include "utlbuffer.h"
#include "usermessages.h"
#ifdef CLIENT_DLL
#include "hud_closecaption.h"
#include "panelmetaclassmgr.h"
#include "c_soundscape.h"
#include "hud_macros.h"
#else
#include "soundscape_system.h"
#include "AI_ResponseSystem.h"
@@ -616,3 +618,48 @@ BEGIN_DATADESC( CMapbaseManifestEntity )
END_DATADESC()
#endif
#ifdef CLIENT_DLL
void __MsgFunc_CallClientScriptFunction( bf_read &msg )
{
char szFunction[64];
if (!msg.ReadString( szFunction, sizeof( szFunction ) ))
{
CGMsg( 0, CON_GROUP_VSCRIPT, "Unable to read function string\n" );
}
int idx = msg.ReadByte();
C_BaseEntity *pEntity = CBaseEntity::Instance( idx );
if (pEntity)
{
if (pEntity->m_ScriptScope.IsInitialized())
{
//CGMsg( 0, CON_GROUP_VSCRIPT, "%s calling function \"%s\"\n", pEntity->GetDebugName(), szFunction );
pEntity->CallScriptFunction( szFunction, NULL );
}
else
{
CGMsg( 0, CON_GROUP_VSCRIPT, "%s scope not initialized\n", pEntity->GetDebugName() );
}
}
else
{
CGMsg( 0, CON_GROUP_VSCRIPT, "Clientside entity not found for script function (index %i)\n", idx );
}
}
void HookMapbaseUserMessages( void )
{
HOOK_MESSAGE( CallClientScriptFunction );
}
#endif
void RegisterMapbaseUserMessages( void )
{
usermessages->Register( "CallClientScriptFunction", -1 );
#ifdef CLIENT_DLL
HookMapbaseUserMessages();
#endif
}