added amb441, vguimenu and hinttext natives

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401224
This commit is contained in:
Borja Ferrer
2007-07-30 23:16:58 +00:00
parent 5acdc40618
commit 4a6a016790
4 changed files with 210 additions and 0 deletions
+56
View File
@@ -85,6 +85,8 @@ void CHalfLife2::OnSourceModStartup(bool late)
void CHalfLife2::OnSourceModAllInitialized()
{
m_MsgTextMsg = g_UserMsgs.GetMessageIndex("TextMsg");
m_HinTextMsg = g_UserMsgs.GetMessageIndex("HintText");
m_VGUIMenu = g_UserMsgs.GetMessageIndex("VGUIMenu");
g_ShareSys.AddInterface(NULL, this);
}
@@ -260,3 +262,57 @@ bool CHalfLife2::TextMsg(int client, int dest, const char *msg)
return true;
}
bool CHalfLife2::HinTextMsg(int client, const char *msg)
{
bf_write *pBitBuf = NULL;
cell_t players[] = {client};
if ((pBitBuf = g_UserMsgs.StartMessage(m_HinTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
{
return false;
}
pBitBuf->WriteByte(1);
pBitBuf->WriteString(msg);
g_UserMsgs.EndMessage();
return true;
}
bool CHalfLife2::ShowVGUIMenu(int client, const char *name, KeyValues *data, bool show)
{
bf_write *pBitBuf = NULL;
KeyValues *SubKey = NULL;
int count = 0;
cell_t players[] = {client};
if ((pBitBuf = g_UserMsgs.StartMessage(m_VGUIMenu, players, 1, USERMSG_RELIABLE)) == NULL)
{
return false;
}
if (data)
{
SubKey = data->GetFirstSubKey();
while (SubKey)
{
count++;
SubKey = SubKey->GetNextKey();
}
SubKey = data->GetFirstSubKey();
}
pBitBuf->WriteString(name);
pBitBuf->WriteByte((show) ? 1 : 0);
pBitBuf->WriteByte(count);
while (SubKey)
{
pBitBuf->WriteString(SubKey->GetName());
pBitBuf->WriteString(SubKey->GetString());
SubKey = SubKey->GetNextKey();
}
g_UserMsgs.EndMessage();
return true;
}
+5
View File
@@ -20,6 +20,7 @@
#include "sm_trie.h"
#include "sm_globals.h"
#include <IGameHelpers.h>
#include <KeyValues.h>
using namespace SourceHook;
using namespace SourceMod;
@@ -57,6 +58,8 @@ public: //IGameHelpers
typedescription_t *FindInDataMap(datamap_t *pMap, const char *offset);
void SetEdictStateChanged(edict_t *pEdict, unsigned short offset);
bool TextMsg(int client, int dest, const char *msg);
bool HinTextMsg(int client, const char *msg);
bool ShowVGUIMenu(int client, const char *name, KeyValues *data, bool show);
private:
DataTableInfo *_FindServerClass(const char *classname);
private:
@@ -64,6 +67,8 @@ private:
List<DataTableInfo *> m_Tables;
THash<datamap_t *, DataMapTrie> m_Maps;
int m_MsgTextMsg;
int m_HinTextMsg;
int m_VGUIMenu;
};
extern CHalfLife2 g_HL2;
+74
View File
@@ -326,6 +326,78 @@ static cell_t PrintCenterText(IPluginContext *pContext, const cell_t *params)
return 1;
}
static cell_t PrintHintText(IPluginContext *pContext, const cell_t *params)
{
int client = params[1];
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
if (!pPlayer)
{
return pContext->ThrowNativeError("Client index %d is invalid", client);
}
if (!pPlayer->IsInGame())
{
return pContext->ThrowNativeError("Client %d is not in game", client);
}
g_SourceMod.SetGlobalTarget(client);
char buffer[192];
g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
/* Check for an error before printing to the client */
if (pContext->GetContext()->n_err != SP_ERROR_NONE)
{
return 0;
}
if (!g_HL2.HinTextMsg(client, buffer))
{
return pContext->ThrowNativeError("Could not send a usermessage");
}
return 1;
}
static cell_t ShowVGUIPanel(IPluginContext *pContext, const cell_t *params)
{
HandleError herr;
char *name;
KeyValues *pKV = NULL;
int client = params[1];
Handle_t hndl = static_cast<Handle_t>(params[3]);
CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
if (!pPlayer)
{
return pContext->ThrowNativeError("Client index %d is invalid", client);
}
if (!pPlayer->IsInGame())
{
return pContext->ThrowNativeError("Client %d is not in game", client);
}
if (hndl != BAD_HANDLE)
{
pKV = g_SourceMod.ReadKeyValuesHandle(hndl, &herr, true);
if (herr != HandleError_None)
{
return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
}
}
pContext->LocalToString(params[2], &name);
if (!g_HL2.ShowVGUIMenu(client, name, pKV, (params[4]) ? true : false))
{
return pContext->ThrowNativeError("Could not send a usermessage");
}
return 1;
}
static HalfLifeNatives s_HalfLifeNatives;
REGISTER_NATIVES(halflifeNatives)
@@ -354,5 +426,7 @@ REGISTER_NATIVES(halflifeNatives)
{"CreateDialog", smn_CreateDialog},
{"PrintToChat", PrintToChat},
{"PrintCenterText", PrintCenterText},
{"PrintHintText", PrintHintText},
{"ShowVGUIPanel", ShowVGUIPanel},
{NULL, NULL},
};