|
ds@1952
|
1 |
/** |
|
ds@1952
|
2 |
* vim: set ts=4 : |
|
ds@1952
|
3 |
* ============================================================================= |
|
ds@1952
|
4 |
* SourceMod |
|
ds@1952
|
5 |
* Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved. |
|
ds@1952
|
6 |
* ============================================================================= |
|
ds@1952
|
7 |
* |
|
ds@1952
|
8 |
* This program is free software; you can redistribute it and/or modify it under |
|
ds@1952
|
9 |
* the terms of the GNU General Public License, version 3.0, as published by the |
|
ds@1952
|
10 |
* Free Software Foundation. |
|
ds@1952
|
11 |
* |
|
ds@1952
|
12 |
* This program is distributed in the hope that it will be useful, but WITHOUT |
|
ds@1952
|
13 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
|
ds@1952
|
14 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
|
ds@1952
|
15 |
* details. |
|
ds@1952
|
16 |
* |
|
ds@1952
|
17 |
* You should have received a copy of the GNU General Public License along with |
|
ds@1952
|
18 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
|
ds@1952
|
19 |
* |
|
ds@1952
|
20 |
* As a special exception, AlliedModders LLC gives you permission to link the |
|
ds@1952
|
21 |
* code of this program (as well as its derivative works) to "Half-Life 2," the |
|
ds@1952
|
22 |
* "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software |
|
ds@1952
|
23 |
* by the Valve Corporation. You must obey the GNU General Public License in |
|
ds@1952
|
24 |
* all respects for all other code used. Additionally, AlliedModders LLC grants |
|
ds@1952
|
25 |
* this exception to all derivative works. AlliedModders LLC defines further |
|
ds@1952
|
26 |
* exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007), |
|
ds@1952
|
27 |
* or <http://www.sourcemod.net/license.php>. |
|
ds@1952
|
28 |
* |
|
ds@1952
|
29 |
* Version: $Id$ |
|
ds@1952
|
30 |
*/ |
|
ds@1952
|
31 |
|
|
ds@1952
|
32 |
#include "sm_globals.h" |
|
ds@1952
|
33 |
#include "GameConfigs.h" |
|
ds@1952
|
34 |
#include "UserMessages.h" |
|
ds@1952
|
35 |
#include "TimerSys.h" |
|
ds@1952
|
36 |
#include "PlayerManager.h" |
|
ds@1952
|
37 |
#include "HandleSys.h" |
|
ds@1952
|
38 |
|
|
ds@1952
|
39 |
#define MAX_HUD_CHANNELS 6 |
|
ds@1952
|
40 |
|
|
ds@1952
|
41 |
int g_HudMsgNum = -1; |
|
ds@1952
|
42 |
|
|
ds@1952
|
43 |
struct hud_syncobj_t |
|
ds@1952
|
44 |
{ |
|
ds@1952
|
45 |
int *player_channels; |
|
ds@1952
|
46 |
}; |
|
ds@1952
|
47 |
|
|
ds@1952
|
48 |
struct player_chaninfo_t |
|
ds@1952
|
49 |
{ |
|
ds@1952
|
50 |
double chan_times[MAX_HUD_CHANNELS]; |
|
ds@1952
|
51 |
hud_syncobj_t *chan_syncobjs[MAX_HUD_CHANNELS]; |
|
ds@1952
|
52 |
}; |
|
ds@1952
|
53 |
|
|
ds@1952
|
54 |
struct hud_text_parms |
|
ds@1952
|
55 |
{ |
|
ds@1952
|
56 |
float x; |
|
ds@1952
|
57 |
float y; |
|
ds@1952
|
58 |
int effect; |
|
ds@1952
|
59 |
byte r1, g1, b1, a1; |
|
ds@1952
|
60 |
byte r2, g2, b2, a2; |
|
ds@1952
|
61 |
float fadeinTime; |
|
ds@1952
|
62 |
float fadeoutTime; |
|
ds@1952
|
63 |
float holdTime; |
|
ds@1952
|
64 |
float fxTime; |
|
ds@1952
|
65 |
int channel; |
|
ds@1952
|
66 |
}; |
|
ds@1952
|
67 |
|
|
ds@1952
|
68 |
class HudMsgHelpers : |
|
ds@1952
|
69 |
public SMGlobalClass, |
|
ds@1952
|
70 |
public IHandleTypeDispatch, |
|
ds@1952
|
71 |
public IClientListener |
|
ds@1952
|
72 |
{ |
|
ds@1952
|
73 |
public: |
|
ds@1952
|
74 |
bool IsSupported() |
|
ds@1952
|
75 |
{ |
|
ds@1952
|
76 |
return (g_HudMsgNum != -1); |
|
ds@1952
|
77 |
} |
|
ds@1952
|
78 |
|
|
ds@1952
|
79 |
virtual void OnSourceModAllInitialized_Post() |
|
ds@1952
|
80 |
{ |
|
ds@1952
|
81 |
const char *key; |
|
ds@1952
|
82 |
|
|
ds@1952
|
83 |
key = g_pGameConf->GetKeyValue("HudTextMsg"); |
|
ds@1952
|
84 |
if (key != NULL) |
|
ds@1952
|
85 |
{ |
|
ds@1952
|
86 |
g_HudMsgNum = g_UserMsgs.GetMessageIndex(key); |
|
ds@1952
|
87 |
} |
|
ds@1952
|
88 |
|
|
ds@1952
|
89 |
if (!IsSupported()) |
|
ds@1952
|
90 |
{ |
|
ds@1952
|
91 |
m_hHudSyncObj = 0; |
|
ds@1952
|
92 |
m_PlayerHuds = NULL; |
|
ds@1952
|
93 |
return; |
|
ds@1952
|
94 |
} |
|
ds@1952
|
95 |
|
|
ds@1952
|
96 |
m_PlayerHuds = new player_chaninfo_t[256+1]; |
|
ds@1952
|
97 |
m_hHudSyncObj = g_HandleSys.CreateType("HudSyncObj", this, 0, NULL, NULL, g_pCoreIdent, NULL); |
|
ds@1952
|
98 |
|
|
ds@1952
|
99 |
g_Players.AddClientListener(this); |
|
ds@1952
|
100 |
} |
|
ds@1952
|
101 |
|
|
ds@1952
|
102 |
virtual void OnSourceModShutdown() |
|
ds@1952
|
103 |
{ |
|
ds@1952
|
104 |
if (!IsSupported()) |
|
ds@1952
|
105 |
{ |
|
ds@1952
|
106 |
return; |
|
ds@1952
|
107 |
} |
|
ds@1952
|
108 |
|
|
ds@1952
|
109 |
delete [] m_PlayerHuds; |
|
ds@1952
|
110 |
g_HandleSys.RemoveType(m_hHudSyncObj, g_pCoreIdent); |
|
ds@1952
|
111 |
|
|
ds@1952
|
112 |
g_Players.RemoveClientListener(this); |
|
ds@1952
|
113 |
} |
|
ds@1952
|
114 |
|
|
ds@1952
|
115 |
virtual void OnHandleDestroy(HandleType_t type, void *object) |
|
ds@1952
|
116 |
{ |
|
ds@1952
|
117 |
hud_syncobj_t *obj = (hud_syncobj_t *)object; |
|
ds@1952
|
118 |
|
|
ds@1952
|
119 |
delete [] obj->player_channels; |
|
ds@1952
|
120 |
delete obj; |
|
ds@1952
|
121 |
} |
|
ds@1952
|
122 |
|
|
ds@1952
|
123 |
virtual bool GetHandleApproxSize(HandleType_t type, void *object, unsigned int *pSize) |
|
ds@1952
|
124 |
{ |
|
ds@1952
|
125 |
*pSize = sizeof(unsigned int) * g_Players.GetMaxClients(); |
|
ds@1952
|
126 |
return true; |
|
ds@1952
|
127 |
} |
|
ds@1952
|
128 |
|
|
ds@1952
|
129 |
virtual void OnClientConnected(int client) |
|
ds@1952
|
130 |
{ |
|
ds@1952
|
131 |
player_chaninfo_t *player; |
|
ds@1952
|
132 |
|
|
ds@1952
|
133 |
player = &m_PlayerHuds[client]; |
|
ds@1952
|
134 |
memset(player->chan_syncobjs, 0, sizeof(player->chan_syncobjs)); |
|
ds@1952
|
135 |
memset(player->chan_times, 0, sizeof(player->chan_times)); |
|
ds@1952
|
136 |
} |
|
ds@1952
|
137 |
|
|
ds@1952
|
138 |
Handle_t CreateHudSyncObj(IdentityToken_t *pIdent) |
|
ds@1952
|
139 |
{ |
|
ds@1952
|
140 |
Handle_t hndl; |
|
ds@1952
|
141 |
int max_clients; |
|
ds@1952
|
142 |
HandleError err; |
|
ds@1952
|
143 |
hud_syncobj_t *obj; |
|
ds@1952
|
144 |
HandleSecurity sec; |
|
ds@1952
|
145 |
|
|
ds@1952
|
146 |
if ((max_clients = g_Players.MaxClients()) == 0) |
|
ds@1952
|
147 |
{ |
|
ds@1952
|
148 |
max_clients = 256+1; |
|
ds@1952
|
149 |
} |
|
ds@1952
|
150 |
|
|
ds@1952
|
151 |
obj = new hud_syncobj_t; |
|
ds@1952
|
152 |
obj->player_channels = new int[max_clients]; |
|
ds@1952
|
153 |
|
|
ds@1952
|
154 |
memset(obj->player_channels, 0, sizeof(int) * max_clients); |
|
ds@1952
|
155 |
|
|
ds@1952
|
156 |
sec = HandleSecurity(pIdent, g_pCoreIdent); |
|
ds@1952
|
157 |
|
|
ds@1952
|
158 |
if ((hndl = g_HandleSys.CreateHandleEx(m_hHudSyncObj, obj, &sec, NULL, &err)) |
|
ds@1952
|
159 |
== BAD_HANDLE) |
|
ds@1952
|
160 |
{ |
|
ds@1952
|
161 |
delete [] obj->player_channels; |
|
ds@1952
|
162 |
delete obj; |
|
ds@1952
|
163 |
} |
|
ds@1952
|
164 |
|
|
ds@1952
|
165 |
return hndl; |
|
ds@1952
|
166 |
} |
|
ds@1952
|
167 |
|
|
ds@1952
|
168 |
HandleError ReadHudSyncObj(Handle_t hndl, |
|
ds@1952
|
169 |
IdentityToken_t *pOwner, |
|
ds@1952
|
170 |
hud_syncobj_t **pObj) |
|
ds@1952
|
171 |
{ |
|
ds@1952
|
172 |
HandleSecurity sec(pOwner, g_pCoreIdent); |
|
ds@1952
|
173 |
return g_HandleSys.ReadHandle(hndl, m_hHudSyncObj, &sec, (void **)pObj); |
|
ds@1952
|
174 |
} |
|
ds@1952
|
175 |
|
|
ds@1952
|
176 |
unsigned int AutoSelectChannel(unsigned int client) |
|
ds@1952
|
177 |
{ |
|
ds@1952
|
178 |
int last_channel; |
|
ds@1952
|
179 |
player_chaninfo_t *player; |
|
ds@1952
|
180 |
|
|
ds@1952
|
181 |
player = &m_PlayerHuds[client]; |
|
ds@1952
|
182 |
|
|
ds@1952
|
183 |
last_channel = 0; |
|
ds@1952
|
184 |
for (unsigned int i = 1; i < MAX_HUD_CHANNELS; i++) |
|
ds@1952
|
185 |
{ |
|
ds@1952
|
186 |
if (player->chan_times[i] < player->chan_times[last_channel]) |
|
ds@1952
|
187 |
{ |
|
ds@1952
|
188 |
last_channel = i; |
|
ds@1952
|
189 |
} |
|
ds@1952
|
190 |
} |
|
ds@1952
|
191 |
|
|
ds@1952
|
192 |
ManualSelectChannel(client, last_channel); |
|
ds@1952
|
193 |
|
|
ds@1952
|
194 |
return last_channel; |
|
ds@1952
|
195 |
} |
|
ds@1952
|
196 |
|
|
ds@1952
|
197 |
int TryReuseLastChannel(unsigned int client, hud_syncobj_t *obj) |
|
ds@1952
|
198 |
{ |
|
ds@1952
|
199 |
int last_channel; |
|
ds@1952
|
200 |
player_chaninfo_t *player; |
|
ds@1952
|
201 |
|
|
ds@1952
|
202 |
player = &m_PlayerHuds[client]; |
|
ds@1952
|
203 |
|
|
ds@1952
|
204 |
/* First, see if we can re-use the previous channel. */ |
|
ds@1952
|
205 |
last_channel = obj->player_channels[client]; |
|
ds@1952
|
206 |
|
|
ds@1952
|
207 |
if (player->chan_syncobjs[last_channel] == obj) |
|
ds@1952
|
208 |
{ |
|
ds@1952
|
209 |
player->chan_times[last_channel] = *g_pUniversalTime; |
|
ds@1952
|
210 |
return last_channel; |
|
ds@1952
|
211 |
} |
|
ds@1952
|
212 |
|
|
ds@1952
|
213 |
return -1; |
|
ds@1952
|
214 |
} |
|
ds@1952
|
215 |
|
|
ds@1952
|
216 |
int AutoSelectChannel(unsigned int client, hud_syncobj_t *obj) |
|
ds@1952
|
217 |
{ |
|
ds@1952
|
218 |
int last_channel; |
|
ds@1952
|
219 |
player_chaninfo_t *player; |
|
ds@1952
|
220 |
|
|
ds@1952
|
221 |
player = &m_PlayerHuds[client]; |
|
ds@1952
|
222 |
|
|
ds@1952
|
223 |
/* First, see if we can re-use the previous channel. */ |
|
ds@1952
|
224 |
last_channel = obj->player_channels[client]; |
|
ds@1952
|
225 |
|
|
ds@1952
|
226 |
if (player->chan_syncobjs[last_channel] == obj) |
|
ds@1952
|
227 |
{ |
|
ds@1952
|
228 |
player->chan_times[last_channel] = *g_pUniversalTime; |
|
ds@1952
|
229 |
return last_channel; |
|
ds@1952
|
230 |
} |
|
ds@1952
|
231 |
|
|
ds@1952
|
232 |
last_channel = 0; |
|
ds@1952
|
233 |
for (unsigned int i = 1; i < MAX_HUD_CHANNELS; i++) |
|
ds@1952
|
234 |
{ |
|
ds@1952
|
235 |
if (player->chan_times[i] < player->chan_times[last_channel]) |
|
ds@1952
|
236 |
{ |
|
ds@1952
|
237 |
last_channel = i; |
|
ds@1952
|
238 |
} |
|
ds@1952
|
239 |
} |
|
ds@1952
|
240 |
|
|
ds@1952
|
241 |
obj->player_channels[client] = last_channel; |
|
ds@1952
|
242 |
player->chan_syncobjs[last_channel] = obj; |
|
ds@1952
|
243 |
player->chan_times[last_channel] = *g_pUniversalTime; |
|
ds@1952
|
244 |
|
|
ds@1952
|
245 |
return last_channel; |
|
ds@1952
|
246 |
} |
|
ds@1952
|
247 |
|
|
ds@1952
|
248 |
int ManualSelectChannel(unsigned int client, int channel) |
|
ds@1952
|
249 |
{ |
|
ds@1952
|
250 |
player_chaninfo_t *player; |
|
ds@1952
|
251 |
|
|
ds@1952
|
252 |
player = &m_PlayerHuds[client]; |
|
ds@1952
|
253 |
player->chan_times[channel] = *g_pUniversalTime; |
|
ds@1952
|
254 |
player->chan_syncobjs[channel] = NULL; |
|
ds@1952
|
255 |
|
|
ds@1952
|
256 |
return channel; |
|
ds@1952
|
257 |
} |
|
ds@1952
|
258 |
private: |
|
ds@1952
|
259 |
HandleType_t m_hHudSyncObj; |
|
ds@1952
|
260 |
player_chaninfo_t *m_PlayerHuds; |
|
ds@1952
|
261 |
} s_HudMsgHelpers; |
|
ds@1952
|
262 |
|
|
ds@1952
|
263 |
hud_text_parms g_hud_params; |
|
ds@1952
|
264 |
|
|
ds@1952
|
265 |
static cell_t CreateHudSynchronizer(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
266 |
{ |
|
ds@1952
|
267 |
return s_HudMsgHelpers.CreateHudSyncObj(pContext->GetIdentity()); |
|
ds@1952
|
268 |
} |
|
ds@1952
|
269 |
|
|
ds@1952
|
270 |
static cell_t SetHudTextParams(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
271 |
{ |
|
ds@1952
|
272 |
g_hud_params.x = sp_ctof(params[1]); |
|
ds@1952
|
273 |
g_hud_params.y = sp_ctof(params[2]); |
|
ds@1952
|
274 |
g_hud_params.holdTime = sp_ctof(params[3]); |
|
ds@1952
|
275 |
g_hud_params.r1 = static_cast<byte>(params[4]); |
|
ds@1952
|
276 |
g_hud_params.g1 = static_cast<byte>(params[5]); |
|
ds@1952
|
277 |
g_hud_params.b1 = static_cast<byte>(params[6]); |
|
ds@1952
|
278 |
g_hud_params.a1 = static_cast<byte>(params[7]); |
|
ds@1952
|
279 |
g_hud_params.effect = params[8]; |
|
ds@1952
|
280 |
g_hud_params.fxTime = sp_ctof(params[9]); |
|
ds@1952
|
281 |
g_hud_params.fadeinTime = sp_ctof(params[10]); |
|
ds@1952
|
282 |
g_hud_params.fadeoutTime = sp_ctof(params[11]); |
|
ds@1952
|
283 |
g_hud_params.r2 = 255; |
|
ds@1952
|
284 |
g_hud_params.g2 = 255; |
|
ds@1952
|
285 |
g_hud_params.b2 = 250; |
|
ds@1952
|
286 |
g_hud_params.a2 = 0; |
|
ds@1952
|
287 |
|
|
ds@1952
|
288 |
return 1; |
|
ds@1952
|
289 |
} |
|
ds@1952
|
290 |
|
|
ds@1952
|
291 |
static cell_t SetHudTextParamsEx(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
292 |
{ |
|
ds@1952
|
293 |
cell_t *color1, *color2; |
|
ds@1952
|
294 |
|
|
ds@1952
|
295 |
pContext->LocalToPhysAddr(params[4], &color1); |
|
ds@1952
|
296 |
pContext->LocalToPhysAddr(params[5], &color2); |
|
ds@1952
|
297 |
|
|
ds@1952
|
298 |
g_hud_params.x = sp_ctof(params[1]); |
|
ds@1952
|
299 |
g_hud_params.y = sp_ctof(params[2]); |
|
ds@1952
|
300 |
g_hud_params.holdTime = sp_ctof(params[3]); |
|
ds@1952
|
301 |
g_hud_params.r1 = static_cast<byte>(color1[0]); |
|
ds@1952
|
302 |
g_hud_params.g1 = static_cast<byte>(color1[1]); |
|
ds@1952
|
303 |
g_hud_params.b1 = static_cast<byte>(color1[2]); |
|
ds@1952
|
304 |
g_hud_params.a1 = static_cast<byte>(color1[3]); |
|
ds@1952
|
305 |
g_hud_params.effect = params[6]; |
|
ds@1952
|
306 |
g_hud_params.fxTime = sp_ctof(params[7]); |
|
ds@1952
|
307 |
g_hud_params.fadeinTime = sp_ctof(params[8]); |
|
ds@1952
|
308 |
g_hud_params.fadeoutTime = sp_ctof(params[9]); |
|
ds@1952
|
309 |
g_hud_params.r2 = static_cast<byte>(color2[0]); |
|
ds@1952
|
310 |
g_hud_params.g2 = static_cast<byte>(color2[1]); |
|
ds@1952
|
311 |
g_hud_params.b2 = static_cast<byte>(color2[2]); |
|
ds@1952
|
312 |
g_hud_params.a2 = static_cast<byte>(color2[3]); |
|
ds@1952
|
313 |
|
|
ds@1952
|
314 |
return 1; |
|
ds@1952
|
315 |
} |
|
ds@1952
|
316 |
|
|
ds@1952
|
317 |
void UTIL_SendHudText(int client, const hud_text_parms &textparms, const char *pMessage) |
|
ds@1952
|
318 |
{ |
|
ds@1952
|
319 |
bf_write *bf; |
|
ds@1952
|
320 |
cell_t players[1]; |
|
ds@1952
|
321 |
|
|
ds@1952
|
322 |
players[0] = client; |
|
ds@1952
|
323 |
|
|
ds@1952
|
324 |
bf = g_UserMsgs.StartMessage(g_HudMsgNum, players, 1, 0); |
|
ds@1952
|
325 |
bf->WriteByte(textparms.channel & 0xFF ); |
|
ds@1952
|
326 |
bf->WriteFloat(textparms.x); |
|
ds@1952
|
327 |
bf->WriteFloat(textparms.y); |
|
ds@1952
|
328 |
bf->WriteByte(textparms.r1); |
|
ds@1952
|
329 |
bf->WriteByte(textparms.g1); |
|
ds@1952
|
330 |
bf->WriteByte(textparms.b1); |
|
ds@1952
|
331 |
bf->WriteByte(textparms.a1); |
|
ds@1952
|
332 |
bf->WriteByte(textparms.r2); |
|
ds@1952
|
333 |
bf->WriteByte(textparms.g2); |
|
ds@1952
|
334 |
bf->WriteByte(textparms.b2); |
|
ds@1952
|
335 |
bf->WriteByte(textparms.a2); |
|
ds@1952
|
336 |
bf->WriteByte(textparms.effect); |
|
ds@1952
|
337 |
bf->WriteFloat(textparms.fadeinTime); |
|
ds@1952
|
338 |
bf->WriteFloat(textparms.fadeoutTime); |
|
ds@1952
|
339 |
bf->WriteFloat(textparms.holdTime); |
|
ds@1952
|
340 |
bf->WriteFloat(textparms.fxTime); |
|
ds@1952
|
341 |
bf->WriteString(pMessage); |
|
ds@1952
|
342 |
g_UserMsgs.EndMessage(); |
|
ds@1952
|
343 |
} |
|
ds@1952
|
344 |
|
|
ds@1952
|
345 |
static cell_t ShowSyncHudText(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
346 |
{ |
|
ds@1952
|
347 |
int client; |
|
ds@1952
|
348 |
Handle_t err; |
|
ds@1952
|
349 |
CPlayer *pPlayer; |
|
ds@1952
|
350 |
hud_syncobj_t *obj; |
|
ds@1952
|
351 |
char message_buffer[255-36]; |
|
ds@1952
|
352 |
|
|
ds@1952
|
353 |
if (!s_HudMsgHelpers.IsSupported()) |
|
ds@1952
|
354 |
{ |
|
ds@1952
|
355 |
return -1; |
|
ds@1952
|
356 |
} |
|
ds@1952
|
357 |
|
|
ds@1952
|
358 |
if ((err = s_HudMsgHelpers.ReadHudSyncObj(params[2], pContext->GetIdentity(), &obj)) != HandleError_None) |
|
ds@1952
|
359 |
{ |
|
ds@1952
|
360 |
return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[2], err); |
|
ds@1952
|
361 |
} |
|
ds@1952
|
362 |
|
|
ds@1952
|
363 |
client = params[1]; |
|
ds@1952
|
364 |
if ((pPlayer = g_Players.GetPlayerByIndex(client)) == NULL) |
|
ds@1952
|
365 |
{ |
|
ds@1952
|
366 |
return pContext->ThrowNativeError("Invalid client index %d", client); |
|
ds@1952
|
367 |
} |
|
ds@1952
|
368 |
else if (!pPlayer->IsInGame()) |
|
ds@1952
|
369 |
{ |
|
ds@1952
|
370 |
return pContext->ThrowNativeError("Client %d is not in-game", client); |
|
ds@1952
|
371 |
} |
|
ds@1952
|
372 |
|
|
ds@1952
|
373 |
g_SourceMod.FormatString(message_buffer, sizeof(message_buffer), pContext, params, 3); |
|
ds@1952
|
374 |
if (pContext->GetContext()->n_err != SP_ERROR_NONE) |
|
ds@1952
|
375 |
{ |
|
ds@1952
|
376 |
return 0; |
|
ds@1952
|
377 |
} |
|
ds@1952
|
378 |
|
|
ds@1952
|
379 |
g_hud_params.channel = s_HudMsgHelpers.AutoSelectChannel(client, obj); |
|
ds@1952
|
380 |
UTIL_SendHudText(client, g_hud_params, message_buffer); |
|
ds@1952
|
381 |
|
|
ds@1952
|
382 |
return 1; |
|
ds@1952
|
383 |
} |
|
ds@1952
|
384 |
|
|
ds@1952
|
385 |
static cell_t ClearSyncHud(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
386 |
{ |
|
ds@1952
|
387 |
int client; |
|
ds@1952
|
388 |
int channel; |
|
ds@1952
|
389 |
Handle_t err; |
|
ds@1952
|
390 |
CPlayer *pPlayer; |
|
ds@1952
|
391 |
hud_syncobj_t *obj; |
|
ds@1952
|
392 |
|
|
ds@1952
|
393 |
if (!s_HudMsgHelpers.IsSupported()) |
|
ds@1952
|
394 |
{ |
|
ds@1952
|
395 |
return -1; |
|
ds@1952
|
396 |
} |
|
ds@1952
|
397 |
|
|
ds@1952
|
398 |
if ((err = s_HudMsgHelpers.ReadHudSyncObj(params[2], pContext->GetIdentity(), &obj)) != HandleError_None) |
|
ds@1952
|
399 |
{ |
|
ds@1952
|
400 |
return pContext->ThrowNativeError("Invalid Handle %x (error %d)", params[2], err); |
|
ds@1952
|
401 |
} |
|
ds@1952
|
402 |
|
|
ds@1952
|
403 |
client = params[1]; |
|
ds@1952
|
404 |
if ((pPlayer = g_Players.GetPlayerByIndex(client)) == NULL) |
|
ds@1952
|
405 |
{ |
|
ds@1952
|
406 |
return pContext->ThrowNativeError("Invalid client index %d", client); |
|
ds@1952
|
407 |
} |
|
ds@1952
|
408 |
else if (!pPlayer->IsInGame()) |
|
ds@1952
|
409 |
{ |
|
ds@1952
|
410 |
return pContext->ThrowNativeError("Client %d is not in-game", client); |
|
ds@1952
|
411 |
} |
|
ds@1952
|
412 |
|
|
ds@1952
|
413 |
if ((channel = s_HudMsgHelpers.TryReuseLastChannel(client, obj)) == -1) |
|
ds@1952
|
414 |
{ |
|
ds@1952
|
415 |
return -1; |
|
ds@1952
|
416 |
} |
|
ds@1952
|
417 |
|
|
ds@1952
|
418 |
g_hud_params.channel = channel; |
|
ds@1952
|
419 |
UTIL_SendHudText(client, g_hud_params, ""); |
|
ds@1952
|
420 |
|
|
ds@1952
|
421 |
return g_hud_params.channel; |
|
ds@1952
|
422 |
} |
|
ds@1952
|
423 |
|
|
ds@1952
|
424 |
static cell_t ShowHudText(IPluginContext *pContext, const cell_t *params) |
|
ds@1952
|
425 |
{ |
|
ds@1952
|
426 |
int client; |
|
ds@1952
|
427 |
CPlayer *pPlayer; |
|
ds@1952
|
428 |
char message_buffer[255-36]; |
|
ds@1952
|
429 |
|
|
ds@1952
|
430 |
if (!s_HudMsgHelpers.IsSupported()) |
|
ds@1952
|
431 |
{ |
|
ds@1952
|
432 |
return -1; |
|
ds@1952
|
433 |
} |
|
ds@1952
|
434 |
|
|
ds@1952
|
435 |
client = params[1]; |
|
ds@1952
|
436 |
if ((pPlayer = g_Players.GetPlayerByIndex(client)) == NULL) |
|
ds@1952
|
437 |
{ |
|
ds@1952
|
438 |
return pContext->ThrowNativeError("Invalid client index %d", client); |
|
ds@1952
|
439 |
} |
|
ds@1952
|
440 |
else if (!pPlayer->IsInGame()) |
|
ds@1952
|
441 |
{ |
|
ds@1952
|
442 |
return pContext->ThrowNativeError("Client %d is not in-game", client); |
|
ds@1952
|
443 |
} |
|
ds@1952
|
444 |
|
|
ds@1952
|
445 |
g_SourceMod.FormatString(message_buffer, sizeof(message_buffer), pContext, params, 3); |
|
ds@1952
|
446 |
if (pContext->GetContext()->n_err != SP_ERROR_NONE) |
|
ds@1952
|
447 |
{ |
|
ds@1952
|
448 |
return 0; |
|
ds@1952
|
449 |
} |
|
ds@1952
|
450 |
|
|
ds@1952
|
451 |
if (params[2] == -1) |
|
ds@1952
|
452 |
{ |
|
ds@1952
|
453 |
g_hud_params.channel = s_HudMsgHelpers.AutoSelectChannel(client); |
|
ds@1952
|
454 |
} |
|
ds@1952
|
455 |
else |
|
ds@1952
|
456 |
{ |
|
ds@1952
|
457 |
g_hud_params.channel = params[2] % MAX_HUD_CHANNELS; |
|
ds@1952
|
458 |
s_HudMsgHelpers.ManualSelectChannel(client, g_hud_params.channel); |
|
ds@1952
|
459 |
} |
|
ds@1952
|
460 |
|
|
ds@1952
|
461 |
UTIL_SendHudText(client, g_hud_params, message_buffer); |
|
ds@1952
|
462 |
|
|
ds@1952
|
463 |
return g_hud_params.channel; |
|
ds@1952
|
464 |
} |
|
ds@1952
|
465 |
|
|
ds@1952
|
466 |
REGISTER_NATIVES(hudNatives) |
|
ds@1952
|
467 |
{ |
|
ds@1952
|
468 |
{"ClearSyncHud", ClearSyncHud}, |
|
ds@1952
|
469 |
{"CreateHudSynchronizer", CreateHudSynchronizer}, |
|
ds@1952
|
470 |
{"SetHudTextParams", SetHudTextParams}, |
|
ds@1952
|
471 |
{"SetHudTextParamsEx", SetHudTextParamsEx}, |
|
ds@1952
|
472 |
{"ShowHudText", ShowHudText}, |
|
ds@1952
|
473 |
{"ShowSyncHudText", ShowSyncHudText}, |
|
ds@1952
|
474 |
{NULL, NULL}, |
|
ds@1952
|
475 |
}; |