cssdm_callbacks.cpp
author Ruben Gonzalez <drifter01620@gmail.com>
Wed Oct 01 11:50:24 2014 -0400 (2014-10-01)
changeset 193 277c856152b0
parent 0 67dcd379a2d5
permissions -rw-r--r--
Update linix CS:GO gamedata
[email protected]
     1
/**
[email protected]
     2
 * vim: set ts=4 :
[email protected]
     3
 * ===============================================================
[email protected]
     4
 * CS:S DM, Copyright (C) 2004-2007 AlliedModders LLC. 
[email protected]
     5
 * By David "BAILOPAN" Anderson
[email protected]
     6
 * All rights reserved.
[email protected]
     7
 * ===============================================================
[email protected]
     8
 *
[email protected]
     9
 * This program is free software; you can redistribute it and/or modify
[email protected]
    10
 * it under the terms of the GNU General Public License as published by
[email protected]
    11
 * the Free Software Foundation; either version 2 of the License, or (at
[email protected]
    12
 * your option) any later version.
[email protected]
    13
 * 
[email protected]
    14
 * This program is distributed in the hope that it will be useful, but
[email protected]
    15
 * WITHOUT ANY WARRANTY; without even the implied warranty of
[email protected]
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
[email protected]
    17
 * General Public License for more details.
[email protected]
    18
 * 
[email protected]
    19
 * You should have received a copy of the GNU General Public License
[email protected]
    20
 * along with this program; see the file COPYING; if not, write to the
[email protected]
    21
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
[email protected]
    22
 * MA 02110-1301 USA
[email protected]
    23
 * 
[email protected]
    24
 * Version: $Id$
[email protected]
    25
 */
[email protected]
    26
[email protected]
    27
#include "cssdm_headers.h"
[email protected]
    28
#include "cssdm_callbacks.h"
[email protected]
    29
#include "cssdm_config.h"
[email protected]
    30
#include "cssdm_weapons.h"
[email protected]
    31
#include "cssdm_players.h"
[email protected]
    32
#include "cssdm_utils.h"
[email protected]
    33
[email protected]
    34
IForward *g_pOnClientDeath = NULL;
[email protected]
    35
IForward *g_pOnClientSpawned = NULL;
[email protected]
    36
IForward *g_pOnClientPostSpawned = NULL;
[email protected]
    37
IForward *g_pOnSetSpawnMethod = NULL;
[email protected]
    38
IForward *g_pOnStartup = NULL;
[email protected]
    39
IForward *g_pOnShutdown = NULL;
[email protected]
    40
[email protected]
    41
void DM_InitCallbacks()
[email protected]
    42
{
[email protected]
    43
	g_pOnClientDeath = forwards->CreateForward("DM_OnClientDeath", ET_Hook, 1, NULL, Param_Cell);
[email protected]
    44
	g_pOnClientSpawned = forwards->CreateForward("DM_OnClientSpawned", ET_Ignore, 1, NULL, Param_Cell);
[email protected]
    45
	g_pOnClientPostSpawned = forwards->CreateForward("DM_OnClientPostSpawned", ET_Ignore, 1, NULL, Param_Cell);
[email protected]
    46
	g_pOnSetSpawnMethod = forwards->CreateForward("DM_OnSetSpawnMethod", ET_Hook, 1, NULL, Param_String);
[email protected]
    47
	g_pOnStartup = forwards->CreateForward("DM_OnStartup", ET_Ignore, 0, NULL);
[email protected]
    48
	g_pOnShutdown = forwards->CreateForward("DM_OnShutdown", ET_Ignore, 0, NULL);
[email protected]
    49
}
[email protected]
    50
[email protected]
    51
void DM_ShutdownCallbacks()
[email protected]
    52
{
[email protected]
    53
	forwards->ReleaseForward(g_pOnClientDeath);
[email protected]
    54
	forwards->ReleaseForward(g_pOnClientSpawned);
[email protected]
    55
	forwards->ReleaseForward(g_pOnClientPostSpawned);
[email protected]
    56
	forwards->ReleaseForward(g_pOnSetSpawnMethod);
[email protected]
    57
	forwards->ReleaseForward(g_pOnStartup);
[email protected]
    58
	forwards->ReleaseForward(g_pOnShutdown);
[email protected]
    59
}
[email protected]
    60
[email protected]
    61
