- Added natives: PrintToChat() and PrintCenterText()

- Bit of reorganization with moving some natives from sourcemod.inc to halflife.inc

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40879
This commit is contained in:
Scott Ehlert
2007-06-01 06:33:54 +00:00
parent 1ab452c897
commit 6c17b9f37b
11 changed files with 322 additions and 212 deletions
+17
View File
@@ -15,6 +15,7 @@
#include "HalfLife2.h"
#include "sourcemod.h"
#include "sourcemm_api.h"
#include "UserMessages.h"
CHalfLife2 g_HL2;
bool g_IsOriginalEngine = false;
@@ -81,6 +82,11 @@ void CHalfLife2::OnSourceModStartup(bool late)
}
}
void CHalfLife2::OnSourceModAllInitialized()
{
m_MsgTextMsg = g_UserMsgs.GetMessageIndex("TextMsg");
}
IChangeInfoAccessor *CBaseEdict::GetChangeAccessor()
{
return engine->GetChangeAccessor( (const edict_t *)this );
@@ -236,3 +242,14 @@ void CHalfLife2::SetEdictStateChanged(edict_t *pEdict, unsigned short offset)
pEdict->m_fStateFlags |= FL_EDICT_CHANGED;
}
}
void CHalfLife2::TextMsg(int client, int dest, const char *msg)
{
bf_write *pBitBuf = NULL;
cell_t players[] = {client};
pBitBuf = g_UserMsgs.StartMessage(m_MsgTextMsg, players, 1, USERMSG_RELIABLE);
pBitBuf->WriteByte(dest);
pBitBuf->WriteString(msg);
g_UserMsgs.EndMessage();
}
+7 -4
View File
@@ -19,10 +19,10 @@
#include <sh_tinyhash.h>
#include "sm_trie.h"
#include "sm_globals.h"
#include "dt_send.h"
#include "server_class.h"
#include "datamap.h"
#include "edict.h"
#include <dt_send.h>
#include <server_class.h>
#include <datamap.h>
#include <edict.h>
using namespace SourceHook;
@@ -45,18 +45,21 @@ public:
~CHalfLife2();
public:
void OnSourceModStartup(bool late);
void OnSourceModAllInitialized();
/*void OnSourceModAllShutdown();*/
public:
SendProp *FindInSendTable(const char *classname, const char *offset);
ServerClass *FindServerClass(const char *classname);
typedescription_t *FindInDataMap(datamap_t *pMap, const char *offset);
void SetEdictStateChanged(edict_t *pEdict, unsigned short offset);
void TextMsg(int client, int dest, const char *msg);
private:
DataTableInfo *_FindServerClass(const char *classname);
private:
Trie *m_pClasses;
List<DataTableInfo *> m_Tables;
THash<datamap_t *, DataMapTrie> m_Maps;
int m_MsgTextMsg;
};
extern CHalfLife2 g_HL2;
+1 -1
View File
@@ -625,7 +625,7 @@ static cell_t sm_ClientCommand(IPluginContext *pContext, const cell_t *params)
}
char buffer[256];
g_SourceMod.FormatString(buffer, sizeof(buffer)-1, pContext, params, 2);
g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
engine->ClientCommand(pPlayer->GetEdict(), "%s", buffer);
+52 -2
View File
@@ -15,8 +15,10 @@
#include "sm_globals.h"
#include "sourcemod.h"
#include "sourcemm_api.h"
#include "PlayerManager.h"
#include "HandleSys.h"
#include "PlayerManager.h"
#include "HalfLife2.h"
#include <shareddefs.h>
IServerPluginCallbacks *g_VSP = NULL;
@@ -244,7 +246,7 @@ static cell_t FakeClientCommand(IPluginContext *pContext, const cell_t *params)
}
char buffer[256];
g_SourceMod.FormatString(buffer, sizeof(buffer)-1, pContext, params, 2);
g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
serverpluginhelpers->ClientCommand(pPlayer->GetEdict(), buffer);
@@ -279,6 +281,52 @@ static cell_t smn_CreateDialog(IPluginContext *pContext, const cell_t *params)
return 1;
}
static cell_t PrintToChat(IPluginContext *pContext, const cell_t *params)
{
int client = params[1];
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
if (!pPlayer)
{
return pContext->ThrowNativeError("Player %d is not a valid player", params[1]);
}
if (!pPlayer->IsConnected())
{
return pContext->ThrowNativeError("Player %d is not connected", params[1]);
}
char buffer[256];
g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
g_HL2.TextMsg(client, HUD_PRINTTALK, buffer);
return 1;
}
static cell_t PrintCenterText(IPluginContext *pContext, const cell_t *params)
{
int client = params[1];
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
if (!pPlayer)
{
return pContext->ThrowNativeError("Player %d is not a valid player", params[1]);
}
if (!pPlayer->IsConnected())
{
return pContext->ThrowNativeError("Player %d is not connected", params[1]);
}
char buffer[256];
g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
g_HL2.TextMsg(client, HUD_PRINTCENTER, buffer);
return 1;
}
static HalfLifeNatives s_HalfLifeNatives;
REGISTER_NATIVES(halflifeNatives)
@@ -306,5 +354,7 @@ REGISTER_NATIVES(halflifeNatives)
{"IsSoundPrecached", IsSoundPrecached},
{"FakeClientCommand", FakeClientCommand},
{"CreateDialog", smn_CreateDialog},
{"PrintToChat", PrintToChat},
{"PrintCenterText", PrintCenterText},
{NULL, NULL},
};