added
amb441, vguimenu and hinttext natives
1.1 --- a/core/HalfLife2.cpp Mon Jul 30 20:26:18 2007 +0000
1.2 +++ b/core/HalfLife2.cpp Mon Jul 30 23:16:58 2007 +0000
1.3 @@ -85,6 +85,8 @@
1.4 void CHalfLife2::OnSourceModAllInitialized()
1.5 {
1.6 m_MsgTextMsg = g_UserMsgs.GetMessageIndex("TextMsg");
1.7 + m_HinTextMsg = g_UserMsgs.GetMessageIndex("HintText");
1.8 + m_VGUIMenu = g_UserMsgs.GetMessageIndex("VGUIMenu");
1.9 g_ShareSys.AddInterface(NULL, this);
1.10 }
1.11
1.12 @@ -260,3 +262,57 @@
1.13
1.14 return true;
1.15 }
1.16 +
1.17 +bool CHalfLife2::HinTextMsg(int client, const char *msg)
1.18 +{
1.19 + bf_write *pBitBuf = NULL;
1.20 + cell_t players[] = {client};
1.21 +
1.22 + if ((pBitBuf = g_UserMsgs.StartMessage(m_HinTextMsg, players, 1, USERMSG_RELIABLE)) == NULL)
1.23 + {
1.24 + return false;
1.25 + }
1.26 +
1.27 + pBitBuf->WriteByte(1);
1.28 + pBitBuf->WriteString(msg);
1.29 + g_UserMsgs.EndMessage();
1.30 +
1.31 + return true;
1.32 +}
1.33 +
1.34 +bool CHalfLife2::ShowVGUIMenu(int client, const char *name, KeyValues *data, bool show)
1.35 +{
1.36 + bf_write *pBitBuf = NULL;
1.37 + KeyValues *SubKey = NULL;
1.38 + int count = 0;
1.39 + cell_t players[] = {client};
1.40 +
1.41 + if ((pBitBuf = g_UserMsgs.StartMessage(m_VGUIMenu, players, 1, USERMSG_RELIABLE)) == NULL)
1.42 + {
1.43 + return false;
1.44 + }
1.45 +
1.46 + if (data)
1.47 + {
1.48 + SubKey = data->GetFirstSubKey();
1.49 + while (SubKey)
1.50 + {
1.51 + count++;
1.52 + SubKey = SubKey->GetNextKey();
1.53 + }
1.54 + SubKey = data->GetFirstSubKey();
1.55 + }
1.56 +
1.57 + pBitBuf->WriteString(name);
1.58 + pBitBuf->WriteByte((show) ? 1 : 0);
1.59 + pBitBuf->WriteByte(count);
1.60 + while (SubKey)
1.61 + {
1.62 + pBitBuf->WriteString(SubKey->GetName());
1.63 + pBitBuf->WriteString(SubKey->GetString());
1.64 + SubKey = SubKey->GetNextKey();
1.65 + }
1.66 + g_UserMsgs.EndMessage();
1.67 +
1.68 + return true;
1.69 +}
2.1 --- a/core/HalfLife2.h Mon Jul 30 20:26:18 2007 +0000
2.2 +++ b/core/HalfLife2.h Mon Jul 30 23:16:58 2007 +0000
2.3 @@ -20,6 +20,7 @@
2.4 #include "sm_trie.h"
2.5 #include "sm_globals.h"
2.6 #include <IGameHelpers.h>
2.7 +#include <KeyValues.h>
2.8
2.9 using namespace SourceHook;
2.10 using namespace SourceMod;
2.11 @@ -57,6 +58,8 @@
2.12 typedescription_t *FindInDataMap(datamap_t *pMap, const char *offset);
2.13 void SetEdictStateChanged(edict_t *pEdict, unsigned short offset);
2.14 bool TextMsg(int client, int dest, const char *msg);
2.15 + bool HinTextMsg(int client, const char *msg);
2.16 + bool ShowVGUIMenu(int client, const char *name, KeyValues *data, bool show);
2.17 private:
2.18 DataTableInfo *_FindServerClass(const char *classname);
2.19 private:
2.20 @@ -64,6 +67,8 @@
2.21 List<DataTableInfo *> m_Tables;
2.22 THash<datamap_t *, DataMapTrie> m_Maps;
2.23 int m_MsgTextMsg;
2.24 + int m_HinTextMsg;
2.25 + int m_VGUIMenu;
2.26 };
2.27
2.28 extern CHalfLife2 g_HL2;
3.1 --- a/core/smn_halflife.cpp Mon Jul 30 20:26:18 2007 +0000
3.2 +++ b/core/smn_halflife.cpp Mon Jul 30 23:16:58 2007 +0000
3.3 @@ -326,6 +326,78 @@
3.4 return 1;
3.5 }
3.6
3.7 +static cell_t PrintHintText(IPluginContext *pContext, const cell_t *params)
3.8 +{
3.9 + int client = params[1];
3.10 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
3.11 +
3.12 + if (!pPlayer)
3.13 + {
3.14 + return pContext->ThrowNativeError("Client index %d is invalid", client);
3.15 + }
3.16 +
3.17 + if (!pPlayer->IsInGame())
3.18 + {
3.19 + return pContext->ThrowNativeError("Client %d is not in game", client);
3.20 + }
3.21 +
3.22 + g_SourceMod.SetGlobalTarget(client);
3.23 +
3.24 + char buffer[192];
3.25 + g_SourceMod.FormatString(buffer, sizeof(buffer), pContext, params, 2);
3.26 +
3.27 + /* Check for an error before printing to the client */
3.28 + if (pContext->GetContext()->n_err != SP_ERROR_NONE)
3.29 + {
3.30 + return 0;
3.31 + }
3.32 +
3.33 + if (!g_HL2.HinTextMsg(client, buffer))
3.34 + {
3.35 + return pContext->ThrowNativeError("Could not send a usermessage");
3.36 + }
3.37 +
3.38 + return 1;
3.39 +}
3.40 +
3.41 +static cell_t ShowVGUIPanel(IPluginContext *pContext, const cell_t *params)
3.42 +{
3.43 + HandleError herr;
3.44 + char *name;
3.45 + KeyValues *pKV = NULL;
3.46 + int client = params[1];
3.47 + Handle_t hndl = static_cast<Handle_t>(params[3]);
3.48 + CPlayer *pPlayer = g_Players.GetPlayerByIndex(client);
3.49 +
3.50 + if (!pPlayer)
3.51 + {
3.52 + return pContext->ThrowNativeError("Client index %d is invalid", client);
3.53 + }
3.54 +
3.55 + if (!pPlayer->IsInGame())
3.56 + {
3.57 + return pContext->ThrowNativeError("Client %d is not in game", client);
3.58 + }
3.59 +
3.60 + if (hndl != BAD_HANDLE)
3.61 + {
3.62 + pKV = g_SourceMod.ReadKeyValuesHandle(hndl, &herr, true);
3.63 + if (herr != HandleError_None)
3.64 + {
3.65 + return pContext->ThrowNativeError("Invalid key value handle %x (error %d)", hndl, herr);
3.66 + }
3.67 + }
3.68 +
3.69 + pContext->LocalToString(params[2], &name);
3.70 +
3.71 + if (!g_HL2.ShowVGUIMenu(client, name, pKV, (params[4]) ? true : false))
3.72 + {
3.73 + return pContext->ThrowNativeError("Could not send a usermessage");
3.74 + }
3.75 +
3.76 + return 1;
3.77 +}
3.78 +
3.79 static HalfLifeNatives s_HalfLifeNatives;
3.80
3.81 REGISTER_NATIVES(halflifeNatives)
3.82 @@ -354,5 +426,7 @@
3.83 {"CreateDialog", smn_CreateDialog},
3.84 {"PrintToChat", PrintToChat},
3.85 {"PrintCenterText", PrintCenterText},
3.86 + {"PrintHintText", PrintHintText},
3.87 + {"ShowVGUIPanel", ShowVGUIPanel},
3.88 {NULL, NULL},
3.89 };
4.1 --- a/plugins/include/halflife.inc Mon Jul 30 20:26:18 2007 +0000
4.2 +++ b/plugins/include/halflife.inc Mon Jul 30 23:16:58 2007 +0000
4.3 @@ -18,6 +18,11 @@
4.4 #endif
4.5 #define _halflife_included
4.6
4.7 +#define MOTDPANEL_TYPE_TEXT 0 /**< Treat msg as plain text */
4.8 +#define MOTDPANEL_TYPE_INDEX 1 /**< Msg is auto determined by the engine */
4.9 +#define MOTDPANEL_TYPE_URL 2 /**< Treat msg as an URL link */
4.10 +#define MOTDPANEL_TYPE_FILE 3 /**< Treat msg as a filename to be openned */
4.11 +
4.12 enum DialogType
4.13 {
4.14 DialogType_Msg = 0, /**< just an on screen message */
4.15 @@ -275,3 +280,73 @@
4.16 }
4.17 }
4.18 }
4.19 +
4.20 +/**
4.21 + * Prints a message to a specific client with a hint box.
4.22 + *
4.23 + * @param client Client index.
4.24 + * @param format Formatting rules.
4.25 + * @param ... Variable number of format parameters.
4.26 + * @noreturn
4.27 + * @error If the client is not connected an error will be thrown.
4.28 + */
4.29 +native PrintHintText(client, const String:format[], any:...);
4.30 +
4.31 +/**
4.32 + * Prints a message to all clients with a hint box.
4.33 + *
4.34 + * @param format Formatting rules.
4.35 + * @param ... Variable number of format parameters.
4.36 + * @noreturn
4.37 + */
4.38 +stock PrintHintTextToAll(const String:format[], any:...)
4.39 +{
4.40 + new maxClients = GetMaxClients();
4.41 + decl String:buffer[192];
4.42 +
4.43 + for (new i = 1; i <= maxClients; i++)
4.44 + {
4.45 + if (IsClientInGame(i))
4.46 + {
4.47 + SetGlobalTransTarget(i);
4.48 + VFormat(buffer, sizeof(buffer), format, 2);
4.49 + PrintHintText(i, "%s", buffer);
4.50 + }
4.51 + }
4.52 +}
4.53 +
4.54 +/**
4.55 + * Shows a VGUI panel to a specific client.
4.56 + *
4.57 + * @param client Client index.
4.58 + * @param name Panel type name (Check viewport_panel_names.h to see a list of some panel names).
4.59 + * @param Kv KeyValues handle with all the data for the panel setup (Depends on the panel type and may be unused).
4.60 + * @param show True to show the panel, or false to remove it from the client screen.
4.61 + * @noreturn
4.62 + * @error If the client is not connected an error will be thrown.
4.63 + */
4.64 +native ShowVGUIPanel(client, const String:name[], Handle:Kv=INVALID_HANDLE, bool:show=true);
4.65 +
4.66 +/**
4.67 + * Shows a MOTD panel to a specific client.
4.68 + *
4.69 + * @param client Client index.
4.70 + * @param title Title of the panel (printed on the top border of the window).
4.71 + * @param msg Contents of the panel, it can be treated as an url, filename or plain text
4.72 + * depending on the type parameter (WARNING: msg has to be 192 bytes maximum!)
4.73 + * @param type Determines the way to treat the message body of the panel.
4.74 + * @noreturn
4.75 + * @error If the client is not connected an error will be thrown.
4.76 + */
4.77 +stock ShowMOTDPanel(client, const String:title[], const String:msg[], type=MOTDPANEL_TYPE_INDEX)
4.78 +{
4.79 + decl String:num[3];
4.80 + new Handle:Kv = CreateKeyValues("data");
4.81 + IntToString(type, num, sizeof(num));
4.82 +
4.83 + KvSetString(Kv, "title", title);
4.84 + KvSetString(Kv, "type", num);
4.85 + KvSetString(Kv, "msg", msg);
4.86 + ShowVGUIPanel(client, "info", Kv);
4.87 + CloseHandle(Kv);
4.88 +}