bool DM_OnClientDeath(int client)
[email protected]
    62
{
[email protected]
    63
	cell_t res = 0;
[email protected]
    64
	g_pOnClientDeath->PushCell(client);
[email protected]
    65
	g_pOnClientDeath->Execute(&res);
[email protected]
    66
[email protected]
    67
	return (res == (cell_t)Pl_Continue);
[email protected]
    68
}
[email protected]
    69
[email protected]
    70
void DM_OnClientSpawned(int client, bool wasDead)
[email protected]
    71
{
[email protected]
    72
	g_pOnClientSpawned->PushCell(client);
[email protected]
    73
	g_pOnClientSpawned->Execute(NULL);
[email protected]
    74
	g_pOnClientPostSpawned->PushCell(client);
[email protected]
    75
	g_pOnClientPostSpawned->Execute(NULL);
[email protected]
    76
}
[email protected]
    77
[email protected]
    78
void DM_OnSetSpawnMethod(const char *method)
[email protected]
    79
{
[email protected]
    80
	g_pOnSetSpawnMethod->PushString(method);
[email protected]
    81
	g_pOnSetSpawnMethod->Execute(NULL);
[email protected]
    82
}
[email protected]
    83
[email protected]
    84
void DM_OnStartup()
[email protected]
    85
{
[email protected]
    86
	g_pOnStartup->Execute(NULL);
[email protected]
    87
}
[email protected]
    88
[email protected]
    89
void DM_OnShutdown()
[email protected]
    90
{
[email protected]
    91
	g_pOnShutdown->Execute(NULL);
[email protected]
    92
}
[email protected]
    93
[email protected]
    94
static cell_t DMN_GetSpawnMethod(IPluginContext *pContext, const cell_t *params)
[email protected]
    95
{
[email protected]
    96
	pContext->StringToLocal(params[1], params[2], DM_GetSpawnMethod());
[email protected]
    97
	return 1;
[email protected]
    98
}
[email protected]
    99
[email protected]
   100
static cell_t DMN_GetWeaponID(IPluginContext *pContext, const cell_t *params)
[email protected]
   101
{
[email protected]
   102
	char *str;
[email protected]
   103
	dm_weapon_t *weapon;
[email protected]
   104
	
[email protected]
   105
	pContext->LocalToString(params[1], &str);
[email protected]
   106
	if ((weapon = DM_FindWeapon(str)) == NULL)
[email protected]
   107
	{
[email protected]
   108
		return -1;
[email protected]
   109
	}
[email protected]
   110
[email protected]
   111
	return weapon->id;
[email protected]
   112
}
[email protected]
   113
[email protected]
   114
static cell_t DMN_GetWeaponType(IPluginContext *pContext, const cell_t *params)
[email protected]
   115
{
[email protected]
   116
	dm_weapon_t *weapon;
[email protected]
   117
[email protected]
   118
	if ((weapon = DM_GetWeapon(params[1])) == NULL)
[email protected]
   119
	{
[email protected]
   120
		return pContext->ThrowNativeError("Invalid CS:S DM weapon id (%d)", params[1]);
[email protected]
   121
	}
[email protected]
   122
[email protected]
   123
	return (cell_t)weapon->type;
[email protected]
   124
}
[email protected]
   125
[email protected]
   126
static cell_t DMN_GetWeaponClassname(IPluginContext *pContext, const cell_t *params)
[email protected]
   127
{
[email protected]
   128
	dm_weapon_t *weapon;
[email protected]
   129
[email protected]
   130
	if ((weapon = DM_GetWeapon(params[1])) == NULL)
[email protected]
   131
	{
[email protected]
   132
		return pContext->ThrowNativeError("Invalid CS:S DM weapon id (%d)", params[1]);
[email protected]
   133
	}
[email protected]
   134
[email protected]
   135
	pContext->StringToLocal(params[2], params[3], weapon->classname);
[email protected]
   136
[email protected]
   137
	return 1;
[email protected]
   138
}
[email protected]
   139
[email protected]
   140
static cell_t DMN_GetWeaponName(IPluginContext *pContext, const cell_t *params)
[email protected]
   141
{
[email protected]
   142
	dm_weapon_t *weapon;
[email protected]
   143
[email protected]
   144
	if ((weapon = DM_GetWeapon(params[1])) == NULL)
[email protected]
   145
	{
[email protected]
   146
		return pContext->ThrowNativeError("Invalid CS:S DM weapon id (%d)", params[1]);
[email protected]
   147
	}
[email protected]
   148
[email protected]
   149
	pContext->StringToLocal(params[2], params[3], weapon->display);
[email protected]
   150
[email protected]
   151
	return 1;
[email protected]
   152
}
[email protected]
   153
