Change CallClientScriptFunction UserMsg to EntityMsg

This commit is contained in:
samisalreadytaken 2022-03-06 18:46:00 +03:00
parent f2f874939d
commit 5e444b2db9
2 changed files with 30 additions and 43 deletions

View File

@ -187,23 +187,41 @@ public:
BaseClass::OnRestore(); BaseClass::OnRestore();
} }
#else
void InputCallScriptFunctionClient( inputdata_t &inputdata )
{
// TODO: Support for specific players?
CBroadcastRecipientFilter filter;
filter.MakeReliable();
const char *pszFunction = inputdata.value.String(); void ReceiveMessage( int classID, bf_read &msg )
if (strlen( pszFunction ) > 64) {
if ( classID != GetClientClass()->m_ClassID )
{ {
Msg("%s CallScriptFunctionClient: \"%s\" is too long at %i characters, must be 64 or less\n", GetDebugName(), pszFunction, strlen(pszFunction)); BaseClass::ReceiveMessage( classID, msg );
return; return;
} }
UserMessageBegin( filter, "CallClientScriptFunction" ); char szFunction[64];
WRITE_STRING( pszFunction ); // function msg.ReadString( szFunction, sizeof( szFunction ) );
WRITE_SHORT( entindex() ); // entity
if ( m_ScriptScope.IsInitialized() )
{
CallScriptFunction( szFunction, NULL );
}
else
{
CGMsg( 0, CON_GROUP_VSCRIPT, "%s script scope not initialized!\n", GetDebugName() );
}
}
#endif
#ifdef GAME_DLL
void InputCallScriptFunctionClient( inputdata_t &inputdata )
{
const char *pszFunction = inputdata.value.String();
if ( V_strlen( pszFunction ) >= 64 )
{
Msg( "%s CallScriptFunctionClient: \"%s\" is too long at %i characters, must be 64 or less\n", GetDebugName(), pszFunction, V_strlen(pszFunction)+1 );
return;
}
EntityMessageBegin( this, true );
WRITE_STRING( pszFunction );
MessageEnd(); MessageEnd();
} }
#endif #endif

View File

@ -16,39 +16,9 @@
#include "tier0/memdbgon.h" #include "tier0/memdbgon.h"
#ifdef CLIENT_DLL #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 ) void HookMapbaseUserMessages( void )
{ {
// VScript // VScript
HOOK_MESSAGE( CallClientScriptFunction );
//HOOK_MESSAGE( ScriptMsg ); // Hooked in CNetMsgScriptHelper //HOOK_MESSAGE( ScriptMsg ); // Hooked in CNetMsgScriptHelper
} }
#endif #endif
@ -56,7 +26,6 @@ void HookMapbaseUserMessages( void )
void RegisterMapbaseUserMessages( void ) void RegisterMapbaseUserMessages( void )
{ {
// VScript // VScript
usermessages->Register( "CallClientScriptFunction", -1 );
usermessages->Register( "ScriptMsg", -1 ); // CNetMsgScriptHelper usermessages->Register( "ScriptMsg", -1 ); // CNetMsgScriptHelper
#ifdef CLIENT_DLL #ifdef CLIENT_DLL