· 6 years ago · Nov 11, 2019, 07:54 PM
1#include <amxmodx>
2#include <amxmisc>
3#include <fun>
4#include <engine>
5#include <hamsandwich>
6#include <cstrike>
7#include <fakemeta>
8#include <sqlx>
9
10//#pragma semicolon 1
11
12/* === DEFINES === */
13#define SZPREFIX "!g[DEATHRUN]"
14#define ROUND_STARTED() ((g_round_end + 5.0) < get_gametime())
15#define FREEROUND_ROUNDS 5
16#define DMG_FALL (1<<5)
17#define PLUGIN_VERSION "4.1.89b"
18#define TIME_START 10
19
20// TABLA Y BASE DE DATOS
21#define SQL_TABLE "SQL_MyTable"
22#define SQL_DATABASE "SQL_DBTest"
23
24#define NivelSiguente(%1) (%1 * 400 + 200)
25#define NivelMax 400
26
27/* === CONST === */
28const OFFSET_BUYZONE = 235;
29const OFFSET_VGUIMENU = 2;
30const OFFSET_CSMENUCODE = 205;
31const OFFSET_LINUX = 5;
32const OFFSET_WEAPON_LINUX = 4;
33const OFFSET_OWNER = 41;
34const HIDE_MONEY = (1<<5);
35const GRENADE_SHOWTRAPS = 5544;
36const IMPULSE_FLASHLIGHT = 100;
37const TASK_MODEL = 1111;
38
39#define ID_MODEL (taskid - TASK_MODEL)
40
41/* === ENUMS === */
42enum _:MESSAGEMODE_STRUCT
43{
44 REGISTRAR_PASSWORD,
45 CONFIRMAR_PASSWORD,
46 INGRESAR_PASSWORD
47};
48
49enum _:rango { rangos_nombre[64], rango_requerido }
50
51enum _:SYNCHUD_STRUCT
52{
53 START,
54 MESSAGE,
55 FREEROUND,
56 WELCOME,
57 DESTROY
58};
59
60enum _:MESSAGES_STRUCT
61{
62 SAYTEXT,
63 SHOWMENU,
64 VGUIMENU,
65 STATUSICON,
66 TEXTMSG,
67 HIDEWEAPON,
68 DEATHMSG
69};
70
71enum _:FREEROUND_STRUCT
72{
73 FR_ROUNDS,
74 FR_STARTED
75};
76
77enum _:OPTIONS_STRUCT
78{
79 PLAYER_INVISIBILITY,
80 WATER_INVISIBILITY
81};
82
83enum _:SPRITE_STRUCT
84{
85 LASERBEAM,
86 RING
87};
88
89enum _:COLORS_STRUCT
90{
91 COLOR_NAME[21],
92 Float:RED,
93 Float:GREEN,
94 Float:BLUE
95};
96
97enum _:MODELS_STRUCT
98{
99 MODEL_NAME[32],
100 MODEL_MODEL[32]
101};
102
103/* === NEW CONST === */
104new const MODELS_DEPLOY[][] =
105{
106 "weapon_knife",
107 "weapon_smokegrenade"
108};
109
110new const GRENADE_COLOR[][COLORS_STRUCT] =
111{
112 { "VERDE", 0.0, 255.0, 0.0 },
113 { "AZUL", 0.0, 0.0, 255.0 },
114 { "ROJO", 255.0, 0.0, 0.0 },
115 { "AMARILLO", 255.0, 255.0, 0.0 },
116 { "ROSADO", 255.0, 0.0, 255.0 },
117 { "CELESTE", 0.0, 255.0, 255.0 },
118 { "AZUL MAJORELLE", 96.0, 80.0, 220.0 },
119 { "AZUL PETROLEO", 1.0, 70.0, 99.0 },
120 { "MALVA", 224.0, 176.0, 255.0 },
121 { "TURQUESA", 48.0, 213.0, 200.0 },
122 { "DORADO", 255.0, 215.0, 0.0 }
123};
124
125new const ADMIN_MODEL[][MODELS_STRUCT] =
126{
127 { "Arnold", "dr_amodel_1" },
128 { "Kevin", "dr_amodel_2" },
129 { "Frank", "dr_amodel_3" },
130 { "Frederic", "dr_amodel_4" },
131 { "George", "dr_amodel_4" },
132 { "Hibrahím", "dr_amodel_4" },
133 { "Isaac", "dr_amodel_5" },
134 { "Abraham", "dr_amodel_6" },
135 { "Oso", "dr_amodel_7" },
136 { "Papá Noel", "dr_amodel_8" },
137 { "Telettubie", "dr_amodel_9" },
138 { "Jugador de Rugby", "dr_amodel_10" },
139 { "Eve's", "dr_amodel_11" },
140 { "Tommy Vercetti", "dr_amodel_12" },
141 { "Carl Jhonson", "dr_amodel_13" }
142};
143
144new const rangos[][rango] =
145 {
146 { "Nuevo", 0 }, { "Recien llegado", 1 }, { "Aventurero", 5 }, { "Principiante", 10 }, { "Experimentado", 15 } , { "Civil I", 20 },
147 { "Civil II", 25 }, { "Soldado ", 30 }, { "Distinguido", 35 }, { "Cabo II", 40 }, { "Cabo I", 45 }, { "Sargento I", 50 },
148 { "Sargento II", 55 }, { "Sargento Mayor I", 60 }, { "Sargento Mayor II", 65 }, { "Sargento Mayor III", 70 } ,
149 { "Sargento Ayudante", 75 }, { "Sargento Supervisor", 80 }, { "Sargento Técnico I", 85 }, { "Sargento Técnico II", 90 },
150 { "Sargento Técnico III", 95 }, { "Maestro Técnico I", 100 }, { "Maestro Técnico II", 105 }, { "Maestro Técnico III", 110 },
151 { "Maestro Técnico Supervisor", 115 }, { "Sub-Teniente I", 120 }, { "Sub-Teniente II", 125 } , { "Sub-Teniente III", 130 },
152 { "Teniente I", 135 }, { "Teniente II", 140 }, { "Teniente III", 145 }, { "Capitán I", 150 }, { "Capitán II", 200 }, { "Capitán III", 210 },
153 { "Teniente Coronel", 220 }, { "Coronel I", 230 }, { "Coronel II", 240 }, { "Coronel III", 250 } , { "General de Brigada I", 260 },
154 { "General de Brigada II", 270 }, { "General de Brigada III", 280 }, { "General de División", 290 }, { "General en Jefe I", 300 },
155 { "General en Jefe II", 320 }, { "General en Jefe III", 340 }, { "Perra", 360 }, { "Puta", 380 }, { "Mega Puta", 400 }
156}
157
158new const SOUND_FREEROUND[] = "DEATHRUN/dr_freeround.wav";
159new const SOUND_STARTED[] = "fvox/adrenaline_shot.wav";
160new const SOUND_TT_DISCONNECT[] = "fvox/medical_repaired.wav";
161new const SOUND_NOT_TERRORIST[] = "fvox/power_restored.wav";
162new const SOUND_PREHEATINH[] = "fvox/torniquette_applied.wav";
163new const SOUND_WELCOME[] = "buttons/blip1.wav";
164new const sonido[] = "Nivel/Nivel.wav";
165new const SOUND_BUTTON_BLOCK[][] =
166{
167 "buttons/spark5.wav",
168 "buttons/button8.wav",
169 "buttons/button10.wav",
170 "buttons/button11.wav",
171 "buttons/latchlocked1.wav",
172 "buttons/latchlocked2.wav"
173};
174
175new const SOUND_GRENADE_DETECT_BREAKABLE[] = "DEATHRUN/dr_gdetect_breakable.wav";
176new const SPRITE_GRENADE_TRAIL[] = "sprites/laserbeam.spr";
177new const SPRITE_GRENADE_RING[] = "sprites/shockwave.spr";
178new const MODEL_TERRORIST[] = "dr_amodel_14";
179new const MODEL_KNIFE_V[] = "models/DEATHRUN/dr_v_knife.mdl";
180new const MODEL_KNIFE_P[] = "models/DEATHRUN/dr_p_knife.mdl";
181new const MODEL_BOMB_V[] = "models/DEATHRUN/dr_v_bomb_trap.mdl";
182new const MODEL_BOMB_P[] = "models/DEATHRUN/dr_p_bomb_trap.mdl";
183new const MODEL_BOMB_W[] = "models/DEATHRUN/dr_w_bomb_trap.mdl";
184
185/* === GLOBAL VARIABLES === */
186new g_life[33];
187new g_maxplayers[1 char];
188new g_synchud[SYNCHUD_STRUCT];
189new g_message[MESSAGES_STRUCT];
190new g_option[33][OPTIONS_STRUCT];
191new g_model[33];
192new g_sprite[SPRITE_STRUCT];
193new g_freeround[FREEROUND_STRUCT];
194new g_entity_think;
195new g_firstround;
196new g_dr_time;
197new g_dr_time_start;
198new g_fake_player;
199new g_semiclip[33];
200new bool:g_terrorist_disconnected;
201new bool:g_message_start;
202new g_check_terrorist;
203new g_last_terrorist[32];
204new g_last_tt;
205new g_grenade_showtraps[33];
206new g_detect_trap[4999];
207new Float:g_grenade_time[33];
208new Float:g_round_end;
209new g_game_commencing;
210new Float:g_trap_color[33][3];
211new g_color_select[33];
212new g_camera[33];
213new g_target[33], g_target_name[33][32];
214new g_playermodel[33][32];
215new Trie:g_button;
216new g_szbuttons[5];
217
218//Registros
219new g_user_name[33][32]; // NOMBRE DEL USUARIO - SERÁ UNA CADENA DE 32 DÍGITOS.
220new g_user_password[33][32]; // CONTRASEÑA DEL USUARIO - SERÁ UNA CADENA DE 32 DÍGITOS.
221new g_user_register[33]; // ESTADO DEL USUARIO (SI ESTÁ REGISTRADO O NO).
222new g_user_logged[33]; // ESTADO DEL USUARIO (SI ESTÁ LOGUEADO O NO).
223new g_user_auto_logged[33]; // ESTADO DEL USUARIO (SI ESTÁ AUTOLOGUEADO O NO).
224new g_user_id[33]; // ID DEL USUARIO.
225new g_user_date_register[33][32]; // FECHA DE REGISTRO.
226new g_user_last_date[33][32]; // ÚLTIMO INGRESO DEL USUARIO AL SERVIDOR.
227new g_frags[33]; // FRAGS DEL USUARIO.
228new g_death[33]; // MUERTES DEL USUARIO.
229
230//Nuevo
231new g_nivel[33];
232new g_exp[33];
233new g_rango[33];
234new g_monedas[33];
235
236// Hud
237new Hud;
238
239new g_messagemode[33];
240
241/* ================================================== */
242/*
243 VARIABLES PARA CONECTAR / OBTENER INFORMACIÓN DE LA BASE DE DATOS.
244*/
245new Handle:g_sql_connection; // Variable que abrirá conexión con la base de datos.
246new Handle:g_sql_htuple; // Variable que almacenará información de la conexión (No se conecta a la base de datos).
247
248public plugin_init()
249{
250 register_plugin("AMX Deathrun", PLUGIN_VERSION, "Cristian'");
251
252 /* === EVENTS === */
253 register_event("DeathMsg", "event_deathmsg", "a");
254 register_event("CurWeapon", "event_curweapon", "be", "1=1");
255 register_logevent("event_round_start", 2, "1=Round_Start");
256 register_logevent("event_round_end", 2, "1=Round_End");
257
258 register_event("HLTV", "event_HLTV", "a", "1=0", "2=0");
259
260 register_impulse(IMPULSE_FLASHLIGHT, "reg_Impulse_FlashLight");
261
262 /* === HAMS === */
263 RegisterHam(Ham_Spawn, "player", "ham_PlayerSpawn_Post", true);
264 RegisterHam(Ham_Killed, "player", "fw_PlayerKilled");
265 RegisterHam(Ham_Use, "func_button", "ham_Use_Button");
266 RegisterHam(Ham_Use, "func_rot_button", "ham_Use_Button");
267 RegisterHam(Ham_Use, "button_target", "ham_Use_Button");
268 RegisterHam(Ham_Touch, "weaponbox", "ham_TouchWeapon");
269 RegisterHam(Ham_Touch, "armoury_entity", "ham_TouchWeapon");
270 RegisterHam(Ham_Touch, "weapon_shield", "ham_TouchWeapon");
271 RegisterHam(Ham_Think, "grenade", "ham_ThinkGrenade");
272 new i;
273
274 for (i = 0; i < sizeof(MODELS_DEPLOY); i++)
275 RegisterHam(Ham_Item_Deploy, MODELS_DEPLOY[i], "ham_Item_Deploy_Post", true);
276
277 RegisterHam(Ham_TakeDamage, "player", "ham_TakeDamage");
278 RegisterHam(Ham_TraceAttack, "player", "ham_TraceAttack");
279
280 /* === FORWARDS === */
281 register_forward(FM_AddToFullPack, "fw_AddToFullPack_Post", true);
282 register_forward(FM_SetClientKeyValue, "fw_SetClientKeyValue");
283 register_forward(FM_ClientUserInfoChanged, "fw_ClientUserInfoChanged");
284 register_forward(FM_StartFrame, "fw_StartFrame");
285 register_forward(FM_ClientKill, "fw_ClientKill");
286 register_forward(FM_SetModel, "fw_SetModel");
287
288 /* === CLCMDS === */
289 register_clcmd("chooseteam", "clcmd_changeteam");
290 register_clcmd("jointeam", "clcmd_changeteam");
291 register_clcmd("radio1", "clcmd_radio");
292 register_clcmd("radio2", "clcmd_radio");
293 register_clcmd("radio3", "clcmd_radio");
294 register_clcmd("drop", "clcmd_drop");
295 register_clcmd("say /connected", "clcmd_connected");
296 register_clcmd("say /cam", "clcmd_camera");
297 register_clcmd("say", "clcmd_say");
298 register_clcmd("CANTIDAD_DE_VIDAS", "cantidad_de_vidas");
299 register_impulse(201, "clcmd_imp201");
300
301 register_clcmd("REGISTRAR_PASSWORD", "clcmd_messagemode");
302 register_clcmd("CONFIRMAR_PASSWORD", "clcmd_messagemode");
303 register_clcmd("INGRESAR_PASSWORD", "clcmd_messagemode");
304
305 register_clcmd("say /frags", "clcmd_frags");
306
307 g_maxplayers{0} = get_maxplayers();
308
309 g_synchud[START] = CreateHudSyncObj();
310 g_synchud[MESSAGE] = CreateHudSyncObj();
311 g_synchud[FREEROUND] = CreateHudSyncObj();
312 g_synchud[WELCOME] = CreateHudSyncObj();
313 g_synchud[DESTROY] = CreateHudSyncObj();
314
315 /* === MESSAGES === */
316 g_message[SAYTEXT] = get_user_msgid("SayText");
317 g_message[SHOWMENU] = get_user_msgid("ShowMenu");
318 g_message[VGUIMENU] = get_user_msgid("VGUIMenu");
319 g_message[STATUSICON] = get_user_msgid("StatusIcon");
320 g_message[TEXTMSG] = get_user_msgid("TextMsg");
321 g_message[HIDEWEAPON] = get_user_msgid("HideWeapon");
322 g_message[DEATHMSG] = get_user_msgid("DeathMsg");
323
324 /* === REGISTER_MESSAGE === */
325 register_message(g_message[STATUSICON], "message_statusicon");
326 register_message(g_message[TEXTMSG], "message_textmsg");
327 register_message(g_message[SHOWMENU], "message_showmenu");
328 register_message(g_message[VGUIMENU], "message_vguimenu");
329 register_message(g_message[DEATHMSG], "message_deathmsg");
330
331 g_entity_think = create_entity("info_target");
332
333 entity_set_string(g_entity_think, EV_SZ_classname, "StartDr");
334 register_think("StartDr", "entity_think_countdown");
335
336
337 remove_entity_name("info_map_parameters");
338 remove_entity_name("func_buyzone");
339 remove_entity_name("env_beam");
340
341 g_firstround = true;
342 g_dr_time = TIME_START;
343 g_button = TrieCreate();
344
345 static ent, count;
346
347 while ((ent = find_ent_by_class(ent, "info_player_deathmatch")) > 0)
348 {
349 if (count++ > 1)
350 break;
351 }
352
353 if (count <= 1)
354 g_fake_player = -1;
355
356 set_task(60.0, "print_message", _, _, _, "b");
357 set_task(8.0, "check_terrorist", _, _, _, "b");
358 set_task(5.0, "create_bot");
359
360 server_print("no_amxx_uncompress");
361 Hud = CreateHudSyncObj();
362 sqlx_init(); // Llamamos a la función que conectará la base de datos y creará la tabla.
363}
364
365public print_message()
366{
367 switch(random_num(0, 1))
368 {
369 case 0: chat_color(0, "%s !gDeathrun %s!y by !g; Cristian'", SZPREFIX, PLUGIN_VERSION);
370 case 1:
371 {
372 static mapname[32], admin[21];
373 get_mapname(mapname, charsmax(mapname));
374
375 if (get_administration() > 0)
376 {
377 format(admin, charsmax(admin), " !t(!g+%d !y%s!t)", get_administration(), (get_administration() == 1) ?
378 "administrador" : "administradores");
379 }
380 else
381 format(admin, charsmax(admin), "");
382
383 chat_color(0, "%s !g%d %s!y %s%s jugando en el mapa !g%s!y.", SZPREFIX, get_connected(),
384 (get_connected() == 1) ? "usuario" : "usuarios", admin,
385 (get_connected() == 1) ? "está" : "están", mapname);
386 }
387 }
388}
389
390public plugin_precache()
391{
392 new i, sztext[256];
393
394 precache_sound(SOUND_FREEROUND);
395 precache_sound(SOUND_GRENADE_DETECT_BREAKABLE);
396 precache_sound(SOUND_WELCOME);
397
398 for (i = 0; i < sizeof(SOUND_BUTTON_BLOCK); i++)
399 precache_sound(SOUND_BUTTON_BLOCK[i]);
400
401 precache_model("models/rpgrocket.mdl");
402 precache_model(MODEL_KNIFE_V);
403 precache_model(MODEL_KNIFE_P);
404 precache_model(MODEL_BOMB_V);
405 precache_model(MODEL_BOMB_P);
406 precache_model(MODEL_BOMB_W);
407
408 g_sprite[LASERBEAM] = precache_model(SPRITE_GRENADE_TRAIL);
409 g_sprite[RING] = precache_model(SPRITE_GRENADE_RING);
410
411 for (i = 0; i < sizeof(ADMIN_MODEL); i++)
412 {
413 format(sztext, charsmax(sztext), "models/player/%s/%s.mdl", ADMIN_MODEL[i][MODEL_MODEL], ADMIN_MODEL[i][MODEL_MODEL]);
414 precache_model(sztext);
415
416 format(sztext, charsmax(sztext), "models/player/%s/%sT.mdl", ADMIN_MODEL[i][MODEL_MODEL], ADMIN_MODEL[i][MODEL_MODEL]);
417
418 if (file_exists(sztext))
419 precache_model(sztext);
420 }
421
422 format(sztext, charsmax(sztext), "models/player/%s/%s.mdl", MODEL_TERRORIST, MODEL_TERRORIST);
423 precache_model(sztext);
424}
425
426public client_putinserver(id)
427{
428 g_option[id][PLAYER_INVISIBILITY] = false;
429 g_option[id][WATER_INVISIBILITY] = false;
430 g_color_select[id] = 4;
431 g_trap_color[id][0] = 255.0;
432 g_trap_color[id][1] = 0.0;
433 g_trap_color[id][2] = 255.0;
434
435 g_life[id] = 0;
436
437 //set_task(0.5, "client_jointeam", id);
438 set_task(2.0, "client_welcome", id);
439 set_task(1.0,"ShowHud", id+570,_,_,"b");
440
441 // Reseteamos sus valores
442 get_user_name(id, g_user_name[id], 31);
443
444 g_user_register[id] = 0;
445 g_user_logged[id] = 0;
446 g_user_auto_logged[id] = 0;
447 g_frags[id] = 0;
448 g_death[id] = 0;
449
450 g_user_password[id][0] = EOS;
451 g_user_date_register[id][0] = EOS;
452 g_user_last_date[id][0] = EOS;
453
454 set_task(0.1, "user_check", id); // Llamamos a la función "user_check" en un lapso de 0.1 segundos para seleccionar los datos del usuario que ingresó al servidor.
455}
456
457public client_jointeam(id)
458{
459 if (is_user_bot(id))
460 return;
461
462 static vgui;
463 vgui = (get_pdata_int(id, 510) & (1<<0));
464
465 if (vgui)
466 set_pdata_int(id, 510, get_pdata_int(id, 510) & ~(1<<0));
467
468 set_msg_block(get_user_msgid("ShowMenu"), BLOCK_ONCE);
469 set_msg_block(get_user_msgid("VGUIMenu"), BLOCK_ONCE);
470 //engclient_cmd(id, "jointeam", "2");
471 //engclient_cmd(id, "joinclass", "5");
472
473
474 set_msg_block(get_user_msgid("ShowMenu"), get_msg_block(get_user_msgid("ShowMenu")));
475 set_msg_block(get_user_msgid("ShowMenu"), get_msg_block(get_user_msgid("VGUIMenu")));
476
477 if (vgui)
478 set_pdata_int(id, 510, get_pdata_int(id, 510));
479
480 //set_task(0.1, "respawn_player", id);
481}
482
483public respawn_player(id)
484 ExecuteHamB(Ham_CS_RoundRespawn, id);
485
486public client_welcome(id)
487{
488 if (!is_user_connected(id))
489 return;
490
491 static name[32];
492 get_user_name(id, name, charsmax(name));
493
494 client_cmd(id, "spk ^"%s^"", SOUND_WELCOME);
495
496 client_print(id, print_center, "BIENEVNID@ %s AL DEATHRUN!", name);
497}
498
499public client_disconnect(id)
500{
501 // Si el usuario logueado se desconecta del servidor, llamamos a la función que ejecutará la consulta para guardar sus datos.
502 if (g_user_logged[id])
503 {
504 save_data(id);
505 g_user_logged[id] = 0;
506 }
507
508 if (g_fake_player == id)
509 {
510 set_task(1.5, "create_bot");
511 g_fake_player = 0;
512 }
513
514 if (get_connected() > 1)
515 {
516 if (cs_get_user_team(id) == CS_TEAM_T)
517 {
518 g_terrorist_disconnected = true;
519 get_user_name(id, g_last_terrorist, charsmax(g_last_terrorist));
520 select_terrorist();
521 }
522 }
523
524 if (task_exists(id + TASK_MODEL))
525 remove_task(id + TASK_MODEL);
526
527 check_terrorist();
528 remove_task(id+570);
529
530}
531
532public user_check(id)
533{
534 if (!is_user_connected(id)) // Si no está conectado detenemos el complemento.
535 return PLUGIN_HANDLED;
536
537 /*
538 * Lógica de la consulta: SELECCIONAR id, password, ip, date_register, last_date DE 'tabla' DONDE name = 'mi_name';
539 * El ";" es utilizado para separar las consultas.
540
541 */
542
543 // Preparamos la consulta
544 new Handle:query;
545 query = SQL_PrepareQuery(g_sql_connection, "SELECT id, password, ip, date_register, last_date FROM '%s' WHERE name = ^"%s^";", SQL_TABLE, g_user_name[id]);
546
547 // Ejecutamos la consulta que anteriormente preparamos (SQL_PrepareQuery).
548 if (!SQL_Execute(query)) // Si la consulta no es válida
549 {
550 SQL_FreeHandle(query); // Liberamos el identificador de la consulta.
551 sql_query_error(id, query);
552 }
553 else if (SQL_NumResults(query)) // Si la consulta arroja resultados
554 {
555 /*
556 * Si seleccionamos los datos individualmente y no todos (*) el SQL_ReadResult comenzaría en 0.
557 * Ejemplo: SELECT id, password, ip, date_register, last_date (0, 1, 2, 3, 4).
558 */
559
560 g_user_register[id] = 1; // Ponemos que el usuario está registrado.
561
562 new ip[21], dbip[21];
563 get_user_ip(id, ip, 20, 1); // Obtenemos la IP del usuario.
564
565 g_user_id[id] = SQL_ReadResult(query, 0); // Obtenemos el ID del usuario de la base de datos.
566 SQL_ReadResult(query, 1, g_user_password[id], 31); // Obtenemos la CONTRASEÑA de la base de datos que luego será verificada al ingresar la contraseña en una nueva cadena.
567 SQL_ReadResult(query, 2, dbip, 20); // Obtenemos la IP de la base de datos.
568 SQL_ReadResult(query, 3, g_user_date_register[id], 31); // Obtenemos la fecha de registro de la base de datos.
569 SQL_ReadResult(query, 4, g_user_last_date[id], 31); // Obtenemos la última vez que ingresó de la base de datos.
570
571 if (equali(ip, dbip)) // Si la IP del USUARIO es igual a la IP de la BASE DE DATOS.
572 g_user_auto_logged[id] = 1; // Ponemos que está auto logueado.
573
574
575 SQL_FreeHandle(query); // Liberamos el identificador de la consulta.
576 }
577 else
578 SQL_FreeHandle(query); // Liberamos el identificador de la consulta.
579
580 clcmd_changeteam(id);
581 return PLUGIN_HANDLED;
582}
583
584public check_terrorist()
585{
586 if (get_connected() < 2)
587 return;
588
589 static id;
590
591 if (get_tts() < 1)
592 {
593 g_check_terrorist = true;
594
595 if (g_firstround)
596 {
597 if (!g_dr_time_start)
598 {
599 for (id = 1; id <= g_maxplayers{0}; id++)
600 {
601 if (!is_user_alive(id))
602 continue;
603
604 if (is_user_bot(id))
605 continue;
606
607 user_silentkill(id);
608 }
609
610 set_hudmessage(0, 255, 0, -1.0, 0.17, 1, 0.0, 3.0, 2.0, 1.0, -1);
611 ShowSyncHudMsg(0, g_synchud[START], "¡ RONDA DE PRECALENTAMIENTO !");
612 client_cmd(0, "spk ^"%s^"", SOUND_PREHEATINH);
613 }
614 }
615 else
616 {
617 if (!g_terrorist_disconnected)
618 detect_terrorist();
619
620 select_terrorist();
621 }
622 }
623}
624
625detect_terrorist()
626{
627 static id;
628
629 for (id = 1; id <= g_maxplayers{0}; id++)
630 {
631 if (!is_user_alive(id))
632 continue;
633
634 if (is_user_bot(id))
635 continue;
636
637 user_silentkill(id);
638 }
639
640 set_hudmessage(0, 255, 0, -1.0, 0.17, 1, 0.0, 3.0, 2.0, 1.0, -1);
641 ShowSyncHudMsg(0, g_synchud[START], "¡ NO SE DETECTÓ NINGÚN TERRORISTA !");
642 client_cmd(0, "spk ^"%s^"", SOUND_NOT_TERRORIST);
643}
644
645public create_bot()
646{
647 if (g_fake_player == -1)
648 return;
649
650 new ent;
651 ent = find_player("i");
652
653 if (!ent)
654 {
655 ent = engfunc(EngFunc_CreateFakeClient, "[AMX] DEATHRUN ");
656
657 if (is_valid_ent(ent))
658 {
659 engfunc(EngFunc_FreeEntPrivateData, ent);
660 dllfunc(MetaFunc_CallGameEntity, "player", ent);
661 set_user_info(ent, "rate", "3500");
662 set_user_info(ent, "cl_updaterate", "25");
663 set_user_info(ent, "cl_lw", "1");
664 set_user_info(ent, "cl_lc", "1");
665 set_user_info(ent, "cl_dlmax", "128");
666 set_user_info(ent, "cl_righthand", "1");
667 set_user_info(ent, "_vgui_menus", "0");
668 set_user_info(ent, "_ah", "0");
669 set_user_info(ent, "dm", "0");
670 set_user_info(ent, "tracker", "0");
671 set_user_info(ent, "friends", "0");
672 set_user_info(ent, "*bot", "1");
673 entity_set_int(ent, EV_INT_flags, (entity_get_int(ent, EV_INT_flags)) | FL_FAKECLIENT);
674 entity_set_int(ent, EV_INT_colormap, ent);
675
676 new szMsg[128];
677 dllfunc(DLLFunc_ClientConnect, ent, "DEATHRUN", "127.0.0.1", szMsg);
678 dllfunc(DLLFunc_ClientPutInServer, ent);
679
680 cs_set_user_team(ent, CS_TEAM_T);
681 ExecuteHamB(Ham_CS_RoundRespawn, ent);
682
683 entity_set_int(ent, EV_INT_effects, (entity_get_int(ent, EV_INT_effects)) | EF_NODRAW);
684 entity_set_int(ent, EV_INT_solid, SOLID_NOT);
685 dllfunc(DLLFunc_Think, ent);
686
687 g_fake_player = ent;
688 }
689 }
690}
691
692public event_deathmsg()
693{
694 new attacker, victim;
695 attacker = read_data(1);
696 victim = read_data(2);
697
698 g_frags[attacker]++;
699 g_death[victim]++;
700
701 if( victim == attacker )
702 return;
703
704 if( is_user_alive( attacker ) )
705 {
706 g_exp[ attacker ] += 100; // El 20 es el numero de experiencia que ganara el usuario al matar.
707 ver_nivel( attacker );
708 }
709
710 if (cs_get_user_team(victim) == CS_TEAM_T && is_user_alive(g_fake_player))
711 fakedamage(g_fake_player, "worldspawn", 100.0, DMG_GENERIC);
712
713 if (is_user_connected(attacker) && cs_get_user_team(victim) == CS_TEAM_T)
714 {
715 SetHamParamInteger(3, 2);
716 static name[32], name2[32];
717 get_user_name(attacker, name, charsmax(name));
718 get_user_name(victim, name2, charsmax(name2));
719
720 chat_color(0, "%s !g%s!y ganó una vida por matar al terrorista [!g%s!y].", SZPREFIX, name, name2);
721 g_life[attacker]++;
722 set_user_frags(attacker, get_user_frags(attacker) + 1);
723 }
724
725 if (ROUND_STARTED() && g_life[victim] >= 1)
726 {
727 if (get_cts_alive() > 1)
728 {
729 chat_color(victim, "%s !yEn 3 segundos se te abrirá el menú de vidas.", SZPREFIX);
730 set_task(3.0, "show_menu_lifes", victim);
731 }
732 else
733 {
734 chat_color(victim, "%s !yTenés !g%d!y %s, no podés %s ahora ya que hay un solo ct con vida.",
735 SZPREFIX, g_life[victim], (g_life[victim] > 1) ? "vidas" : "vida", (g_life[victim] > 1) ? "usarlas" : "usarla");
736 }
737 }
738 ver_nivel(attacker)
739}
740
741public event_curweapon(id)
742{
743 if (g_freeround[FR_STARTED])
744 engclient_cmd(id, "weapon_knife");
745}
746
747public message_deathmsg(msgent, dest, id)
748{
749 if (get_msg_arg_int(2) == g_fake_player)
750 return PLUGIN_HANDLED;
751
752 return PLUGIN_CONTINUE;
753}
754
755public show_menu_lifes(id)
756{
757 if (cs_get_user_team(id) == CS_TEAM_T)
758 return;
759
760 if (get_cts_alive() == 1)
761 {
762 chat_color(id, "%s !yEl menú de vidas fue cancelado ya que hay un solo jugador vivo.", SZPREFIX);
763 return;
764 }
765
766 static menu, sztext[56];
767 format(sztext, charsmax(sztext), "Tenés \y%d %s", g_life[id], (g_life[id] == 1) ? "vida" : "vidas");
768 menu = menu_create(sztext, "handled_show_menu_lifes");
769
770 menu_additem(menu, "\yUsar vida", "1", 0);
771 menu_additem(menu, "Guardar vida", "2", 0);
772
773
774 set_pdata_int(id, OFFSET_CSMENUCODE, false, OFFSET_LINUX);
775 menu_display(id, menu);
776}
777
778public handled_show_menu_lifes(id, menu, item)
779{
780 if (cs_get_user_team(id) == CS_TEAM_T || !ROUND_STARTED())
781 {
782 menu_destroy(menu);
783 return PLUGIN_HANDLED;
784 }
785
786 switch(item)
787 {
788 case MENU_EXIT:
789 {
790 menu_destroy(menu);
791 return PLUGIN_HANDLED;
792 }
793 case 0:
794 {
795 if (get_cts_alive() == 1)
796 {
797 chat_color(id, "%s !yNo fuiste revivido ya que hay un solo ct vivo.", SZPREFIX);
798 return PLUGIN_HANDLED;
799 }
800
801 g_life[id]--;
802
803 if (g_life[id] >= 1)
804 chat_color(id, "%s !yUsaste una vida. Te quedan !g%d!y %s.", SZPREFIX, g_life[id], (g_life[id] == 1) ? "vida" : "vidas");
805 else
806 chat_color(id, "%s !yUsaste una vida. Ya no tenés más vidas.", SZPREFIX);
807
808 ExecuteHamB(Ham_CS_RoundRespawn, id);
809 }
810 case 1: chat_color(id, "%s !yCerraste el menú de vidas.", SZPREFIX);
811 }
812
813 menu_destroy(menu);
814 return PLUGIN_HANDLED;
815}
816
817public event_round_start()
818{
819 set_cvar_float("mp_freezetime", 0.0);
820 set_cvar_num("sv_airaccelerate", 100);
821 set_cvar_num("mp_autoteambalance", 0);
822 set_cvar_num("mp_limitteams", 0);
823 set_cvar_num("sv_alltalk", 1);
824
825 if (get_connected() <= 1)
826 return;
827
828 if (g_check_terrorist)
829 g_check_terrorist = false;
830
831 if (g_firstround)
832 {
833 if (!g_dr_time_start)
834 {
835 g_dr_time_start = true;
836 g_message_start = true;
837 chat_color(0, "%s !yEl deathrun está por comenzar.", SZPREFIX);
838 entity_set_float(g_entity_think, EV_FL_nextthink, get_gametime() + 0.5);
839 }
840 }
841 else
842 {
843 if (g_freeround[FR_ROUNDS] < FREEROUND_ROUNDS)
844 g_freeround[FR_ROUNDS]++;
845 else
846 {
847 g_freeround[FR_STARTED] = true;
848 client_cmd(0, "spk ^"%s^"", SOUND_FREEROUND);
849 set_hudmessage(0, 255, 0, -1.0, 0.17, 1, 0.0, 3.0, 2.0, 1.0, -1);
850 ShowSyncHudMsg(0, g_synchud[START], "¡ COMENZÓ LA RONDA LIBRE !");
851 entity_set_float(g_entity_think, EV_FL_nextthink, get_gametime() + 1.0);
852 g_freeround[FR_ROUNDS] = 0;
853 }
854 }
855
856 new ent;
857
858 while ((ent = engfunc(EngFunc_FindEntityByString, ent, "classname", "func_button")) != 0)
859 dllfunc(DLLFunc_Think, ent);
860
861 TrieClear(g_button);
862}
863
864public event_round_end()
865{
866 if (g_firstround)
867 return;
868
869 if (g_freeround[FR_STARTED])
870 g_freeround[FR_STARTED] = false;
871
872 if (!g_check_terrorist)
873 select_terrorist();
874
875 g_round_end = get_gametime();
876}
877
878public event_HLTV()
879{
880 new id;
881
882 for (id = 1; id <= g_maxplayers{0}; id++)
883 {
884 if (g_user_logged[id]) // Si el usuario está logueado, le guardamos sus datos.
885 save_data(id); // Si es una nueva ronda, llamamos a la función que ejecutará la consulta para guardar sus datos.
886 }
887}
888
889public reg_Impulse_FlashLight(id)
890 return PLUGIN_HANDLED;
891
892select_terrorist()
893{
894 if (get_connected() < 2)
895 return;
896
897 static target, name[32], id;
898
899 while ((target = random_player(random_num(1, get_cts()))) == g_last_tt) {}
900
901 g_last_tt = target;
902
903 for (id = 1; id <= g_maxplayers{0}; id++)
904 {
905 if (!is_user_connected(id))
906 continue;
907
908 if (is_user_bot(id))
909 continue;
910
911 if (cs_get_user_team(id) == CS_TEAM_T)
912 cs_set_user_team(id, CS_TEAM_CT);
913 }
914
915 if (cs_get_user_team(target) == CS_TEAM_CT || cs_get_user_team(target) == CS_TEAM_T)
916 {
917 get_user_name(target, name, charsmax(name));
918 cs_set_user_team(target, CS_TEAM_T);
919 set_user_info(target, "model", MODEL_TERRORIST);
920
921 if (is_user_alive(target))
922 ExecuteHamB(Ham_CS_RoundRespawn, target);
923
924 if (g_firstround)
925 chat_color(0, "%s !ySe inició una ronda nueva de precalentamiento.", SZPREFIX, name);
926 else
927 {
928 if (!g_message_start)
929 {
930 if (g_terrorist_disconnected)
931 {
932 client_cmd(0, "spk ^"%s^"", SOUND_TT_DISCONNECT);
933 chat_color(0, "%s !yEl terrorista !g%s!y se desconectó del servidor. !g%s!y será el nuevo terrorista.", SZPREFIX, g_last_terrorist, name);
934 ExecuteHamB(Ham_CS_RoundRespawn, target);
935 g_terrorist_disconnected = false;
936 }
937 else
938 chat_color(0, "%s !yEl jugador !g%s!y es ahora el terrorista.", SZPREFIX, name);
939 }
940 else
941 chat_color(0, "%s !yComenzó el deathrun. !g%s!y será el terrorista.", SZPREFIX, name);
942 }
943 }
944}
945
946public entity_think_countdown(ent)
947{
948 if (ent != g_entity_think)
949 return;
950
951 static sztime[6];
952
953 if (g_freeround[FR_STARTED])
954 {
955 set_hudmessage(random_num(50, 255), random_num(50, 255), random_num(50, 255), 0.70, 0.25, 1, 0.0, 3.0, 2.0, 1.0, -1);
956 ShowSyncHudMsg(0, g_synchud[FREEROUND], "¡ FREERUN !");
957 entity_set_float(g_entity_think, EV_FL_nextthink, get_gametime() + 2.0);
958 return;
959 }
960
961 if (g_firstround)
962 {
963 if (g_dr_time > 0)
964 {
965 num_to_word(g_dr_time, sztime, charsmax(sztime));
966 client_cmd(0, "spk ^"fvox/%s.wav^"", sztime);
967
968 set_hudmessage(0, 255, 0, -1.0, 0.17, 1, 0.0, 3.0, 2.0, 1.0, -1);
969 ShowSyncHudMsg(0, g_synchud[START], "¡ EL DEATHRUN COMENZARÁ EN %d SEGUNDOS !", g_dr_time);
970
971 g_dr_time--;
972
973 entity_set_float(g_entity_think, EV_FL_nextthink, get_gametime() + 1.0);
974 }
975 else
976 {
977 g_firstround = false;
978 ClearSyncHud(0, g_synchud[START]);
979
980 client_cmd(0, "spk ^"%s^"", SOUND_STARTED);
981 set_cvar_num("sv_restart", 1);
982 select_terrorist();
983 }
984 }
985}
986
987public ham_PlayerSpawn_Post(id)
988{
989 if (!is_user_alive(id))
990 return HAM_IGNORED;
991
992 strip_user_weapons(id);
993 give_item(id, "weapon_knife");
994
995
996 if (cs_get_user_team(id) == CS_TEAM_CT)
997 set_task(0.5, "give_usp", id);
998
999 if (g_fake_player == id)
1000 {
1001 entity_set_float(id, EV_FL_frags, -9999.0);
1002 cs_set_user_deaths(id, -9999);
1003
1004 entity_set_int(id, EV_INT_effects, (entity_get_int(id, EV_INT_effects)) | EF_NODRAW );
1005 entity_set_int(id, EV_INT_solid, SOLID_NOT);
1006 entity_set_origin(id, Float:{ 999999.0, 999999.0, 999999.0 });
1007 dllfunc(DLLFunc_Think, id);
1008 }
1009
1010
1011 if (g_grenade_showtraps[id])
1012 g_grenade_showtraps[id] = false;
1013
1014 remove_task(id + TASK_MODEL);
1015 set_task(0.5, "check_model", id + TASK_MODEL);
1016
1017 remove_hud_money(id);
1018
1019 return HAM_IGNORED;
1020}
1021
1022public check_model(taskid)
1023{
1024 if (!is_user_connected(ID_MODEL) || !is_user_alive(ID_MODEL) || cs_get_user_team(ID_MODEL) == CS_TEAM_T)
1025 return;
1026
1027 static model[32];
1028 get_user_model(ID_MODEL, model, charsmax(model));
1029
1030 if (!equal(model, g_playermodel[ID_MODEL]))
1031 set_user_info(ID_MODEL, "model", g_playermodel[ID_MODEL]);
1032}
1033
1034public give_usp(id)
1035{
1036 if (!is_user_connected(id) || g_freeround[FR_STARTED])
1037 return;
1038
1039 give_item(id, "weapon_usp");
1040 cs_set_user_bpammo(id, CSW_USP, 100);
1041}
1042
1043public remove_hud_money(id)
1044{
1045 if (!is_user_alive(id))
1046 return;
1047
1048 message_begin(MSG_ONE, g_message[HIDEWEAPON], .player = id);
1049 write_byte(HIDE_MONEY);
1050 message_end();
1051}
1052
1053public fw_PlayerKilled( victim, attacker )
1054{
1055 if ( !is_user_alive(attacker))
1056 return;
1057
1058 if(cs_get_user_team(victim) == cs_get_user_team(attacker)) return;
1059
1060 if(cs_get_user_team(victim) == CS_TEAM_T)
1061 g_monedas[attacker] += 20
1062 else if(cs_get_user_team(victim) == CS_TEAM_CT)
1063 g_monedas[attacker] += 30
1064}
1065
1066public vermonedas(id)
1067{
1068 if(g_monedas[id] >= 1)
1069 chat_color(id, "[AMXX] Tienes %d moneda%s.", g_monedas[id], g_monedas[id] >= 2 ? "s" : "")
1070 else
1071 chat_color(id, "[AMXX] No tienes ninguna moneda.")
1072}
1073
1074public ham_Use_Button(button, id, activator, use_type, Float:value)
1075{
1076 if (!is_user_alive(id))
1077 return HAM_IGNORED;
1078
1079 if (cs_get_user_team(id) == CS_TEAM_T)
1080 {
1081 if (g_freeround[FR_STARTED])
1082 return HAM_SUPERCEDE;
1083
1084 num_to_str(button, g_szbuttons, charsmax(g_szbuttons));
1085
1086 if (!TrieKeyExists(g_button, g_szbuttons))
1087 TrieSetCell(g_button, g_szbuttons, true);
1088 else
1089 {
1090 client_print(id, print_center, "YA ACTIVASTE ESTA TRAMPA");
1091 emit_sound(button, CHAN_VOICE, SOUND_BUTTON_BLOCK[random_num(1, charsmax(SOUND_BUTTON_BLOCK))], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
1092 return HAM_SUPERCEDE;
1093 }
1094 }
1095
1096 return HAM_IGNORED;
1097}
1098
1099public ham_TouchWeapon(weapon, id)
1100{
1101 if (!is_user_connected(id))
1102 return HAM_IGNORED;
1103
1104 if (g_freeround[FR_STARTED])
1105 return HAM_SUPERCEDE;
1106
1107 return HAM_IGNORED;
1108}
1109
1110public ham_ThinkGrenade(ent)
1111{
1112 if (!is_valid_ent(ent))
1113 return HAM_IGNORED;
1114
1115 if (entity_get_float(ent, EV_FL_dmgtime) > get_gametime())
1116 return HAM_IGNORED;
1117
1118 static owner;
1119 owner = entity_get_edict(ent, EV_ENT_owner);
1120
1121 if (!g_grenade_showtraps[owner])
1122 return HAM_IGNORED;
1123
1124 if (entity_get_int(ent, EV_INT_flTimeStepSound) == GRENADE_SHOWTRAPS)
1125 {
1126 g_grenade_showtraps[owner] = false;
1127 grenade_explode(ent);
1128 return HAM_SUPERCEDE;
1129 }
1130
1131 return HAM_IGNORED;
1132}
1133
1134public ham_Item_Deploy_Post(ent)
1135{
1136 if (!pev_valid(ent))
1137 return HAM_IGNORED;
1138
1139 static id;
1140 id = get_pdata_cbase(ent, OFFSET_OWNER, OFFSET_WEAPON_LINUX);
1141
1142 if (!is_user_alive(id))
1143 return HAM_IGNORED;
1144
1145 static weapon;
1146 weapon = cs_get_weapon_id(ent);
1147
1148 switch(weapon)
1149 {
1150 case CSW_KNIFE:
1151 {
1152 if (cs_get_user_team(id) == CS_TEAM_T)
1153 {
1154 entity_set_string(id, EV_SZ_viewmodel, MODEL_KNIFE_V);
1155 entity_set_string(id, EV_SZ_weaponmodel, MODEL_KNIFE_P);
1156 }
1157 }
1158 case CSW_SMOKEGRENADE:
1159 {
1160 if (g_grenade_showtraps[id])
1161 {
1162 entity_set_string(id, EV_SZ_viewmodel, MODEL_BOMB_V);
1163 entity_set_string(id, EV_SZ_weaponmodel, MODEL_BOMB_P);
1164 }
1165 }
1166 }
1167
1168 return HAM_IGNORED;
1169}
1170
1171public ham_TakeDamage(victim, inflictor, attacker, Float:damage, damage_type)
1172{
1173 if (!is_user_connected(victim))
1174 return HAM_IGNORED;
1175
1176 if (cs_get_user_team(victim) == CS_TEAM_T && (damage_type & DMG_FALL))
1177 return HAM_SUPERCEDE;
1178
1179 return HAM_IGNORED;
1180}
1181
1182public ham_TraceAttack(victim, attacker)
1183{
1184 if (!is_user_connected(attacker) || victim == attacker)
1185 return HAM_IGNORED;
1186
1187 if (g_firstround)
1188 return HAM_SUPERCEDE;
1189
1190 return HAM_IGNORED;
1191}
1192
1193public grenade_explode(ent)
1194{
1195 static Float:originF[3], target, owner, Float:colors[3];
1196 entity_get_vector(ent, EV_VEC_origin, originF);
1197 target = -1;
1198 owner = entity_get_edict(ent, EV_ENT_owner);
1199 colors[0] = g_trap_color[owner][0];
1200 colors[1] = g_trap_color[owner][1];
1201 colors[2] = g_trap_color[owner][2];
1202
1203 engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, originF, 0);
1204 write_byte(TE_DLIGHT);
1205 engfunc(EngFunc_WriteCoord, originF[0]);
1206 engfunc(EngFunc_WriteCoord, originF[1]);
1207 engfunc(EngFunc_WriteCoord, originF[2]);
1208 write_byte(35);
1209 write_byte(floatround(g_trap_color[owner][0]));
1210 write_byte(floatround(g_trap_color[owner][1]));
1211 write_byte(floatround(g_trap_color[owner][2]));
1212 write_byte(50);
1213 write_byte(100);
1214 message_end();
1215
1216 engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, originF, 0);
1217 write_byte(TE_BEAMCYLINDER);
1218 engfunc(EngFunc_WriteCoord, originF[0]);
1219 engfunc(EngFunc_WriteCoord, originF[1]);
1220 engfunc(EngFunc_WriteCoord, originF[2]);
1221 engfunc(EngFunc_WriteCoord, originF[0]);
1222 engfunc(EngFunc_WriteCoord, originF[1]);
1223 engfunc(EngFunc_WriteCoord, originF[2] + 385.0);
1224 write_short(g_sprite[RING]);
1225 write_byte(0);
1226 write_byte(0);
1227 write_byte(5);
1228 write_byte(15);
1229 write_byte(0);
1230 write_byte(floatround(g_trap_color[owner][0]));
1231 write_byte(floatround(g_trap_color[owner][1]));
1232 write_byte(floatround(g_trap_color[owner][2]));
1233 write_byte(200);
1234 write_byte(0);
1235 message_end();
1236
1237 engfunc(EngFunc_MessageBegin, MSG_PVS, SVC_TEMPENTITY, originF, 0);
1238 write_byte(TE_IMPLOSION);
1239 engfunc(EngFunc_WriteCoord, originF[0]);
1240 engfunc(EngFunc_WriteCoord, originF[1]);
1241 engfunc(EngFunc_WriteCoord, originF[2]);
1242 write_byte(100);
1243 write_byte(100);
1244 write_byte(2);
1245 message_end();
1246
1247 emit_sound(ent, CHAN_AUTO, SOUND_GRENADE_DETECT_BREAKABLE, VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
1248
1249 while ((target = find_ent_in_sphere(target, originF, 300.0)) != 0)
1250 {
1251 static classname[32];
1252 entity_get_string(target, EV_SZ_classname, classname, charsmax(classname));
1253
1254 if (equal(classname, "func_breakable") || equal(classname, "func_door_rotating") || equal(classname, "func_door"))
1255 {
1256 if (entity_get_int(target, EV_INT_rendermode) > 1)
1257 continue;
1258
1259 if (!g_detect_trap[target])
1260 {
1261 g_detect_trap[target] = true;
1262 entity_set_int(target, EV_INT_renderfx, 0);
1263 entity_set_float(target, EV_FL_renderamt, 100.0);
1264 entity_set_vector(target, EV_VEC_rendercolor, colors);
1265 entity_set_int(target, EV_INT_rendermode, 1);
1266 set_task(7.5, "remove_breakable_effects", target);
1267 }
1268 }
1269 }
1270
1271 remove_entity(ent);
1272}
1273
1274public remove_breakable_effects(ent)
1275{
1276 g_detect_trap[ent] = false;
1277
1278 entity_set_int(ent, EV_INT_renderfx, 0);
1279 entity_set_float(ent, EV_FL_renderamt, 255.0);
1280 entity_set_vector(ent, EV_VEC_rendercolor, Float:{ 0.0, 0.0, 0.0 });
1281 entity_set_int(ent, EV_INT_rendermode, 0);
1282}
1283
1284
1285public fw_AddToFullPack_Post(es, e, ent, id, hostflag, player, player_set)
1286{
1287 if (player)
1288 {
1289 if (g_semiclip[ent] && g_semiclip[id])
1290 set_es(es, ES_Solid, SOLID_NOT);
1291
1292 if (g_option[id][PLAYER_INVISIBILITY])
1293 {
1294 if (cs_get_user_team(ent) == CS_TEAM_T)
1295 return FMRES_IGNORED;
1296
1297 set_es(es, ES_RenderMode, kRenderTransTexture);
1298 set_es(es, ES_RenderAmt, 7);
1299 }
1300 }
1301
1302 if (is_valid_ent(ent))
1303 {
1304 static classname[32];
1305 entity_get_string(ent, EV_SZ_classname, classname, charsmax(classname));
1306
1307 if (equali(classname, "func_water"))
1308 {
1309 if (g_option[id][WATER_INVISIBILITY])
1310 {
1311 set_es(es, ES_RenderMode, kRenderTransTexture);
1312 set_es(es, ES_RenderAmt, 10);
1313 }
1314 }
1315 }
1316
1317 return FMRES_IGNORED;
1318}
1319
1320public fw_SetClientKeyValue(id, const infobuffer[], const key[])
1321{
1322 if (key[0] == 'm' && key[1] == 'o' && key[2] == 'd' && key[3] == 'e' && key[4] == 'l')
1323 return FMRES_SUPERCEDE;
1324
1325 return FMRES_IGNORED;
1326}
1327
1328public fw_ClientUserInfoChanged(id, buffer)
1329{
1330 if (!is_user_connected(id))
1331 return FMRES_IGNORED;
1332
1333 static name[32];
1334 get_user_info(id, "name", name, 31); // Obtenemos la información del usuario, en este caso del nombre.
1335
1336 if (equal(g_user_name[id], name)) // Si el nombre que ingresó es igual al nombre que tiene, hacemos que la función continúe con normalidad.
1337 return FMRES_IGNORED; //
1338
1339 set_user_info(id, "name", g_user_name[id]); // Le ingresamos la información de la cadena del nombre que se almacenó en la variable al conectarse.
1340 //return FMRES_SUPERCEDE; // Detenemos el complemento.
1341
1342 if (cs_get_user_team(id) == CS_TEAM_T)
1343 {
1344 set_user_info(id, "model", MODEL_TERRORIST);
1345 return FMRES_SUPERCEDE;
1346 }
1347
1348 static mdl[32];
1349 get_user_model(id, mdl, charsmax(mdl));
1350
1351 if (!equal(mdl, g_playermodel[id]))
1352 set_user_info(id, "model", g_playermodel[id]);
1353
1354 return FMRES_IGNORED;
1355}
1356
1357
1358public fw_StartFrame()
1359{
1360 static id, id2, players[32], num, pl1, pl2;
1361 get_players(players, num, "ache", "CT");
1362
1363 arrayset(g_semiclip, 0, 32);
1364
1365 if (num <= 1)
1366 return FMRES_IGNORED;
1367
1368 for (id = 0; id < num; id++)
1369 {
1370 pl1 = players[id];
1371
1372 for (id2 = 0; id2 < num; id2++)
1373 {
1374 pl2 = players[id2];
1375
1376 if (pl1 == pl2)
1377 continue;
1378
1379 if (g_semiclip[pl1] && g_semiclip[pl2])
1380 continue;
1381
1382 if (entity_range(pl1, pl2) < 85)
1383 {
1384 g_semiclip[pl1] = true;
1385 g_semiclip[pl2] = true;
1386 }
1387 }
1388 }
1389
1390 for (id = 0; id < num; id++)
1391 entity_set_int(players[id], EV_INT_solid, (g_semiclip[players[id]]) ? SOLID_NOT : SOLID_SLIDEBOX);
1392
1393 return FMRES_IGNORED;
1394}
1395
1396public fw_ClientKill(id)
1397 return FMRES_SUPERCEDE;
1398
1399public fw_SetModel(ent, const model[])
1400{
1401 static classname[32];
1402 entity_get_string(ent, EV_SZ_classname, classname, charsmax(classname));
1403
1404 if (equal(classname, "weaponbox"))
1405 {
1406 entity_set_float(ent, EV_FL_nextthink, get_gametime() + 1.0);
1407 return FMRES_SUPERCEDE;
1408 }
1409
1410 if (entity_get_float(ent, EV_FL_dmgtime) == 0.0)
1411 return FMRES_IGNORED;
1412
1413 if (!equal(model[7], "w_sm", 4))
1414 return FMRES_IGNORED;
1415
1416 static owner;
1417 owner = entity_get_edict(ent, EV_ENT_owner);
1418
1419 if (g_grenade_showtraps[owner])
1420 {
1421 set_rendering(ent, kRenderFxGlowShell, floatround(g_trap_color[owner][0]), floatround(g_trap_color[owner][1]), floatround(g_trap_color[owner][2]), kRenderTransTexture, 17);
1422 entity_set_model(ent, MODEL_BOMB_W);
1423
1424 message_begin(MSG_BROADCAST, SVC_TEMPENTITY);
1425 write_byte(TE_BEAMFOLLOW);
1426 write_short(ent);
1427 write_short(g_sprite[LASERBEAM]);
1428 write_byte(10);
1429 write_byte(10);
1430 write_byte(floatround(g_trap_color[owner][0]));
1431 write_byte(floatround(g_trap_color[owner][1]));
1432 write_byte(floatround(g_trap_color[owner][2]));
1433 write_byte(200);
1434 message_end();
1435
1436 entity_set_model(ent, MODEL_BOMB_W);
1437 entity_set_int(ent, EV_INT_flTimeStepSound, GRENADE_SHOWTRAPS);
1438 return FMRES_SUPERCEDE;
1439 }
1440
1441 return FMRES_IGNORED;
1442}
1443
1444//MENUS
1445show_menu_register(id)
1446{
1447 static menu, sztext[128];
1448 menu = menu_create("\yMENÚ DE REGISTRO", "handled_show_menu_register");
1449
1450 if (!g_user_auto_logged[id]) // Si el usuario no está auto logueado, le mostramos el registro
1451 {
1452 menu_additem(menu, "REGISTRARSE", "1", _, menu_makecallback("menu_makecallback_register"));
1453 menu_additem(menu, "LOGUEARME", "2", _, menu_makecallback("menu_makecallback_login"));
1454 }
1455 else
1456 menu_additem(menu, "INGRESAR AL SERVIDOR", "1");
1457
1458
1459 if (g_user_register[id]) // Si el usuario está registrado le mostramos el número de #REGISTRO de su cuenta, la fecha de registro y el último ingreso.
1460 {
1461 format(sztext, 127, "^n\wCuenta número: \y#%d^n^n\wFecha de registro: \y%s^n\wÚltimo ingreso al servidor: \y%s",
1462 g_user_id[id], g_user_date_register[id], (g_user_last_date[id][0]) ? g_user_last_date[id] : "-");
1463 menu_addtext(menu, sztext);
1464 }
1465
1466 menu_setprop(menu, MPROP_EXIT, -1);
1467
1468 menu_display(id, menu, .page = 0);
1469}
1470
1471public menu_makecallback_register(id, menu, item)
1472 return (g_user_register[id]) ? ITEM_DISABLED : ITEM_ENABLED;
1473
1474public menu_makecallback_login(id, menu, item)
1475 return (g_user_register[id]) ? ITEM_ENABLED : ITEM_DISABLED;
1476
1477public handled_show_menu_register(id, menu, item)
1478{
1479 switch(item)
1480 {
1481 case MENU_EXIT:
1482 {
1483 menu_destroy(menu);
1484 return PLUGIN_HANDLED;
1485 }
1486 case 0:
1487 {
1488 if (g_user_auto_logged[id])
1489 {
1490 enter_user(id);
1491 return PLUGIN_HANDLED;
1492 }
1493
1494 client_cmd(id, "messagemode REGISTRAR_PASSWORD"), g_messagemode[id] = REGISTRAR_PASSWORD;
1495 }
1496 case 1: client_cmd(id, "messagemode INGRESAR_PASSWORD"), g_messagemode[id] = INGRESAR_PASSWORD;
1497 }
1498
1499 menu_destroy(menu);
1500 return PLUGIN_HANDLED;
1501}
1502
1503public clcmd_menu(id)
1504{
1505 if (cs_get_user_team(id) == CS_TEAM_UNASSIGNED || cs_get_user_team(id) == CS_TEAM_SPECTATOR)
1506 return PLUGIN_HANDLED;
1507
1508 static menu, sztext[128];
1509 format(sztext, charsmax(sztext), "\yDEATHRUN v%s^n\dBy ; Cristian'", PLUGIN_VERSION);
1510 menu = menu_create(sztext, "handled_clcmd_menu");
1511
1512 format(sztext, charsmax(sztext), "CT'S INVISIBLES: \d[\y%s\d]", (g_option[id][PLAYER_INVISIBILITY]) ? "ACTIVADO" : "DESACTIVADO");
1513 menu_additem(menu, sztext, "1", 0);
1514
1515 format(sztext, charsmax(sztext), "AGUA INVISIBLE: \d[\y%s\d]", (g_option[id][WATER_INVISIBILITY]) ? "ACTIVADO" : "DESACTIVADO");
1516 menu_additem(menu, sztext, "2", 0);
1517
1518 menu_additem(menu, "¿CUÁNTAS VIDAS TENGO?", "3", 0);
1519 menu_additem(menu, "\yREGLAS", "4", 0);
1520 menu_additem(menu, (g_camera[id]) ? "\yCÁMARA \r[3ra PERSONA]" : "\yCÁMARA \r[1era PERSONA]", "5", 0);
1521 menu_additem(menu, (is_user_alive(id) && is_player_stuck(id)) ? "\yESTOY BUGEADO" : "\dESTOY BUGEADO", "6");
1522
1523 if (is_user_admin(id))
1524 {
1525 menu_additem(menu, "COLOR DE LA BOMBA \d[TRAMPAS]", "7", 0);
1526 menu_additem(menu, "ADQUIRIR BOMBA \d[TRAMPAS]", "8", 0);
1527 menu_additem(menu, "ELEGIR MODELO DE PERSONAJE", "9", 0);
1528 menu_additem(menu, "MENÚ DE ADMIN", "10");
1529 }
1530
1531 menu_setprop(menu, MPROP_BACKNAME, "ATRÁS");
1532 menu_setprop(menu, MPROP_NEXTNAME, "SIGUIENTE");
1533 menu_setprop(menu, MPROP_EXITNAME, "SALIR");
1534
1535 set_pdata_int(id, OFFSET_CSMENUCODE, false, OFFSET_LINUX);
1536
1537 menu_display(id, menu);
1538 return PLUGIN_HANDLED;
1539}
1540
1541public handled_clcmd_menu(id, menu, item)
1542{
1543 switch(item)
1544 {
1545 case MENU_EXIT:
1546 {
1547 menu_destroy(menu);
1548 return PLUGIN_HANDLED;
1549 }
1550 case 0:
1551 {
1552 if (cs_get_user_team(id) == CS_TEAM_T)
1553 {
1554 menu_destroy(menu);
1555 return PLUGIN_HANDLED;
1556 }
1557
1558 g_option[id][PLAYER_INVISIBILITY] = !(g_option[id][PLAYER_INVISIBILITY]);
1559 chat_color(id, "%s !yAhora los CT's están %s.", SZPREFIX, (g_option[id][PLAYER_INVISIBILITY]) ? "invisibles" : "visibles");
1560 }
1561 case 1:
1562 {
1563 g_option[id][WATER_INVISIBILITY] = !(g_option[id][WATER_INVISIBILITY]);
1564 chat_color(id, "%s !yAhora el agua está %s.", SZPREFIX, (g_option[id][WATER_INVISIBILITY]) ? "invisible" : "visible");
1565 }
1566 case 2: clcmd_lifes(id);
1567 case 3: show_rules(id);
1568 case 4: clcmd_camera(id), clcmd_menu(id);
1569 case 5:
1570 {
1571 if (is_user_alive(id) && is_player_stuck(id))
1572 user_silentkill(id);
1573 }
1574 case 6: show_grenade_colors(id);
1575 case 7: client_cmd(id, "say /grenade");
1576 case 8: menu_model_admin(id);
1577 case 9: show_admin_menu(id);
1578 }
1579
1580 menu_destroy(menu);
1581 return PLUGIN_HANDLED;
1582}
1583
1584public menu_model_admin(id)
1585{
1586 static menu, i, sztext[128];
1587 menu = menu_create("ELEGIR MODELO DE PERSONAJE", "show_menu_model_admin");
1588
1589 for (i = 0; i < sizeof(ADMIN_MODEL); i++)
1590 {
1591 format(sztext, charsmax(sztext), "%s%s %s", (i == g_model[id]) ? "\d" : "\w", ADMIN_MODEL[i][MODEL_NAME],
1592 (i == g_model[id]) ? "\y[ACTUAL]" : "");
1593
1594 menu_additem(menu, sztext);
1595 }
1596
1597 menu_setprop(menu, MPROP_BACKNAME, "ATRÁS");
1598 menu_setprop(menu, MPROP_NEXTNAME, "SIGUIENTE");
1599 menu_setprop(menu, MPROP_EXITNAME, "VOLVER");
1600
1601 menu_display(id, menu);
1602}
1603
1604public show_menu_model_admin(id, menu, item)
1605{
1606 if (item == MENU_EXIT)
1607 {
1608 menu_destroy(menu);
1609 clcmd_menu(id);
1610 return;
1611 }
1612
1613 g_model[id] = item;
1614 copy(g_playermodel[id], charsmax(g_playermodel[]), ADMIN_MODEL[g_model[id]][MODEL_MODEL]);
1615 chat_color(id, "%s !yEn tu próxima reaparición tu modelo será: !g%s!y.", SZPREFIX, ADMIN_MODEL[g_model[id]][MODEL_NAME]);
1616 menu_destroy(menu);
1617 menu_model_admin(id);
1618}
1619
1620public show_admin_menu(id)
1621{
1622 static menu;
1623 menu = menu_create("\yMENÚ DE ADMIN", "handled_show_admin_menu");
1624
1625 menu_additem(menu, "REVIVIR A UN USUARIO", "1", 0);
1626 menu_additem(menu, (get_user_godmode(id)) ? "\dINMUNIDAD \y[ACTIVADO]" : "INMUNIDAD", "2", 0);
1627 menu_additem(menu, (get_user_noclip(id)) ? "\dNOCLIP \y[ACTIVADO]" : "NOCLIP", "3", 0);
1628 menu_additem(menu, "DAR VIDAS A UN USUARIO", "4", 0);
1629
1630 menu_setprop(menu, MPROP_EXITNAME, "VOLVER");
1631 menu_display(id, menu);
1632}
1633
1634public handled_show_admin_menu(id, menu, item)
1635{
1636 switch(item)
1637 {
1638 case MENU_EXIT:
1639 {
1640 menu_destroy(menu);
1641 return PLUGIN_HANDLED;
1642 }
1643 case 0: show_menu_revive(id);
1644 case 1:
1645 {
1646 set_user_godmode(id, (get_user_godmode(id)) ? 0 : 1);
1647 chat_color(id, "%s !yLa inmunidad ahora está %s.", SZPREFIX, (get_user_godmode(id)) ? "activada" : "desactivada");
1648 }
1649 case 2:
1650 {
1651 set_user_noclip(id, (get_user_noclip(id)) ? 0 : 1);
1652 chat_color(id, "%s !yEl noclip ahora está %s.", SZPREFIX, (get_user_noclip(id)) ? "activado" : "desactivado");
1653 }
1654 case 3: show_lifes_user(id);
1655 }
1656
1657 menu_destroy(menu);
1658 return PLUGIN_HANDLED;
1659}
1660
1661public show_menu_revive(id)
1662{
1663 static menu, name[32], i, num[7];
1664 menu = menu_create("\yREVIVIR A UN USUARIO", "handled_show_menu_revive");
1665
1666 for (i = 1; i <= g_maxplayers{0}; i++)
1667 {
1668 if (!is_user_connected(i) || is_user_alive(i))
1669 continue;
1670
1671 if (cs_get_user_team(i) == CS_TEAM_SPECTATOR || cs_get_user_team(i) == CS_TEAM_UNASSIGNED)
1672 continue;
1673
1674 get_user_name(i, name, charsmax(name));
1675 num_to_str(i, num, charsmax(num));
1676 menu_additem(menu, name, num);
1677 }
1678
1679 menu_setprop(menu, MPROP_BACKNAME, "ATRÁS");
1680 menu_setprop(menu, MPROP_NEXTNAME, "SIGUIENTE");
1681 menu_setprop(menu, MPROP_EXITNAME, "VOLVER");
1682
1683 menu_display(id, menu);
1684}
1685
1686public handled_show_menu_revive(id, menu, item)
1687{
1688 if (item == MENU_EXIT)
1689 {
1690 menu_destroy(menu);
1691 show_admin_menu(id);
1692 return;
1693 }
1694
1695 static access, num[7], target, name[32], name2[32];
1696 menu_item_getinfo(menu, item, access, num, charsmax(num), _, _, access);
1697
1698 target = str_to_num(num);
1699
1700 if (!is_user_alive(target))
1701 {
1702 get_user_name(id, name, charsmax(name));
1703 get_user_name(target, name2, charsmax(name2));
1704
1705 chat_color(0, "%s !g%s!y revivió a !g%s!y.", SZPREFIX, name, name2);
1706 ExecuteHamB(Ham_CS_RoundRespawn, target);
1707 }
1708 else
1709 chat_color(id, "%s !yEl usuario seleccionado se desconectó o está vivo.", SZPREFIX);
1710
1711 menu_destroy(menu);
1712 show_menu_revive(id);
1713}
1714
1715public show_lifes_user(id)
1716{
1717 static menu, name[32], i, num[7];
1718 menu = menu_create("\yDAR VIDAS A UN USUARIO", "handled_show_lifes_user");
1719
1720 for (i = 1; i <= g_maxplayers{0}; i++)
1721 {
1722 if (!is_user_connected(i))
1723 continue;
1724
1725 if (is_user_bot(i))
1726 continue;
1727
1728 if (cs_get_user_team(i) == CS_TEAM_SPECTATOR || cs_get_user_team(i) == CS_TEAM_UNASSIGNED)
1729 continue;
1730
1731 get_user_name(i, name, charsmax(name));
1732 num_to_str(i, num, charsmax(num));
1733 menu_additem(menu, name, num);
1734 }
1735
1736 menu_setprop(menu, MPROP_BACKNAME, "ATRÁS");
1737 menu_setprop(menu, MPROP_NEXTNAME, "SIGUIENTE");
1738 menu_setprop(menu, MPROP_EXITNAME, "VOLVER");
1739
1740 menu_display(id, menu);
1741}
1742
1743public handled_show_lifes_user(id, menu, item)
1744{
1745 if (item == MENU_EXIT)
1746 {
1747 menu_destroy(menu);
1748 clcmd_menu(id);
1749 return;
1750 }
1751
1752 static access, num[7], target, name[32];
1753 menu_item_getinfo(menu, item, access, num, charsmax(num), _, _, access);
1754
1755 target = str_to_num(num);
1756
1757 if (is_user_connected(id))
1758 {
1759 g_target[id] = target;
1760 get_user_name(id, name, charsmax(name));
1761 get_user_name(target, g_target_name[id], charsmax(g_target_name[]));
1762 client_cmd(id, "messagemode CANTIDAD_DE_VIDAS");
1763 }
1764 else
1765 chat_color(id, "%s !yEl usuario seleccionado se desconectó.", SZPREFIX);
1766
1767 menu_destroy(menu);
1768}
1769
1770public cantidad_de_vidas(id)
1771{
1772 if (!is_user_admin(id) || !g_target[id])
1773 return;
1774
1775 static amount[10], lifes, name[32];
1776 read_args(amount, charsmax(amount));
1777 remove_quotes(amount);
1778 trim(amount);
1779
1780 get_user_name(id, name, charsmax(name));
1781
1782 if (strlen(amount) < 1 || !isdigit(amount[0]))
1783 return;
1784
1785 lifes = str_to_num(amount);
1786
1787 if (!lifes)
1788 return;
1789
1790 g_life[g_target[id]] += lifes;
1791
1792 chat_color(id, "%s !yLe aumentaste !g%d!y vida%s a !g%s!y. Ahora tiene !g%d!y.", SZPREFIX, lifes,
1793 (lifes > 1) ? "s" : "", g_target_name[id], g_life[g_target[id]]);
1794 chat_color(g_target[id], "%s !g%s!y te aumentó !g%d!y vida%s.", SZPREFIX, name, lifes, (lifes > 1) ? "%s" : "");
1795}
1796
1797public clcmd_frags(id)
1798{
1799 chat_color(id, "%s !yFrags: !g%d!y | Muertes: !g%d!y.", SZPREFIX, g_frags[id], g_death[id]);
1800 return PLUGIN_HANDLED;
1801}
1802
1803public clcmd_changeteam(id)
1804{
1805 /* ========================= */
1806 // SI EL USUARIO ESTÁ LOGUEADO, HACEMOS QUE EL COMPLEMENTO DE LA FUNCIÓN DE ELECCIÓN DE EQUIPO CONTINÚE CON NORMALIDAD.
1807 if (g_user_logged[id])
1808 {
1809 clcmd_menu(id);
1810 return PLUGIN_HANDLED;
1811 }
1812 /* ========================= */
1813
1814 /* ========================= */
1815 /*
1816 * COMO HEMOS DICHO ANTERIORMENTE, SI EL USUARIO ESTABA LOGUEADO (VER ARRIBA) CONTINUAMOS EL VALOR DE LA FUNCIÓN CON NORMALIDAD.
1817 * SI NO LO ESTÁ, LE MOSTRAMOS EL REGISTRO Y DETENEMOS EL COMPLEMENTO DE DICHA FUNCIÓN.
1818 */
1819
1820 show_menu_register(id); // Función que tendrá el registro del usuario.
1821 return PLUGIN_HANDLED; // Detiene le complemento de la función.
1822}
1823
1824public clcmd_radio(id)
1825 return PLUGIN_HANDLED;
1826
1827public clcmd_drop(id)
1828{
1829 if (cs_get_user_team(id) == CS_TEAM_T)
1830 return PLUGIN_CONTINUE;
1831
1832 if (user_has_weapon(id, CSW_USP))
1833 return PLUGIN_HANDLED;
1834
1835 return PLUGIN_CONTINUE;
1836}
1837
1838public clcmd_connected(id)
1839{
1840 chat_color(id, "%s !yUsuarios conectados: !g%d!y. ", SZPREFIX, get_connected());
1841 return PLUGIN_HANDLED;
1842}
1843
1844public clcmd_camera(id)
1845{
1846 g_camera[id] = !(g_camera[id]);
1847
1848 set_view(id, (g_camera[id]) ? CAMERA_3RDPERSON : CAMERA_NONE);
1849 chat_color(id, "%s !yAhora tu cámara está en %s.", SZPREFIX, (g_camera[id]) ? "tercera persona" : "primera persona");
1850 return PLUGIN_HANDLED;
1851}
1852
1853public clcmd_say(id)
1854{
1855 static message[191], sztext[191], name[32];
1856 read_args(message, charsmax(message));
1857 remove_quotes(message);
1858 trim(message);
1859 get_user_name(id, name, charsmax(name));
1860
1861 replace_all(message, 190, "%", "");
1862 replace_all(message, 190, "!y", "");
1863 replace_all(message, 190, "!t", "");
1864 replace_all(message, 190, "!g", "");
1865
1866 if (equal(message, "/life") || equal(message, "/lifes") || equal(message, "/vida") || equal(message, "/vidas"))
1867 {
1868 clcmd_lifes(id);
1869 return PLUGIN_HANDLED;
1870 }
1871 else if (equal(message, "/free") || equal(message, "/libre"))
1872 {
1873 if (g_freeround[FR_STARTED])
1874 chat_color(id, "%s !yYa se está jugando la ronda libre.", SZPREFIX);
1875 else if (g_freeround[FR_ROUNDS] < (FREEROUND_ROUNDS - 1))
1876 chat_color(id, "%s !yLa ronda libre comenzará en !g%d rondas.", SZPREFIX, FREEROUND_ROUNDS - g_freeround[FR_ROUNDS]);
1877 else
1878 chat_color(id, "%s !yLa ronda libre comenzará en la próxima ronda.", SZPREFIX);
1879
1880 return PLUGIN_HANDLED;
1881 }
1882 else if (equal(message, "/grenade"))
1883 {
1884 if (cs_get_user_team(id) == CS_TEAM_T)
1885 return PLUGIN_HANDLED;
1886
1887 if (g_firstround || g_freeround[FR_STARTED])
1888 {
1889 chat_color(id, "%s !yNo podés usar esto ahora.", SZPREFIX);
1890 return PLUGIN_HANDLED;
1891 }
1892
1893 if (is_user_admin(id))
1894 {
1895 if (is_user_alive(id))
1896 {
1897 if (user_has_weapon(id, CSW_SMOKEGRENADE))
1898 {
1899 if (g_grenade_showtraps[id])
1900 {
1901 chat_color(id, "%s !yYa tenés una granada que detecta trampas.", SZPREFIX);
1902 return PLUGIN_HANDLED;
1903 }
1904 else
1905 {
1906 chat_color(id, "%s !yNo tenés que tener ninguna !gSG Grenade!y.", SZPREFIX);
1907 return PLUGIN_HANDLED;
1908 }
1909 }
1910
1911 if (g_grenade_time[id] > get_gametime())
1912 {
1913 chat_color(id, "%s !yTenés que esperar !g%d %s!y para usar esto.", SZPREFIX,
1914 floatround(g_grenade_time[id] - get_gametime()), (floatround(g_grenade_time[id]) - get_gametime() > 1) ? "segundos" : "segundos");
1915 return PLUGIN_HANDLED;
1916 }
1917
1918 g_grenade_time[id] = get_gametime() + 10.0;
1919
1920 g_grenade_showtraps[id] = true;
1921 give_item(id, "weapon_smokegrenade");
1922 chat_color(id, "%s !yAhora tenés una granada que detecta las trampas.", SZPREFIX);
1923 }
1924 else
1925 {
1926 chat_color(id, "%s !yTenés que estár vivo para adquirir una granada.", SZPREFIX);
1927 return PLUGIN_HANDLED;
1928 }
1929 }
1930
1931 return PLUGIN_HANDLED;
1932 }
1933 // else if (equal(message, "/noclip"))
1934 // {
1935 // static noclip;
1936 // noclip = !(noclip);
1937
1938 // set_user_noclip(id, noclip);
1939 // chat_color(id, "%s !yEl noclip está %s.", SZPREFIX, (noclip) ? "activado" : "desactivado");
1940 // return PLUGIN_HANDLED;
1941 // }
1942
1943 if (equal(message, "") || message[0] == '@' || message[0] == '!' || message[0] == '/')
1944 return PLUGIN_HANDLED;
1945
1946 format(sztext, charsmax(sztext), "!y%s!t%s !y: %s", (!is_user_alive(id)) ? "* MUERTO* " : "", name, message);
1947 chat_color(0, sztext);
1948
1949 return PLUGIN_HANDLED;
1950}
1951
1952public clcmd_lifes(id)
1953{
1954 if (g_life[id] > 0)
1955 chat_color(id, "%s !yTenés !g%d!y %s.", SZPREFIX, g_life[id], (g_life[id] == 1) ? "vida" : "vidas");
1956 else
1957 chat_color(id, "%s !yNo tenés vidas.", SZPREFIX);
1958
1959 return PLUGIN_HANDLED;
1960}
1961
1962public ShowHud(id)
1963{
1964 id -= 570
1965
1966 //if(is_user_connected(id)) Frags[id]++
1967
1968 if(g_user_logged[id])
1969 {
1970 //set_hudmessage(0, 85, 255, 0.15, 0.05, 0, 6.0, 12.0)
1971 set_hudmessage(85, 255, 212, 0.80, 0.12, 0, 6.0, 12.0)
1972 ShowSyncHudMsg(id, Hud, "Nivel: %d ^nExperiencia: %d/%d ^nMonedas: %d ^nRango: %s", g_nivel[id] , g_exp[id], NivelSiguente(g_nivel[id]), g_monedas[id], rangos[g_rango[id]])
1973 }
1974}
1975
1976public ver_nivel(id) {
1977 new subido = false
1978 while(g_exp[id] >= NivelSiguente(g_nivel[id]) && g_nivel[id] < NivelMax) {
1979 g_nivel[id]++
1980 subido = true;
1981 ver_rango(id)
1982 }
1983
1984 if(subido)
1985 {
1986 client_cmd(id, "spk ^"%s^"", sonido);
1987 chat_color(id, "Felicitaciones, subiste al nivel %d", g_nivel[id])
1988 //ver_rango(id)
1989 subido = false
1990 }
1991}
1992
1993public ver_rango(id)
1994{
1995 new Rsubido = false
1996 while(g_nivel[id] >= rangos[g_rango[id] + 1][rango_requerido])
1997 {
1998 g_rango[id]++
1999 Rsubido = true
2000 }
2001 if(Rsubido)
2002 {
2003 chat_color(id, "Felicitaciones, subiste al rango %s", rangos[g_rango[id]][rangos_nombre])
2004 Rsubido = false
2005 }
2006}
2007
2008public show_rules(id)
2009{
2010 static motd[1536], len;
2011 len = 0;
2012
2013 len += format(motd[len], charsmax(motd) - len,
2014 "<html><meta charset = 'UTF-8'><style>body {background: #040404} #b {size: 7}</style> \
2015 <center><font style = 'color: violet', style = 'size: 17'>Reglas del servidor [DEATHRUN]</center> \
2016 <br><font id = b>* Está prohibido dar un arma al terrorista, él debe agarrarla al matar al ct. \
2017 <br>* Está prohibido desconectarte si sos terrorista.<br>* El terrorista tiene la obligación de activar una trampa. \
2018 <br>* Está prohibido activar dos veces la misma trampa.");
2019
2020 len += format(motd[len], charsmax(motd) - len,
2021 "<br>* Si un usuario se cayó y es el último sobreviviente, éste se tiene que tirar<br>* Si un usuario ingresó al servidor tarde, tiene la obligación de tirarse\
2022 <br><br><center><font style = 'color: violet', style = 'size: 17'>¿Dudas o sugerencias? ¡No dudes en reportarlo en amxmodx-es.com!\
2023 </font></center></html>");
2024
2025 show_motd(id, motd);
2026 return PLUGIN_HANDLED;
2027}
2028
2029public show_grenade_colors(id)
2030{
2031 static menu, i, sztext[128], num[7];
2032 menu = menu_create("\yCOLOR DE BOMBA QUE DETECTA TRAMPAS", "handled_show_grenade_colors");
2033
2034 for (i = 0; i < sizeof(GRENADE_COLOR); i++)
2035 {
2036 num_to_str(i, num, charsmax(num));
2037 format(sztext, charsmax(sztext), "%s%s %s",
2038 (i == g_color_select[id]) ? "\d" : "\w", GRENADE_COLOR[i][COLOR_NAME], (i == g_color_select[id]) ? "\d[\ySELECCIONADO]" : "");
2039 menu_additem(menu, sztext, num);
2040 }
2041
2042 menu_setprop(menu, MPROP_BACKNAME, "ATRÁS");
2043 menu_setprop(menu, MPROP_NEXTNAME, "SIGUIENTE");
2044 menu_setprop(menu, MPROP_EXITNAME, "VOLVER");
2045
2046 menu_display(id, menu);
2047}
2048
2049public handled_show_grenade_colors(id, menu, item)
2050{
2051 if (item == MENU_EXIT)
2052 {
2053 menu_destroy(menu);
2054 clcmd_menu(id);
2055 return;
2056 }
2057
2058 g_color_select[id] = item;
2059 g_trap_color[id][0] = GRENADE_COLOR[item][RED];
2060 g_trap_color[id][1] = GRENADE_COLOR[item][GREEN];
2061 g_trap_color[id][2] = GRENADE_COLOR[item][BLUE];
2062
2063 menu_destroy(menu);
2064 show_grenade_colors(id);
2065}
2066
2067
2068public clcmd_imp201(id)
2069 return PLUGIN_HANDLED;
2070
2071public clcmd_messagemode(id)
2072{
2073 /* ================================================= */
2074 /*
2075 VERIFICAMOS QUE EL USUARIO ESTÉ LOGUEADO
2076 PARA EVITAR QUE PUEDA BUGUEAR LOS MESSAGEMODES
2077 (REGISTRARSE / LOGUEARSE) A TRAVÉS DE CONSOLA.
2078 EN CASO DE ESTARLO, DETENEMOS EL COMPLEMENTO
2079 DE LA FUNCIÓN.
2080 */
2081 /* ================================================= */
2082
2083 if (g_user_logged[id])
2084 return PLUGIN_HANDLED;
2085
2086 static args[28];
2087 read_args(args, 27); // Obtenemos la cadena que puso en consola.
2088 remove_quotes(args); // Removemos las comillas "".
2089 trim(args); // Eliminamos los espacios en blanco del principio a final de la cadena.
2090
2091 switch(g_messagemode[id])
2092 {
2093 case REGISTRAR_PASSWORD:
2094 {
2095 // Verificamos que el usuario esté registrado para detener el complemento de la función.
2096 if (g_user_register[id])
2097 return PLUGIN_HANDLED;
2098
2099 // Calculamos la longitud de la cadena introducda, en este caso si la cadena posee menos de 4 dígitos
2100 // detenemos el complemento.
2101 if (strlen(args) < 4)
2102 {
2103 client_print(id, print_center, "LA CONTRASEÑA DEBE CONTENER MÁS DE 4 DÍGITOS");
2104 return PLUGIN_HANDLED;
2105 }
2106
2107 // Si puso más de 4 dígitos, hacemos que confirme su contraseña.
2108 g_messagemode[id] = CONFIRMAR_PASSWORD;
2109 client_cmd(id, "messagemode CONFIRMAR_PASSWORD");
2110 copy(g_user_password[id], 31, args);
2111 }
2112 case CONFIRMAR_PASSWORD:
2113 {
2114 // Verificamos que el usuario esté registrado para detener el complemento de la función.
2115 if (g_user_register[id])
2116 return PLUGIN_HANDLED;
2117
2118 // Verificamos si la contraseña que introdujo sea igual a la que puso al REGISTRAR_PASSWORD.
2119 // Si no es igual, detenemos el complemento de la función.
2120 if (!equali(g_user_password[id], args))
2121 {
2122 client_print(id, print_center, "La contraseña introducia no coincide");
2123 return PLUGIN_HANDLED;
2124 }
2125
2126 // Si no se detuvo el complemento anteriormente (LA CONTRASEÑA ES IGUAL), insertamos sus datos en la base de datos.
2127
2128 /*
2129 * INSERT INTO: Se utiliza para insertar un nuevo registro en la tabla.
2130 * Quedaría de esta manera la lógica: INSERTAR EN 'tabla' (columna1, column2, column3) VALORES (valor1, valor2, valor3);
2131 */
2132
2133 // Preparamos la consulta, que contendrá el nombre, la contraseña, y la fecha de registro
2134 new Handle:query, time[32];
2135 get_time("%d/%m/%Y - %H:%M:%S", time, 31); // Obtenemos la fecha %days/%month/%year - %hour:%minutes/%seconds
2136
2137 query = SQL_PrepareQuery(g_sql_connection, "INSERT INTO '%s' (name, password, date_register) VALUES (^"%s^", ^"%s^", ^"%s^")",
2138 SQL_TABLE, g_user_name[id], g_user_password[id], time);
2139
2140 // Ejecutamos la consulta que anteriormente preparamos (SQL_PrepareQuery).
2141
2142 if (!SQL_Execute(query)) // Si la consulta ejecutada no es válida.
2143 {
2144 sql_query_error(id, query);
2145 SQL_FreeHandle(query); // Liberamos el identificador de la consulta.
2146 }
2147 else // Si es válida
2148 {
2149 SQL_FreeHandle(query); // Liberamos el identificador de la consulta para realizar otra.
2150
2151 // Preparamos la consulta para seleccionar el ID del usuario.
2152 query = SQL_PrepareQuery(g_sql_connection, "SELECT id FROM '%s' WHERE name = ^"%s^"", SQL_TABLE, g_user_name[id]);
2153
2154 if (!SQL_Execute(query)) // Si la consulta no es válida.
2155 {
2156 sql_query_error(id, query);
2157 SQL_FreeHandle(query); // Liberamos el identificador de la consulta.
2158 }
2159 else if (SQL_NumResults(query)) // Si la consulta arroja resultados
2160 {
2161 // Obtenemos en la variable g_user_id el #ID del usuario para que se autoincremente
2162 // y no se buguee al guardar sus datos ya que estamos guardando sus datos por el #ID
2163 // y por defecto la variable del #ID del usuario es 0.
2164
2165 g_user_id[id] = SQL_ReadResult(query, 0);
2166
2167 g_user_register[id] = 1; // Si el usuario se registró con éxito, ponemos que está registrado.
2168 g_user_logged[id] = 1; // Si el usuario se registró con éxito, ponemos que está logueado.
2169
2170 chat_color(id, "%s !yBienvenido !t%s!y, sos la cuenta registrada número !g#%d!y.", SZPREFIX, g_user_name[id], g_user_id[id]);
2171 SQL_FreeHandle(query); // Liberamos el identificador de la consulta.
2172 }
2173 else
2174 SQL_FreeHandle(query); // Liberamos el identificador de la consulta.
2175 }
2176 engclient_cmd(id, "jointeam", "2");
2177 engclient_cmd(id, "joinclass", "5");
2178 }
2179 case INGRESAR_PASSWORD:
2180 {
2181 // Verificamos que el usuario no esté registrado para detener el complemento de la función.
2182 if (!g_user_register[id])
2183 return PLUGIN_HANDLED;
2184
2185 // Si la contraseña que puso no es igual a la contraseña cargada, detenemos el complemento
2186 if (!equali(g_user_password[id], args))
2187 {
2188 chat_color(id, "%s !yTu contraseña no coincide.", SZPREFIX);
2189 return PLUGIN_HANDLED;
2190 }
2191 engclient_cmd(id, "jointeam", "2");
2192 engclient_cmd(id, "joinclass", "5");
2193 enter_user(id); // Función que lo hará ingresar al servidor.
2194 }
2195 }
2196
2197
2198 //client_cmd(id, "chooseteam");
2199 return PLUGIN_HANDLED;
2200}
2201
2202public message_statusicon(msgid, dest, id)
2203{
2204 static icon[8];
2205 get_msg_arg_string(2, icon, charsmax(icon));
2206
2207 if (equal(icon, "buyzone") && get_msg_arg_int(1))
2208 {
2209 set_pdata_int(id, OFFSET_BUYZONE, (get_pdata_int(id, OFFSET_BUYZONE)) & ~(1<<0));
2210 return PLUGIN_HANDLED;
2211 }
2212
2213 return PLUGIN_CONTINUE;
2214}
2215
2216public message_textmsg()
2217{
2218 static sztext[28];
2219 get_msg_arg_string(2, sztext, charsmax(sztext));
2220
2221 if (equal(sztext, "#Terrorists_Win"))
2222 {
2223 if (get_connected() > 2)
2224 {
2225 static id;
2226
2227 for (id = 1; id <= g_maxplayers{0}; id++)
2228 {
2229 if (is_user_bot(id))
2230 continue;
2231
2232 if (is_user_alive(id) && cs_get_user_team(id) == CS_TEAM_T)
2233 {
2234 g_life[id]++;
2235 chat_color(id, "%s !yGanaste una vida por ganar la ronda siendo terrorista.", SZPREFIX);
2236 set_user_frags(id, get_user_frags(id) + 1);
2237 }
2238 }
2239 }
2240
2241 client_print(0, print_center, "¡ GANÓ EL TERRORISTA ! ");
2242 return PLUGIN_HANDLED;
2243 }
2244
2245 if (equal(sztext, "#CTs_Win"))
2246 {
2247 client_print(0, print_center, "¡ GANARON LOS CTS !");
2248 return PLUGIN_HANDLED;
2249 }
2250
2251 if (equal(sztext, "#Game_Commencing"))
2252 {
2253 client_print(0, print_center, "COMENZANDO DEATHRUN...");
2254
2255 if (g_firstround && !g_game_commencing)
2256 g_game_commencing = true;
2257
2258 return PLUGIN_HANDLED;
2259 }
2260
2261 if (g_message_start)
2262 {
2263 if (equal(sztext, "#Game_will_restart_in"))
2264 {
2265 set_hudmessage(0, 255, 0, -1.0, 0.17, 1, 0.0, 3.0, 2.0, 1.0, -1);
2266 ShowSyncHudMsg(0, g_synchud[MESSAGE], "¡ COMENZÓ EL DEATHRUN !", g_dr_time);
2267 return PLUGIN_HANDLED;
2268 }
2269
2270 g_message_start = false;
2271 }
2272
2273
2274
2275 return PLUGIN_CONTINUE;
2276}
2277
2278public message_showmenu(msgid, dest, id)
2279{
2280 static message[21];
2281 get_msg_arg_string(4, message, charsmax(message));
2282
2283 if (containi(message, "Team_Select") != -1)
2284 return PLUGIN_HANDLED;
2285
2286 return PLUGIN_CONTINUE;
2287}
2288
2289public message_vguimenu(msgid, dest, id)
2290{
2291 if (get_msg_arg_int(1) != OFFSET_VGUIMENU)
2292 return PLUGIN_CONTINUE;
2293
2294 return PLUGIN_HANDLED;
2295}
2296
2297get_connected()
2298{
2299 static connected, id;
2300 connected = 0;
2301
2302 for (id = 1; id <= g_maxplayers{0}; id++)
2303 {
2304 if (!is_user_connected(id))
2305 continue;
2306
2307 if (is_user_bot(id))
2308 continue;
2309
2310 if (cs_get_user_team(id) == CS_TEAM_CT || cs_get_user_team(id) == CS_TEAM_T)
2311 connected++;
2312 }
2313
2314 return connected;
2315}
2316
2317get_administration()
2318{
2319 static id, admin;
2320 admin = 0;
2321
2322 for (id = 1; id <= g_maxplayers{0}; id++)
2323 {
2324 if (is_user_admin(id))
2325 id++;
2326 }
2327
2328 return admin;
2329}
2330
2331random_player(const num)
2332{
2333 static alive, id;
2334 alive = 0;
2335
2336 for (id = 1; id <= g_maxplayers{0}; id++)
2337 {
2338 if (!is_user_connected(id) || is_user_bot(id))
2339 continue;
2340
2341 if (cs_get_user_team(id) == CS_TEAM_CT)
2342 alive++;
2343
2344 if (alive == num)
2345 return id;
2346 }
2347
2348 return -1;
2349}
2350
2351get_tts()
2352{
2353 static tts, id;
2354 tts = 0;
2355
2356 for (id = 1; id <= g_maxplayers{0}; id++)
2357 {
2358 if (is_user_bot(id))
2359 continue;
2360
2361 if (is_user_connected(id) && cs_get_user_team(id) == CS_TEAM_T)
2362 tts++;
2363 }
2364
2365 return tts;
2366}
2367
2368get_cts()
2369{
2370 static cts, id;
2371 cts = 0;
2372
2373 for (id = 1; id <= g_maxplayers{0}; id++)
2374 {
2375 if (is_user_connected(id) && cs_get_user_team(id) == CS_TEAM_CT)
2376 cts++;
2377 }
2378
2379 return cts;
2380}
2381
2382
2383get_cts_alive()
2384{
2385 static ct_alive, id;
2386 ct_alive = 0;
2387
2388 for (id = 1; id <= g_maxplayers{0}; id++)
2389 {
2390 if (is_user_alive(id) && cs_get_user_team(id) == CS_TEAM_CT)
2391 ct_alive++;
2392 }
2393
2394 return ct_alive;
2395}
2396
2397// stock p(id, error, const input[], any:...) {
2398 // static msg[2][256], len;
2399 // len = formatex(msg[0], 255, "");
2400
2401 // vformat(msg[0][len], 255, input, 4);
2402 // msg[0][255] = '^0';
2403
2404 // formatex(msg[1], 255, "%s%s%s", g_const_print[error], msg[0], error < PRINT_PERSONAL ? "!y." : "");
2405
2406 // replace_all(msg[1], 254, "!g", "^4");
2407 // replace_all(msg[1], 254, "!y", "^1");
2408 // replace_all(msg[1], 254, "!t", "^3");
2409
2410 // if (id) {
2411 // if (!g_player[id][CONNECTED])
2412 // return;
2413
2414 // message_begin(MSG_ONE_UNRELIABLE, g_mode[MSG_SAYTEXT], _, id);
2415 // write_byte(id);
2416 // write_string(msg[1]);
2417 // message_end();
2418
2419 // if (error == PRINT_ERROR)
2420 // client_cmd(id, "spk ^"%s^"", SOUND_ERROR);
2421
2422 // return;
2423 // }
2424
2425 // for (id = 1; id <= MAX_SLOTS; id++) {
2426 // if (!g_player[id][CONNECTED])
2427 // continue;
2428
2429 // message_begin(MSG_ONE_UNRELIABLE, g_mode[MSG_SAYTEXT], _, id);
2430 // write_byte(id);
2431 // write_string(msg[1]);
2432 // message_end();
2433 // }
2434// }
2435
2436enter_user(id)
2437{
2438 // Preparamos la consulta.
2439 new Handle:query, ip[21], time[32];
2440
2441 get_time("%d/%m/%Y - %H:%M:%S", time, 31); // Obtenemos la fecha %days/%month/%year - %hour:%minutes/%seconds
2442 get_user_ip(id, ip, 21, 1); // Obtenemos la ip del usuario
2443
2444 // Preparamos la consulta para guardar su ip y la fecha de ingreso.
2445 query = SQL_PrepareQuery(g_sql_connection, "UPDATE '%s' SET last_date = ^"%s^", ip = ^"%s^" WHERE id = '%d';", SQL_TABLE, time, ip, g_user_id[id]);
2446
2447 if (!SQL_Execute(query)) // Si la consulta no es válida.
2448 {
2449 sql_query_error(id, query);
2450 SQL_FreeHandle(query); // Liberamos el identificador de la consulta.
2451 }
2452 else // Si es válida, liberamos el identificador de la consulta.
2453 SQL_FreeHandle(query);
2454
2455 g_user_logged[id] = 1; // Si el usuario puso su contraseña correctamente, ponemos que está logueado y le cargamos sus datos.
2456 chat_color(id, "%s !yBienvenido !g%s!y.", SZPREFIX, g_user_name[id]);
2457 load_data(id); // Llamamos a la función que ejecutará la consulta y cargará sus datos.
2458
2459 //client_cmd(id, "chooseteam");
2460 engclient_cmd(id, "jointeam", "2");
2461 engclient_cmd(id, "joinclass", "5");
2462 return PLUGIN_CONTINUE;
2463}
2464
2465save_data(id)
2466{
2467 /*
2468 * UTILIZAMOS ThreadQuery PARA GUARDAR SUS DATOS
2469 * YA QUE PrepareQuery CORRE CON EL MISMO PROCESO
2470 * DEL SERVIDOR Y PUEDE GENERAR QUE SE CONGELE.
2471 */
2472
2473
2474 /*
2475 * PREPARAMOS LA CONSULTA, UTILIZAMOS LA TUPLA QUE NOS DEVOLVIÓ SQL_MakeDbTuple().
2476 SQL_ThreadQuery(Handle:Tupla, "función", "consulta", index);
2477 */
2478
2479
2480 static save[128], data[2];
2481 data[0] = id;
2482 data[1] = 1;
2483
2484 /*
2485 * Lógica de la consulta: ACTUALIZAR 'mi_tabla' CONJUNTO frags = '%d', deaths = '%d' DONDE id = '%d';
2486 * El ";" es utilizado para separar consultas.
2487
2488 */
2489
2490 formatex(save, charsmax(save), "UPDATE '%s' SET nivel = '%d', experiencia = '%d', monedas = '%d', rango = ^"%s^", frags = '%d', deaths = '%d' WHERE id = '%d';", SQL_TABLE, g_nivel[id], g_exp[id], g_monedas[id], rangos[g_rango[id]], g_frags[id], g_death[id], g_user_id[id]);
2491 SQL_ThreadQuery(g_sql_htuple, "SQL_DataHandled", save, data, 2);
2492}
2493
2494
2495public SQL_DataHandled(failstate, Handle:query, error[], errnum, data[], size, Float:queutime)
2496{
2497 /*
2498 * failstate: Una de las 3 consultas lo define.
2499 - TQUERY_CONNECT_FAILED.
2500 - TQUERY_QUERY_FAILED.
2501 - TQUERY_SUCCESS.
2502
2503 * Handle:query: Maneja la consulta, no debe ser liberada.
2504 * const error[]: Devuelve un mensaje de error si es que lo hay.
2505 * errnum: Devuelve un código de error si es lo que hay.
2506 * const data[]: matriz de datos ingresados.
2507 * size: tamaño de la matriz ingresada,
2508 * queutime: El tiempo que pasó mientras la consulta era ejecutada.
2509 */
2510
2511
2512 if (failstate == TQUERY_CONNECT_FAILED || failstate == TQUERY_QUERY_FAILED)
2513 {
2514 sql_query_error(data[0], query);
2515 return PLUGIN_HANDLED;
2516 }
2517
2518 if (data[1])
2519 {
2520 if (failstate != TQUERY_SUCCESS) // Si el failstate no es igual 0 (TQUERY_SUCCESS) detenemos el complemento.
2521 return PLUGIN_HANDLED;
2522
2523 chat_color(data[0], "%s !yTus datos fueron almacenados.", SZPREFIX);
2524 }
2525
2526 return PLUGIN_HANDLED;
2527}
2528
2529load_data(id)
2530{
2531 /*
2532 * Lógica de la consulta: SELECCIONAR * (TODO) DE 'tabla' DONDE id = 'mi_id';
2533 * El ";" es utilizado para separar las consultas.
2534
2535 */
2536
2537 // Preparamos la consulta y cargamos sus datos por el ID del usuario
2538 new Handle:query;
2539 query = SQL_PrepareQuery(g_sql_connection, "SELECT * FROM '%s' WHERE id = '%d';", SQL_TABLE, g_user_id[id]);
2540
2541 // Ejecutamos la consulta que anteriormente preparamos (SQL_PrepareQuery).
2542 if (!SQL_Execute(query)) // Si la consulta no es válida
2543 {
2544 SQL_FreeHandle(query); // Liberamos el identificador de la consulta.
2545 sql_query_error(id, query);
2546 }
2547 else if (SQL_NumResults(query)) // Si la consulta arroja resultados
2548 {
2549 /*
2550 NOTA: Al seleccionar todos los datos (*), si solamente queremos obtener los frags y muertes del usuario.
2551 deberíamos tener en cuenta las columnas anteriores, Un pequeño ejemplo numérico de nuestra tabla:
2552
2553 ID = 0,
2554 NOMBRE = 1
2555 PASSWORD = 2
2556 DATE_REGISTER = 3
2557 LAST_DATE = 4
2558 IP = 5
2559 FRAGS = 6
2560 DEATHS = 7
2561 */
2562
2563 // Cargamos sus datos
2564 g_frags[id] = SQL_ReadResult(query, 6); // Recuperamos en la variable g_frags el resultado actual de la columna Nº 6.
2565 g_death[id] = SQL_ReadResult(query, 7); // Recuperamos en la variable g_death el resultado actual de la columna Nº 7.
2566 g_nivel[id] = SQL_ReadResult(query, 8);
2567 g_exp[id] = SQL_ReadResult(query, 9);
2568 g_monedas[id] = SQL_ReadResult(query, 10);
2569 g_rango[id] = SQL_ReadResult(query, 11);
2570
2571 SQL_FreeHandle(query); // Liberamos el identificador de la consulta.
2572 }
2573 else // Si no arroja resultados, liberamos el identificador de la consulta.
2574 SQL_FreeHandle(query);
2575}
2576
2577sql_query_error(id, Handle:query)
2578{
2579 static error[56];
2580 SQL_QueryError(query, error, 55); // Obtenemos la información de la consulta errónea.
2581
2582 chat_color(id, "%s !yError: !g%s!y.", SZPREFIX, error); // Le mandamos al usuario el mensaje con la consulta errónea.
2583 SQL_FreeHandle(query); // Liberamos el identificador de la consulta.
2584}
2585
2586sqlx_init()
2587{
2588 new error, errorcode[128];
2589
2590 // Si el módulo sqlite no está cargado, detenemos el complemento.
2591 if (!module_exists("sqlite"))
2592 {
2593 log_to_file("SQL_Module.txt", "El módulo ^"sqlite^" es necesario.", SZPREFIX);
2594 return PLUGIN_HANDLED;
2595 }
2596
2597 /* SQL_MakeDbTuple
2598 (
2599 "", | Base de datos host.
2600 "", | Usuario de la base de datos.
2601 "", | Contraseña de la base de datos.
2602 SQL_DATABASE, | Nombre de la base de datos.
2603 TIMEOUT | Tiempo de espera de la conexión antes de cerrarse.
2604 );
2605
2606 */
2607 g_sql_htuple = SQL_MakeDbTuple("", "", "", SQL_DATABASE, .timeout = 0); // Creamos una tupla de información de conexión.
2608
2609
2610 /* SQL_Connect
2611 (
2612 Handle:tupla, | INFORMACIÓN DE CONEXIÓN DEVUELTA POR SQL_MakeDbTuple
2613 error, | Cadena donde se almacenará la cadena error.
2614 errorcode, | Código del error.
2615 127, | Longitud de la cadena.
2616 )
2617 */
2618 g_sql_connection = SQL_Connect(g_sql_htuple, error, errorcode, 127); // Abrimos una conexión con la base de datos.
2619
2620 if (g_sql_htuple == Empty_Handle)
2621 {
2622 log_to_file("SQL_Htuple.txt", "Error en la tupla");
2623 return PLUGIN_HANDLED;
2624 }
2625
2626 if (g_sql_connection == Empty_Handle)
2627 {
2628 log_to_file("SQL_Connection.txt", "Error al conectar base de datos %s (%s)", error, errorcode);
2629 return PLUGIN_HANDLED;
2630 }
2631
2632 /*
2633 Preparamos la consulta que creará nuestra tabla (No es recomendable hacerlo dentro del plugin, para eso existen varios programas).
2634
2635 * INTEGER: Permite números enteros.
2636 * PRIMARY KEY: Identifica de forma única cada registro en una tabla de base de datos.
2637 * AUTOINCREMENT: Permite que se genere automáticamente un número cuando se inserta un registro, en este caso se genera el campo #ID.
2638 * UNIQUE: Asegura que todos los valores de una columna sean diferentes, al igual que la restricción PRIMARY KEY, en este caso el NOMBRE.
2639 * VARCHAR: Permite una cadena de carácteres.
2640 */
2641
2642 new Handle:query;
2643 query = SQL_PrepareQuery
2644 (
2645 g_sql_connection,
2646 "CREATE TABLE IF NOT EXISTS '%s' \
2647 ( \
2648 id INTEGER PRIMARY KEY AUTOINCREMENT, \
2649 name VARCHAR(32) NOT NULL UNIQUE, \
2650 password VARCHAR(32) NOT NULL, \
2651 date_register VARCHAR(32) NOT NULL DEFAULT '', \
2652 last_date VARCHAR(32) NOT NULL NOT NULL DEFAULT '', \
2653 ip VARCHAR(21) NOT NULL DEFAULT '', \
2654 frags INTEGER NOT NULL DEFAULT '0', \
2655 deaths INTEGER NOT NULL DEFAULT '0', \
2656 nivel INTEGER DEFAULT '0', \
2657 experiencia INTEGER DEFAULT '0', \
2658 monedas INTEGER DEFAULT '0', \
2659 rangos INTEGER DEFAULT '0' \
2660 )", SQL_TABLE
2661 );
2662
2663 if (!SQL_Execute(query))
2664 {
2665 sql_query_error(0, query);
2666 SQL_FreeHandle(query);
2667 }
2668 else
2669 SQL_FreeHandle(query);
2670
2671 return PLUGIN_HANDLED;
2672}
2673
2674
2675stock get_user_model(id, model[], len)
2676 get_user_info(id, "model", model, len);
2677
2678stock is_player_stuck(id)
2679{
2680 static Float:originF[3];
2681 entity_get_vector(id, EV_VEC_origin, originF);
2682
2683 engfunc(EngFunc_TraceHull, originF, originF, 0, (entity_get_int(id, EV_INT_flags) & FL_DUCKING) ? HULL_HEAD : HULL_HUMAN, id, 0);
2684
2685 if (get_tr2(0, TR_StartSolid) || get_tr2(0, TR_AllSolid) || !get_tr2(0, TR_InOpen))
2686 return true;
2687
2688 return false;
2689}
2690
2691stock chat_color(id, const input[], any:...)
2692{
2693 static message[191];
2694 vformat(message, 190, input, 3);
2695
2696 replace_all(message, 190, "!g", "^4");
2697 replace_all(message, 190, "!t", "^3");
2698 replace_all(message, 190, "!y", "^1");
2699
2700 if (id)
2701 {
2702 if (!is_user_connected(id))
2703 return;
2704
2705 message_begin(MSG_ONE_UNRELIABLE, g_message[SAYTEXT], .player = id);
2706 write_byte(id);
2707 write_string(message);
2708 message_end();
2709 return;
2710 }
2711
2712 for (id = 1; id <= g_maxplayers{0}; id++)
2713 {
2714 if (!is_user_connected(id))
2715 continue;
2716
2717 if (cs_get_user_team(id) == CS_TEAM_UNASSIGNED || cs_get_user_team(id) == CS_TEAM_SPECTATOR)
2718 continue;
2719
2720 message_begin(MSG_ONE_UNRELIABLE, g_message[SAYTEXT], .player = id);
2721 write_byte(id);
2722 write_string(message);
2723 message_end();
2724 }
2725}
2726
2727public plugin_end()
2728{
2729 SQL_FreeHandle(g_sql_connection); // Liberamos la conexión.
2730 SQL_FreeHandle(g_sql_htuple); // Liberamos la información obtenida.
2731
2732 TrieDestroy(g_button);
2733}