[email protected]
   154
static cell_t DMN_StripBotItems(IPluginContext *pContext, const cell_t *params)
[email protected]
   155
{
[email protected]
   156
	if (params[1] < 1 || params[1] > gpGlobals->maxClients)
[email protected]
   157
	{
[email protected]
   158
		return pContext->ThrowNativeError("Invalid client index %d", params[1]);
[email protected]
   159
	}
[email protected]
   160
[email protected]
   161
	dm_player_t *player = DM_GetPlayer(params[1]);
[email protected]
   162
	if (!player->pEntity)
[email protected]
   163
	{
[email protected]
   164
		return pContext->ThrowNativeError("Client %d is not in game", params[1]);
[email protected]
   165
	}
[email protected]
   166
[email protected]
   167
	if (!player->pBot)
[email protected]
   168
	{
[email protected]
   169
		return pContext->ThrowNativeError("Client %d is not a bot", params[1]);
[email protected]
   170
	}
[email protected]
   171
[email protected]
   172
	player->pBot->RemoveAllItems(false);
[email protected]
   173
[email protected]
   174
	return 1;
[email protected]
   175
}
[email protected]
   176
[email protected]
   177
static cell_t DMN_GetClientWeapon(IPluginContext *pContext, const cell_t *params)
[email protected]
   178
{
[email protected]
   179
	if (params[1] < 1 || params[1] > gpGlobals->maxClients)
[email protected]
   180
	{
[email protected]
   181
		return pContext->ThrowNativeError("Invalid client index %d", params[1]);
[email protected]
   182
	}
[email protected]
   183
[email protected]
   184
	dm_player_t *player = DM_GetPlayer(params[1]);
[email protected]
   185
	if (!player->pEntity)
[email protected]
   186
	{
[email protected]
   187
		return pContext->ThrowNativeError("Client %d is not in game", params[1]);
[email protected]
   188
	}
[email protected]
   189
[email protected]
   190
	CBaseEntity *pEntity = DM_GetWeaponFromSlot(player->pEntity, params[2]);
[email protected]
   191
	if (!pEntity)
[email protected]
   192
	{
[email protected]
   193
		return -1;
[email protected]
   194
	}
[email protected]
   195
[email protected]
   196
	edict_t *pEdict = gameents->BaseEntityToEdict(pEntity);
[email protected]
   197
	if (!pEdict)
[email protected]
   198
	{
[email protected]
   199
		return -1;
[email protected]
   200
	}
[email protected]
   201
[email protected]
   202
	return gamehelpers->IndexOfEdict(pEdict);
[email protected]
   203
}
[email protected]
   204
[email protected]
   205
static cell_t DMN_DropWeapon(IPluginContext *pContext, const cell_t *params)
[email protected]
   206
{
[email protected]
   207
	if (params[1] < 1 || params[1] > gpGlobals->maxClients)
[email protected]
   208
	{
[email protected]
   209
		return pContext->ThrowNativeError("Invalid client index %d", params[1]);
[email protected]
   210
	}
[email protected]
   211
[email protected]
   212
	dm_player_t *player = DM_GetPlayer(params[1]);
[email protected]
   213
	if (!player->pEntity)
[email protected]
   214
	{
[email protected]
   215
		return pContext->ThrowNativeError("Client %d is not in game", params[1]);
[email protected]
   216
	}
[email protected]
   217
[email protected]
   218
	CBaseEntity *pWeapon = DM_GetBaseEntity(params[2]);
[email protected]
   219
	if (!pWeapon)
[email protected]
   220
	{
[email protected]
   221
		return pContext->ThrowNativeError("Entity %d is not a valid entity", params[2]);
[email protected]
   222
	}
[email protected]
   223
[email protected]
   224
	DM_DropWeapon(player->pEntity, pWeapon);
[email protected]
   225
[email protected]
   226
	return 1;
[email protected]
   227
}
[email protected]
   228
[email protected]
   229
static cell_t DMN_IsRunning(IPluginContext *pContext, const cell_t *params)
[email protected]
   230
{
[email protected]
   231
	return g_IsRunning ? true : false;
[email protected]
   232
}
[email protected]
   233
[email protected]
   234
