Add SourceTV_PrintToConsole native
Print text to single spectators' console.
This commit is contained in:
parent
ef76571d74
commit
307a8037d6
46
natives.cpp
46
natives.cpp
@ -40,12 +40,13 @@ extern const sp_nativeinfo_t sourcetv_natives[];
|
|||||||
|
|
||||||
// Print to client consoles
|
// Print to client consoles
|
||||||
SH_DECL_MANUALHOOK0_void_vafmt(CBaseServer_BroadcastPrintf, 0, 0, 0);
|
SH_DECL_MANUALHOOK0_void_vafmt(CBaseServer_BroadcastPrintf, 0, 0, 0);
|
||||||
|
// For print to chat
|
||||||
bool g_bHasClientPrintfOffset = false;
|
|
||||||
SH_DECL_MANUALHOOK1_void(CBaseClient_FireGameEvent, 0, 0, 0, IGameEvent *);
|
SH_DECL_MANUALHOOK1_void(CBaseClient_FireGameEvent, 0, 0, 0, IGameEvent *);
|
||||||
|
|
||||||
void SetupNativeCalls()
|
bool g_bHasBroadcastPrintfOffset = false;
|
||||||
bool g_bHasClientFireGameEventOffset = false;
|
bool g_bHasClientFireGameEventOffset = false;
|
||||||
|
|
||||||
|
void SetupNativeCalls()
|
||||||
{
|
{
|
||||||
int offset = -1;
|
int offset = -1;
|
||||||
if (!g_pGameConf->GetOffset("CBaseServer::BroadcastPrintf", &offset) || offset == -1)
|
if (!g_pGameConf->GetOffset("CBaseServer::BroadcastPrintf", &offset) || offset == -1)
|
||||||
@ -55,7 +56,7 @@ bool g_bHasClientFireGameEventOffset = false;
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
SH_MANUALHOOK_RECONFIGURE(CBaseServer_BroadcastPrintf, offset, 0, 0);
|
SH_MANUALHOOK_RECONFIGURE(CBaseServer_BroadcastPrintf, offset, 0, 0);
|
||||||
g_bHasClientPrintfOffset = true;
|
g_bHasBroadcastPrintfOffset = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
offset = -1;
|
offset = -1;
|
||||||
@ -307,7 +308,7 @@ static cell_t Native_BroadcastConsoleMessage(IPluginContext *pContext, const cel
|
|||||||
if (hltvserver == nullptr)
|
if (hltvserver == nullptr)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (!g_bHasClientPrintfOffset)
|
if (!g_bHasBroadcastPrintfOffset)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
char buffer[1024];
|
char buffer[1024];
|
||||||
@ -854,6 +855,40 @@ static cell_t Native_PrintToChat(IPluginContext *pContext, const cell_t *params)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// native SourceTV_PrintToConsole(client, const String:format[], any:...);
|
||||||
|
static cell_t Native_PrintToConsole(IPluginContext *pContext, const cell_t *params)
|
||||||
|
{
|
||||||
|
if (hltvserver == nullptr)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
cell_t client = params[1];
|
||||||
|
if (client < 1 || client > hltvserver->GetBaseServer()->GetClientCount())
|
||||||
|
{
|
||||||
|
pContext->ReportError("Invalid spectator client index %d.", client);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
HLTVClientWrapper *pClient = hltvserver->GetClient(client);
|
||||||
|
if (!pClient->IsConnected())
|
||||||
|
{
|
||||||
|
pContext->ReportError("Client %d is not connected.", client);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
char buffer[1024];
|
||||||
|
size_t len;
|
||||||
|
{
|
||||||
|
DetectExceptions eh(pContext);
|
||||||
|
len = smutils->FormatString(buffer, sizeof(buffer), pContext, params, 2);
|
||||||
|
if (eh.HasException())
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pClient->BaseClient()->ClientPrintf("%s\n", buffer);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
const sp_nativeinfo_t sourcetv_natives[] =
|
const sp_nativeinfo_t sourcetv_natives[] =
|
||||||
{
|
{
|
||||||
{ "SourceTV_GetServerInstanceCount", Native_GetServerInstanceCount },
|
{ "SourceTV_GetServerInstanceCount", Native_GetServerInstanceCount },
|
||||||
@ -891,5 +926,6 @@ const sp_nativeinfo_t sourcetv_natives[] =
|
|||||||
{ "SourceTV_GetClientPassword", Native_GetClientPassword },
|
{ "SourceTV_GetClientPassword", Native_GetClientPassword },
|
||||||
{ "SourceTV_KickClient", Native_KickClient },
|
{ "SourceTV_KickClient", Native_KickClient },
|
||||||
{ "SourceTV_PrintToChat", Native_PrintToChat },
|
{ "SourceTV_PrintToChat", Native_PrintToChat },
|
||||||
|
{ "SourceTV_PrintToConsole", Native_PrintToConsole },
|
||||||
{ NULL, NULL },
|
{ NULL, NULL },
|
||||||
};
|
};
|
||||||
|
@ -20,7 +20,7 @@ public OnPluginStart()
|
|||||||
RegConsoleCmd("sm_spechintmsg", Cmd_SendHintMessage);
|
RegConsoleCmd("sm_spechintmsg", Cmd_SendHintMessage);
|
||||||
RegConsoleCmd("sm_specchat", Cmd_SendChatMessage);
|
RegConsoleCmd("sm_specchat", Cmd_SendChatMessage);
|
||||||
RegConsoleCmd("sm_specchatlocal", Cmd_SendChatMessageLocal);
|
RegConsoleCmd("sm_specchatlocal", Cmd_SendChatMessageLocal);
|
||||||
RegConsoleCmd("sm_specmsg", Cmd_SendMessage);
|
RegConsoleCmd("sm_specconsole", Cmd_SendMessage);
|
||||||
RegConsoleCmd("sm_viewentity", Cmd_GetViewEntity);
|
RegConsoleCmd("sm_viewentity", Cmd_GetViewEntity);
|
||||||
RegConsoleCmd("sm_vieworigin", Cmd_GetViewOrigin);
|
RegConsoleCmd("sm_vieworigin", Cmd_GetViewOrigin);
|
||||||
RegConsoleCmd("sm_forcechasecam", Cmd_ForceChaseCameraShot);
|
RegConsoleCmd("sm_forcechasecam", Cmd_ForceChaseCameraShot);
|
||||||
@ -35,6 +35,7 @@ public OnPluginStart()
|
|||||||
RegConsoleCmd("sm_botcmd", Cmd_ExecuteStringCommand);
|
RegConsoleCmd("sm_botcmd", Cmd_ExecuteStringCommand);
|
||||||
RegConsoleCmd("sm_speckick", Cmd_KickClient);
|
RegConsoleCmd("sm_speckick", Cmd_KickClient);
|
||||||
RegConsoleCmd("sm_specchatone", Cmd_PrintToChat);
|
RegConsoleCmd("sm_specchatone", Cmd_PrintToChat);
|
||||||
|
RegConsoleCmd("sm_specconsoleone", Cmd_PrintToConsole);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SourceTV_OnStartRecording(instance, const String:filename[])
|
public SourceTV_OnStartRecording(instance, const String:filename[])
|
||||||
@ -228,7 +229,7 @@ public Action:Cmd_SendMessage(client, args)
|
|||||||
{
|
{
|
||||||
if (args < 1)
|
if (args < 1)
|
||||||
{
|
{
|
||||||
ReplyToCommand(client, "Usage: sm_specmsg <message>");
|
ReplyToCommand(client, "Usage: sm_specconsole <message>");
|
||||||
return Plugin_Handled;
|
return Plugin_Handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -450,4 +451,24 @@ public Action:Cmd_PrintToChat(client, args)
|
|||||||
SourceTV_PrintToChat(iTarget, "%s", sMsg);
|
SourceTV_PrintToChat(iTarget, "%s", sMsg);
|
||||||
ReplyToCommand(client, "SourceTV sending chat message to spectator %d: %s", iTarget, sMsg);
|
ReplyToCommand(client, "SourceTV sending chat message to spectator %d: %s", iTarget, sMsg);
|
||||||
return Plugin_Handled;
|
return Plugin_Handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Action:Cmd_PrintToConsole(client, args)
|
||||||
|
{
|
||||||
|
if (args < 2)
|
||||||
|
{
|
||||||
|
ReplyToCommand(client, "Usage: sm_specconsoleone <index> <message>");
|
||||||
|
return Plugin_Handled;
|
||||||
|
}
|
||||||
|
|
||||||
|
new String:sIndex[16], String:sMsg[1024];
|
||||||
|
GetCmdArg(1, sIndex, sizeof(sIndex));
|
||||||
|
StripQuotes(sIndex);
|
||||||
|
GetCmdArg(2, sMsg, sizeof(sMsg));
|
||||||
|
StripQuotes(sMsg);
|
||||||
|
|
||||||
|
new iTarget = StringToInt(sIndex);
|
||||||
|
SourceTV_PrintToConsole(iTarget, "%s", sMsg);
|
||||||
|
ReplyToCommand(client, "SourceTV sending console message to spectator %d: %s", iTarget, sMsg);
|
||||||
|
return Plugin_Handled;
|
||||||
}
|
}
|
@ -404,6 +404,17 @@ native SourceTV_KickClient(client, const String:sReason[]);
|
|||||||
*/
|
*/
|
||||||
native SourceTV_PrintToChat(client, const String:format[], any:...);
|
native SourceTV_PrintToChat(client, const String:format[], any:...);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Print a message to a single client's console.
|
||||||
|
*
|
||||||
|
* @param client The spectator client index.
|
||||||
|
* @param format The format string.
|
||||||
|
* @param ... Variable number of format string arguments.
|
||||||
|
* @noreturn
|
||||||
|
* @error Invalid client index or not connected.
|
||||||
|
*/
|
||||||
|
native SourceTV_PrintToConsole(client, const String:format[], any:...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a spectator wants to connect to the SourceTV server.
|
* Called when a spectator wants to connect to the SourceTV server.
|
||||||
* This is called before any other validation has happened.
|
* This is called before any other validation has happened.
|
||||||
@ -531,5 +542,6 @@ public __ext_stvmngr_SetNTVOptional()
|
|||||||
MarkNativeAsOptional("SourceTV_GetClientPassword");
|
MarkNativeAsOptional("SourceTV_GetClientPassword");
|
||||||
MarkNativeAsOptional("SourceTV_KickClient");
|
MarkNativeAsOptional("SourceTV_KickClient");
|
||||||
MarkNativeAsOptional("SourceTV_PrintToChat");
|
MarkNativeAsOptional("SourceTV_PrintToChat");
|
||||||
|
MarkNativeAsOptional("SourceTV_PrintToConsole");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user