-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathcssdm_callbacks.cpp
More file actions
237 lines (196 loc) · 6.53 KB
/
Copy pathcssdm_callbacks.cpp
File metadata and controls
237 lines (196 loc) · 6.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
/**
* vim: set ts=4 :
* ===============================================================
* CS:S DM, Copyright (C) 2004-2007 AlliedModders LLC.
* By David "BAILOPAN" Anderson
* All rights reserved.
* ===============================================================
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
* MA 02110-1301 USA
*
* Version: $Id$
*/
#include "cssdm_headers.h"
#include "cssdm_callbacks.h"
#include "cssdm_config.h"
#include "cssdm_weapons.h"
#include "cssdm_players.h"
#include "cssdm_utils.h"
IForward *g_pOnClientDeath = NULL;
IForward *g_pOnClientSpawned = NULL;
IForward *g_pOnClientPostSpawned = NULL;
IForward *g_pOnSetSpawnMethod = NULL;
IForward *g_pOnStartup = NULL;
IForward *g_pOnShutdown = NULL;
void DM_InitCallbacks()
{
g_pOnClientDeath = forwards->CreateForward("DM_OnClientDeath", ET_Hook, 1, NULL, Param_Cell);
g_pOnClientSpawned = forwards->CreateForward("DM_OnClientSpawned", ET_Ignore, 1, NULL, Param_Cell);
g_pOnClientPostSpawned = forwards->CreateForward("DM_OnClientPostSpawned", ET_Ignore, 1, NULL, Param_Cell);
g_pOnSetSpawnMethod = forwards->CreateForward("DM_OnSetSpawnMethod", ET_Hook, 1, NULL, Param_String);
g_pOnStartup = forwards->CreateForward("DM_OnStartup", ET_Ignore, 0, NULL);
g_pOnShutdown = forwards->CreateForward("DM_OnShutdown", ET_Ignore, 0, NULL);
}
void DM_ShutdownCallbacks()
{
forwards->ReleaseForward(g_pOnClientDeath);
forwards->ReleaseForward(g_pOnClientSpawned);
forwards->ReleaseForward(g_pOnClientPostSpawned);
forwards->ReleaseForward(g_pOnSetSpawnMethod);
forwards->ReleaseForward(g_pOnStartup);
forwards->ReleaseForward(g_pOnShutdown);
}
bool DM_OnClientDeath(int client)
{
cell_t res = 0;
g_pOnClientDeath->PushCell(client);
g_pOnClientDeath->Execute(&res);
return (res == (cell_t)Pl_Continue);
}
void DM_OnClientSpawned(int client, bool wasDead)
{
g_pOnClientSpawned->PushCell(client);
g_pOnClientSpawned->Execute(NULL);
g_pOnClientPostSpawned->PushCell(client);
g_pOnClientPostSpawned->Execute(NULL);
}
void DM_OnSetSpawnMethod(const char *method)
{
g_pOnSetSpawnMethod->PushString(method);
g_pOnSetSpawnMethod->Execute(NULL);
}
void DM_OnStartup()
{
g_pOnStartup->Execute(NULL);
}
void DM_OnShutdown()
{
g_pOnShutdown->Execute(NULL);
}
static cell_t DMN_GetSpawnMethod(IPluginContext *pContext, const cell_t *params)
{
pContext->StringToLocal(params[1], params[2], DM_GetSpawnMethod());
return 1;
}
static cell_t DMN_GetWeaponID(IPluginContext *pContext, const cell_t *params)
{
char *str;
pContext->LocalToString(params[1], &str);
auto weapon = DM_FindWeapon(str);
if (weapon == nullptr)
{
return -1;
}
return weapon->id;
}
static cell_t DMN_GetWeaponType(IPluginContext *pContext, const cell_t *params)
{
auto weapon = DM_GetWeapon(params[1]);
if (weapon == nullptr)
{
return pContext->ThrowNativeError("Invalid CS:S DM weapon id (%d)", params[1]);
}
return static_cast<cell_t>(weapon->type);
}
static cell_t DMN_GetWeaponClassname(IPluginContext *pContext, const cell_t *params)
{
auto weapon = DM_GetWeapon(params[1]);
if (weapon == nullptr)
{
return pContext->ThrowNativeError("Invalid CS:S DM weapon id (%d)", params[1]);
}
pContext->StringToLocal(params[2], params[3], weapon->classname.c_str());
return 1;
}
static cell_t DMN_GetWeaponName(IPluginContext *pContext, const cell_t *params)
{
auto weapon = DM_GetWeapon(params[1]);
if (weapon == nullptr)
{
return pContext->ThrowNativeError("Invalid CS:S DM weapon id (%d)", params[1]);
}
pContext->StringToLocal(params[2], params[3], weapon->display.c_str());
return 1;
}
static cell_t DMN_StripBotItems(IPluginContext *pContext, const cell_t *params)
{
if (params[1] < 1 || params[1] > gpGlobals->maxClients)
{
return pContext->ThrowNativeError("Invalid client index %d", params[1]);
}
dm_player_t *player = DM_GetPlayer(params[1]);
if (!player->pEntity)
{
return pContext->ThrowNativeError("Client %d is not in game", params[1]);
}
if (!player->pBot)
{
return pContext->ThrowNativeError("Client %d is not a bot", params[1]);
}
player->pBot->RemoveAllItems(false);
return 1;
}
static cell_t DMN_IsRunning(IPluginContext *pContext, const cell_t *params)
{
return g_IsRunning ? true : false;
}
static cell_t DMN_GetSpawnWaitTime(IPluginContext *pContext, const cell_t *params)
{
float f = DM_GetRespawnWait();
return sp_ftoc(f);
}
static cell_t DMN_RespawnClient(IPluginContext *pContext, const cell_t *params)
{
if (params[1] < 1 || params[1] > gpGlobals->maxClients)
{
return pContext->ThrowNativeError("Invalid client index %d", params[1]);
}
dm_player_t *player = DM_GetPlayer(params[1]);
if (!player->pEntity)
{
return pContext->ThrowNativeError("Client %d is not in game", params[1]);
}
player->is_spawned = params[2] ? false : true;
DM_RespawnPlayer(params[1]);
return 1;
}
static cell_t DMN_IsClientAlive(IPluginContext *pContext, const cell_t *params)
{
if (params[1] < 1 || params[1] > gpGlobals->maxClients)
{
return pContext->ThrowNativeError("Invalid client index %d", params[1]);
}
dm_player_t *player = DM_GetPlayer(params[1]);
if (!player->pEntity)
{
return pContext->ThrowNativeError("Client %d is not in game", params[1]);
}
return DM_IsPlayerAlive(params[1]) ? 1 : 0;
}
sp_nativeinfo_t g_BaseNatives[] =
{
{"DM_GetSpawnMethod", DMN_GetSpawnMethod},
{"DM_GetWeaponID", DMN_GetWeaponID},
{"DM_GetWeaponType", DMN_GetWeaponType},
{"DM_StripBotItems", DMN_StripBotItems},
{"DM_GetWeaponClassname", DMN_GetWeaponClassname},
{"DM_GetWeaponName", DMN_GetWeaponName},
{"DM_IsRunning", DMN_IsRunning},
{"DM_GetSpawnWaitTime", DMN_GetSpawnWaitTime},
{"DM_RespawnClient", DMN_RespawnClient},
{"DM_IsClientAlive", DMN_IsClientAlive},
{NULL, NULL},
};