static cell_t DMN_GetSpawnWaitTime(IPluginContext *pContext, const cell_t *params)
[email protected]
   235
{
[email protected]
   236
	float f = DM_GetRespawnWait();
[email protected]
   237
	return sp_ftoc(f);
[email protected]
   238
}
[email protected]
   239
[email protected]
   240
static cell_t DMN_RespawnClient(IPluginContext *pContext, const cell_t *params)
[email protected]
   241
{
[email protected]
   242
	if (params[1] < 1 || params[1] > gpGlobals->maxClients)
[email protected]
   243
	{
[email protected]
   244
		return pContext->ThrowNativeError("Invalid client index %d", params[1]);
[email protected]
   245
	}
[email protected]
   246
[email protected]
   247
	dm_player_t *player = DM_GetPlayer(params[1]);
[email protected]
   248
	if (!player->pEntity)
[email protected]
   249
	{
[email protected]
   250
		return pContext->ThrowNativeError("Client %d is not in game", params[1]);
[email protected]
   251
	}
[email protected]
   252
[email protected]
   253
	player->is_spawned = params[2] ? false : true;
[email protected]
   254
[email protected]
   255
	DM_RespawnPlayer(params[1]);
[email protected]
   256
[email protected]
   257
	return 1;
[email protected]
   258
}
[email protected]
   259
[email protected]
   260
static cell_t DMN_IsClientAlive(IPluginContext *pContext, const cell_t *params)
[email protected]
   261
{
[email protected]
   262
	if (params[1] < 1 || params[1] > gpGlobals->maxClients)
[email protected]
   263
	{
[email protected]
   264
		return pContext->ThrowNativeError("Invalid client index %d", params[1]);
[email protected]
   265
	}
[email protected]
   266
[email protected]
   267
	dm_player_t *player = DM_GetPlayer(params[1]);
[email protected]
   268
	if (!player->pEntity)
[email protected]
   269
	{
[email protected]
   270
		return pContext->ThrowNativeError("Client %d is not in game", params[1]);
[email protected]
   271
	}
[email protected]
   272
[email protected]
   273
	return DM_IsPlayerAlive(params[1]) ? 1 : 0;
[email protected]
   274
}
[email protected]
   275
[email protected]
   276
static cell_t DMN_GiveAmmo(IPluginContext *pContext, const cell_t *params)
[email protected]
   277
{
[email protected]
   278
	if (params[1] < 1 || params[1] > gpGlobals->maxClients)
[email protected]
   279
	{
[email protected]
   280
		return pContext->ThrowNativeError("Invalid client index %d", params[1]);
[email protected]
   281
	}
[email protected]
   282
[email protected]
   283
	dm_player_t *player = DM_GetPlayer(params[1]);
[email protected]
   284
	if (!player->pEntity)
[email protected]
   285
	{
[email protected]
   286
		return pContext->ThrowNativeError("Client %d is not in game", params[1]);
[email protected]
   287
	}
[email protected]
   288
[email protected]
   289
	return DM_GiveAmmo(player->pEntity, params[2], params[3], params[4] ? true : false);
[email protected]
   290
}
[email protected]
   291
[email protected]
   292
sp_nativeinfo_t g_BaseNatives[] = 
[email protected]
   293
{
[email protected]
   294
	{"DM_GetSpawnMethod",		DMN_GetSpawnMethod},
[email protected]
   295
	{"DM_GetWeaponID",			DMN_GetWeaponID},
[email protected]
   296
	{"DM_GetWeaponType",		DMN_GetWeaponType},
[email protected]
   297
	{"DM_StripBotItems",		DMN_StripBotItems},
[email protected]
   298
	{"DM_GetWeaponClassname",	DMN_GetWeaponClassname},
[email protected]
   299
	{"DM_GetClientWeapon",		DMN_GetClientWeapon},
[email protected]
   300
	{"DM_DropWeapon",			DMN_DropWeapon},
[email protected]
   301
	{"DM_GetWeaponName",		DMN_GetWeaponName},
[email protected]
   302
	{"DM_IsRunning",			DMN_IsRunning},
[email protected]
   303
	{"DM_GetSpawnWaitTime",		DMN_GetSpawnWaitTime},
[email protected]
   304
	{"DM_RespawnClient",		DMN_RespawnClient},
[email protected]
   305
	{"DM_IsClientAlive",		DMN_IsClientAlive},
[email protected]
   306
	{"DM_GiveClientAmmo",		DMN_GiveAmmo},
[email protected]
   307
	{NULL,						NULL},
[email protected]
   308
};