· 6 years ago · Dec 19, 2019, 05:58 AM
1#include <amxmodx>
2#include <hamsandwich>
3#include <fakemeta>
4#include <fun>
5#include <sqlx>
6#include <dhudmessage>
7#include <engine>
8
9#define LevelNext(%1) (%1 * 25)
10#define NivelMax 10
11#define SQLX_DATABASE "dataknifemod"
12
13const USER_NO_REGISTRADO = -1;
14const USER_REGISTRADO = 0;
15const USER_LOGEADO = 1;
16const TASK_KICK = 987654;
17
18new g_logeado[33], g_playername[33][32];
19new Handle:g_query, Handle:g_tuple, g_iMsgVguiMenu, g_iMsgShowMenu;
20new gNivel[33], gExp[33], gResets[33], gKnife[33], gHud[33];
21
22enum _:KNIFE_DATA { KNIFE_NAME[30], V_MODEL[50], P_MODEL[50], LVL, RR, Float:DMG }
23new const Knifes[][KNIFE_DATA] = {
24 { "Cuchillo normal", "models/v_knife.mdl", "models/p_knife.mdl", 1, 0, 1.0 },
25 { "Fidget Spinner", "models/knife_mod/v_fidget_spinner.mdl", "models/p_knife.mdl", 2, 0, 2.0 },
26 { "Cuchillo poderoso", "models/v_knife.mdl", "models/p_knife.mdl", 3, 1, 3.0 }
27}
28new Ham:Ham_Player_ResetMaxSpeed = Ham_Item_PreFrame;
29new gPuntos[33], Armadura[33], Float:Gravedad[33], Float:Speed[33]
30new gHabilidades[33][3];
31public plugin_precache() {
32 for(new i = 1; i < sizeof Knifes; ++i) {
33 precache_model(Knifes[i][V_MODEL]);
34 precache_model(Knifes[i][P_MODEL]);
35 }
36}
37public plugin_init() {
38 register_plugin("Knife Mod", "2.0", "Kross");
39
40 /* CLCMD */
41 register_clcmd("REGISTRE_SU_PASSWORD", "REGISTRE_SU_PASSWORD")
42 register_clcmd("INGRESA_TU_PASSWORD", "INGRESA_TU_PASSWORD")
43 register_clcmd("say /knife", "ShowMenuKnifes");
44 register_clcmd("say /cuchillo", "ShowMenuKnifes");
45 register_clcmd("say /level", "Info");
46 register_clcmd("say /nivel", "Info");
47 register_clcmd("say /menu", "clcmd_changeteam")
48 register_clcmd("chooseteam", "clcmd_changeteam")
49 register_clcmd("jointeam", "clcmd_changeteam")
50 register_clcmd("jointeam 1", "clcmd_changeteam")
51 register_clcmd("jointeam 2", "clcmd_changeteam")
52 register_clcmd("jointeam 6", "clcmd_changeteam")
53
54 /* FORWARDS */
55 register_forward(FM_ClientUserInfoChanged, "fwClientInfoChanged");
56 register_forward(FM_GetGameDescription, "FwdGameDesc" )
57
58 /* HAMS */
59 RegisterHam(Ham_Spawn, "player", "HamSpawn", true);
60 RegisterHam(Ham_Killed, "player", "hamPlayerKilled", true);
61 RegisterHam(Ham_Item_Deploy, "weapon_knife", "ham_KnifeDeployPost", true);
62 RegisterHam(Ham_TakeDamage, "player", "FwdTakeDamage", 0);
63 RegisterHam(Ham_Player_ResetMaxSpeed, "player", "fw_ResetMaxSpeed_Post", 1),
64
65 /* MESSAGE */
66 register_message(get_user_msgid("StatusIcon"), "message_statusicon")
67 g_iMsgVguiMenu = get_user_msgid("VGUIMenu");
68 g_iMsgShowMenu = get_user_msgid("ShowMenu");
69
70 register_message(g_iMsgVguiMenu, "message_VGUImenu");
71 register_message(g_iMsgShowMenu, "message_VGUImenu");
72 set_lights("e")
73
74 SQLXInit()
75}
76public client_putinserver(id) {
77 get_user_name(id, g_playername[id], charsmax(g_playername[]))
78 set_task(0.1, "ShowHUD", id, _, _, "b")
79 if(!is_user_bot(id)) { set_task(50.0, "taskKickPlayer", id + TASK_KICK); }
80
81 g_logeado[id] = USER_NO_REGISTRADO
82 g_query = SQL_PrepareQuery(g_tuple, "SELECT Nombre FROM 'Cuentas' WHERE Nombre = ^"%s^"", g_playername[id]);
83
84 if (SQL_Execute(g_query)) {
85 if (SQL_NumResults(g_query)) g_logeado[id] = USER_REGISTRADO
86 }
87 arrayset(gHabilidades[id], 0, charsmax(gHabilidades[]));
88 gNivel[id] = 1;
89 gExp[id] = 0;
90 gResets[id] = 0;
91 gHud[id] = 1;
92 Armadura[id] = 0
93 Gravedad[id] = 1.00
94 Speed[id] = 250.00
95 gPuntos[id] = 28;
96}
97public client_disconnect(id) {
98 if(task_exists(id)) { remove_task(id); }
99
100 remove_task(id + TASK_KICK);
101 Guardar(id);
102}
103public HamSpawn(const id) {
104 if(!is_user_alive(id)) return;
105
106 strip_user_weapons(id);
107 give_item(id, "weapon_knife");
108
109 set_user_gravity(id, Float:Gravedad[id]);
110 set_user_armor(id, Armadura[id]);
111
112 ShowMenuKnifes(id);
113}
114public hamPlayerKilled(victim, attacker, sg) {
115 if(!is_user_connected(victim) || !is_user_connected(attacker) || !attacker || attacker == victim) return HAM_IGNORED;
116
117 if(gNivel[attacker] == NivelMax) {
118 Color(attacker, "!yHas alcanzado el maximo de !tExp !yposible, debes hacer un !tReset.")
119 return HAM_IGNORED;
120 }
121 new Nombre[33]; get_user_name(victim, Nombre, charsmax(Nombre));
122 if(get_pdata_int(victim, 75, 5) == HIT_HEAD) {
123 Subir(attacker, 4);
124 Color(attacker, "!yHas ganado !g4 !yde !tExp !npor matar a !t%s !yde Headshot.", Nombre)
125 }
126 else {
127 Subir(attacker, 2);
128 Color(attacker, "!yHas ganado !g2 !yde !tExp !npor matar a !t%s.", Nombre)
129 }
130 return HAM_IGNORED;
131}
132public ham_KnifeDeployPost(wpn_ent) {
133 static kOwner; kOwner = get_weapon_ent_owner(wpn_ent);
134
135 if(!pev_valid(kOwner) || !is_user_alive(kOwner)) return;
136
137 set_pev(kOwner, pev_viewmodel2, Knifes[gKnife[kOwner]][V_MODEL]);
138 set_pev(kOwner, pev_weaponmodel2, Knifes[gKnife[kOwner]][P_MODEL]);
139}
140public FwdTakeDamage(victim, inflictor, attacker, Float:damage, damage_bits) {
141 if(!is_user_alive(attacker)) return HAM_IGNORED;
142
143 if(get_user_weapon(attacker) == CSW_KNIFE) {
144 damage*= Knifes[gKnife[attacker]][DMG]
145 }
146 SetHamParamFloat(4, damage)
147 return HAM_HANDLED
148}
149public fw_ResetMaxSpeed_Post(id) {
150 if(is_user_alive(id))
151 set_player_maxspeed(id)
152 return;
153}
154set_player_maxspeed(id) {
155 set_user_maxspeed(id, Speed[id])
156}
157public fwClientInfoChanged(id, buffer) {
158 if(!is_user_connected(id)) return FMRES_IGNORED;
159 if(!(g_logeado[id] == USER_LOGEADO)) return FMRES_IGNORED;
160
161 static OldName[33];
162 engfunc(EngFunc_InfoKeyValue, buffer, "name", OldName, sizeof OldName - 1);
163
164 if(equal(OldName, g_playername[id])) return FMRES_IGNORED;
165
166 set_user_info(id, "name", g_playername[id]);
167 client_cmd(id, "setinfo ^"name^" ^"%s^"", g_playername[id]);
168
169 return FMRES_IGNORED;
170}
171public FwdGameDesc() {
172 forward_return(FMV_STRING, "Knife Mod 2.0");
173 return FMRES_SUPERCEDE;
174}
175public message_VGUImenu(msgid, dest, index) {
176 if(g_logeado[index] != USER_LOGEADO) {
177 show_menu_registro(index);
178 return PLUGIN_HANDLED;
179 }
180 return PLUGIN_CONTINUE;
181}
182public message_statusicon(msg_id, msg_dest, id) {
183 static szIcon[8]
184 get_msg_arg_string(2, szIcon, charsmax(szIcon))
185
186 if(equal(szIcon, "buyzone") && get_msg_arg_int(1)) {
187 set_pdata_int(id, 235, get_pdata_int(id, 235) & ~(1<<0))
188 return PLUGIN_HANDLED;
189 }
190 return PLUGIN_CONTINUE;
191}
192public taskKickPlayer(id) {
193 id -= TASK_KICK;
194
195 server_cmd("kick #%d ^"Has excedido el tiempo de espera para poder Loguearte^"", get_user_userid(id));
196}
197public ShowHUD(id) {
198 if(!is_user_alive(id) || !gHud[id]) return;
199
200 set_hudmessage(0, 0, 255, 0.93, 0.15, 0, 1.0, 1.0)
201 show_hudmessage(id, "[Vida: %d]^n[Nivel: %d/%d | EXP: %d/%d]^n[Resets: %d]^n[Skin: %s]^n[Puntos: %d]", get_user_health(id), gNivel[id], NivelMax, gExp[id], LevelNext(gNivel[id]), gResets[id], Knifes[gKnife[id]][KNIFE_NAME], gPuntos[id], get_speed(id))
202}
203Subir(id, ammo) {
204 gExp[id] += ammo;
205
206 new iUploaded = false;
207 while(gExp[id] >= LevelNext(gNivel[id]) && gNivel[id] < NivelMax) {
208 ++gNivel[id];
209 iUploaded = true;
210 }
211 if(iUploaded) {
212 Color(id, "!yFelicidades subistes al nivel: !t%d.", gNivel[id]);
213 iUploaded = false;
214 }
215}
216public REGISTRE_SU_PASSWORD(id) {
217 if(g_logeado[id] != USER_NO_REGISTRADO) return
218
219 static szArg[192]; read_args(szArg, 191);
220 remove_quotes(szArg); trim(szArg);
221
222 if(equal(szArg, "")) {
223 client_cmd(id, "messagemode REGISTRE_SU_PASSWORD");
224 client_cmd(id, "spk ^"buttons/button11.wav^"");
225 client_print(id, print_center, "Debes ingresar una Password.");
226 return;
227 }
228 if(contain(szArg, " ") != -1) {
229 client_cmd(id, "messagemode REGISTRE_SU_PASSWORD");
230 client_cmd(id, "spk ^"buttons/button11.wav^"");
231 client_print(id, print_center, "La password debe contener al menos una palabra.");
232 return;
233 }
234 if (containi(szArg, "^"") != -1) {
235 client_cmd(id, "messagemode REGISTRE_SU_PASSWORD");
236 client_cmd(id, "spk ^"buttons/button11.wav^"");
237 client_print(id, print_center, "No puedes ingresar caracteres especiales")
238 return;
239 }
240 g_query = SQL_PrepareQuery(g_tuple, "INSERT INTO 'Cuentas' (Nombre, Password) VALUES (^"%s^", ^"%s^")", g_playername[id], szArg)
241
242 if (SQL_Execute(g_query)) {
243 g_logeado[id] = USER_LOGEADO
244 ForceJoinTeam(id)
245 client_print(id, print_center, "Te has registrado correctamente!")
246 }
247 else {
248 client_cmd(id, "spk ^"buttons/button11.wav^"");
249 show_menu_registro(id);
250 client_print(id, print_center, "Error al registrarte")
251 }
252}
253public INGRESA_TU_PASSWORD(id) {
254 if(g_logeado[id] != USER_REGISTRADO) return
255
256 static szArg[192]; read_args(szArg, 191);
257 remove_quotes(szArg); trim(szArg);
258
259 if(equal(szArg, "")) {
260 client_cmd(id, "messagemode INGRESA_TU_PASSWORD");
261 client_cmd(id, "spk ^"buttons/button11.wav^"");
262 client_print(id, print_center, "Debes ingresar una Password.");
263 return;
264 }
265 if(contain(szArg, " ") != -1) {
266 client_cmd(id, "messagemode INGRESA_TU_PASSWORD");
267 client_cmd(id, "spk ^"buttons/button11.wav^"");
268 client_print(id, print_center, "La password debe contener al menos una palabra.");
269 return;
270 }
271 if (containi(szArg, "^"") != -1) {
272 client_print(id, print_center, "No puedes ingresar caracteres especiales")
273 client_cmd(id, "spk ^"buttons/button11.wav^"");
274 client_cmd(id, "messagemode INGRESA_TU_PASSWORD")
275 return;
276 }
277 g_query = SQL_PrepareQuery(g_tuple, "SELECT Password, Nivel, Exp, Reset, Puntos, hgrav, hspeed, harmor, Armadura, Gravedad, Velocidad FROM 'Cuentas' WHERE Nombre = ^"%s^"", g_playername[id]);
278
279 if(SQL_Execute(g_query)) {
280 static szPass[192]; SQL_ReadResult(g_query, 0, szPass, 191);
281
282 if (equal(szPass, szArg)) {
283 gNivel[id] = SQL_ReadResult(g_query, 1);
284 gExp[id] = SQL_ReadResult(g_query, 2);
285 gResets[id] = SQL_ReadResult(g_query, 3);
286 gPuntos[id] = SQL_ReadResult(g_query, 4);
287 gHabilidades[id][0] = SQL_ReadResult(g_query, 5);
288 gHabilidades[id][1] = SQL_ReadResult(g_query, 6);
289 gHabilidades[id][2] = SQL_ReadResult(g_query, 7);
290 Armadura[id] = SQL_ReadResult(g_query, 8);
291 SQL_ReadResult(g_query, 9, Float:Gravedad[id]);
292 SQL_ReadResult(g_query, 10, Float:Speed[id]);
293
294 g_logeado[id] = USER_LOGEADO
295 ForceJoinTeam(id);
296 client_print(id, print_center, "Te has logueado correctamente!")
297 }
298 else {
299 client_cmd(id, "messagemode INGRESA_TU_PASSWORD")
300 client_print(id, print_center, "Password incorrecta")
301 }
302 }
303 else {
304 client_cmd(id, "spk ^"buttons/button11.wav^"");
305 show_menu_registro(id);
306 client_print(id, print_center, "Error al loguearte")
307 }
308}
309public clcmd_changeteam(id) {
310 ((g_logeado[id] == USER_LOGEADO) ? show_menu_game(id) : show_menu_registro(id))
311 return PLUGIN_HANDLED;
312}
313public show_menu_game(id) {
314 static text[299];
315 formatex(text, charsmax(text), "\r[Knife Mod Chile] \wMenu principal");
316 new menu = menu_create(text, "menu_game")
317
318 menu_additem(menu, "\wCambiar Skin", "1")
319 menu_additem(menu, "\wMejorar Habilidades", "2")
320 menu_additem(menu, "\wMenu Usuario", "3");
321 menu_additem(menu, "\wMenu Admin", "4");
322
323 menu_setprop(menu, MPROP_EXITNAME, "Salir")
324 menu_display(id, menu, 0)
325}
326public menu_game(id, menu, item) {
327 if(item == MENU_EXIT) { menu_destroy(menu); return PLUGIN_HANDLED; }
328
329 switch(item) {
330 case 0: {
331 ShowMenuKnifes(id);
332 }
333 case 1: {
334 cmdPuntos(id);
335 }
336 case 2: {
337 usermenu(id);
338 }
339 case 3: {
340 }
341 }
342 return PLUGIN_HANDLED;
343}
344public cmdPuntos(id) {
345 new menu, text[1000];
346 formatex(text, charsmax(text), "\wMejoras de habilidades^n\wTienes \r%d punto%s \wpara gastar.", gPuntos[id], (gPuntos[id] > 1) ? "s" : "")
347 menu = menu_create(text, "h_puntos");
348
349 if(gHabilidades[id][0] == 6) {
350 formatex(text, charsmax(text), "\dMejorar gravedad \r[NIVEL MAXIMO]");
351 }
352 else {
353 formatex(text, charsmax(text), "\yMejorar gravedad \r[%d/6]", gHabilidades[id][0]);
354 }
355 menu_additem(menu, text, "1");
356
357 if(gHabilidades[id][1] == 7) {
358 formatex(text, charsmax(text), "\dMejorar velocidad \r[NIVEL MAXIMO]");
359 }
360 else {
361 formatex(text, charsmax(text), "\yMejorar velocidad \r[%d/7]", gHabilidades[id][1]);
362 }
363 menu_additem(menu, text, "2");
364
365 if(gHabilidades[id][2] == 15) {
366 formatex(text, charsmax(text), "\dMejorar armadura \r[NIVEL MAXIMO]");
367 }
368 else {
369 formatex(text, charsmax(text), "\yMejorar armadura \r[%d/15]", gHabilidades[id][2]);
370 }
371 menu_additem(menu, text, "3");
372 menu_setprop(menu, MPROP_EXITNAME, "\rSalir");
373 menu_display(id, menu, 0);
374}
375public h_puntos(id, menu, item) {
376 if(item == MENU_EXIT) { menu_destroy(menu); return PLUGIN_HANDLED; }
377
378 switch(item) {
379 case 0: {
380 if(gPuntos[id] <= 0) {
381 cmdPuntos(id);
382 Color(id, "!yNo te quedan mas !tPuntos !ypara gastar.");
383 return PLUGIN_HANDLED;
384 }
385 if(gHabilidades[id][0] == 6) {
386 cmdPuntos(id);
387 Color(id, "!yHas alcanzado el nivel maximo de esta habilidad.");
388 return PLUGIN_HANDLED;
389 }
390 Gravedad[id] -= 0.07
391 gPuntos[id]--
392 gHabilidades[id][0]++
393 }
394 case 1: {
395 if(gPuntos[id] <= 0) {
396 cmdPuntos(id);
397 Color(id, "!yNo te quedan mas !tPuntos !ypara gastar.");
398 return PLUGIN_HANDLED;
399 }
400 if(gHabilidades[id][1] == 7) {
401 cmdPuntos(id);
402 Color(id, "!yHas alcanzado el nivel maximo de esta habilidad.");
403 return PLUGIN_HANDLED;
404 }
405 Speed[id] += 10.00
406 gPuntos[id]--
407 gHabilidades[id][1]++
408 }
409 case 2: {
410 if(gPuntos[id] <= 0) {
411 cmdPuntos(id);
412 Color(id, "!yNo te quedan mas !tPuntos !ypara gastar.");
413 return PLUGIN_HANDLED;
414 }
415 if(gHabilidades[id][2] == 15) {
416 cmdPuntos(id);
417 Color(id, "!yHas alcanzado el nivel maximo de esta habilidad.");
418 return PLUGIN_HANDLED;
419 }
420 Armadura[id] += 10
421 gPuntos[id]--
422 gHabilidades[id][2]++
423 }
424 }
425 set_user_gravity(id, Float:Gravedad[id]);
426 set_user_armor(id, Armadura[id]);
427 cmdPuntos(id);
428 return PLUGIN_HANDLED;
429}
430public usermenu(id) {
431 static text[299];
432 formatex(text, charsmax(text), "\r[Knife Mod Chile] \wMenu de Usuario");
433 new menu = menu_create(text, "menu_user")
434
435 menu_additem(menu, gHud[id] ? "\wHud: \rON" : "\wHud: \rOFF", "1")
436 menu_additem(menu, (gNivel[id] < NivelMax) ? "\dHacer un Reset" : "\wHacer reset", "2")
437
438 menu_setprop(menu, MPROP_EXITNAME, "Volver al menu principal")
439 menu_display(id, menu, 0)
440}
441public menu_user(id, menu, item) {
442 if(item == MENU_EXIT) { show_menu_game(id); return PLUGIN_HANDLED; }
443
444 switch(item) {
445 case 0: {
446 gHud[id] = !gHud[id]
447 usermenu(id);
448 }
449 case 1: {
450 if(gNivel[id] < NivelMax) {
451 Color(id, "!yNecesitas ser nivel !g%d !ypara poder hacer un !treset.", NivelMax)
452 return PLUGIN_HANDLED;
453 }
454 gResets[id]++
455 gPuntos[id]++
456 gNivel[id] = 1; gExp[id] = 0;
457 }
458 }
459 return PLUGIN_HANDLED;
460}
461public show_menu_registro(id) {
462 static text[299];
463 formatex(text, charsmax(text), "\rKnife Mod Chile^n\wVersion \rv2.0^n^n\wNombre: \y%s^n\wEstado: \y%s", g_playername[id], (g_logeado[id] == USER_NO_REGISTRADO) ? "No Registrado" : "Registrado");
464 new menu = menu_create(text, "Handler")
465
466 menu_additem(menu, (g_logeado[id] == USER_NO_REGISTRADO) ? "\wCrear \ycuenta" : "\dCrear cuenta", "1")
467 menu_additem(menu, (g_logeado[id] == USER_REGISTRADO) ? "\wIniciar \ysesion^n^n" : "\dIniciar sesion^n^n", "2")
468 menu_additem(menu, "\wDesconectarse del servidor^n^n^n\wSi no te \rRegistras/Logueas \wen ^n\r1 minuto \wseras Kickeado del Servidor", "3");
469
470 menu_setprop(menu, MPROP_EXIT, MEXIT_NEVER)
471 menu_display(id, menu)
472
473 return PLUGIN_HANDLED;
474}
475public Handler(id, menu, item) {
476 switch (item) {
477 case 0: {
478 if(g_logeado[id] == USER_REGISTRADO) {
479 show_menu_registro(id);
480 Color(id, "!yYa tienes una cuenta registrada en la !tbase de datos.");
481 return PLUGIN_HANDLED;
482 }
483 client_cmd(id, "messagemode REGISTRE_SU_PASSWORD")
484 client_print(id, print_center, "Ingresa una password para tu cuenta")
485 }
486 case 1: {
487 if(g_logeado[id] == USER_NO_REGISTRADO) {
488 show_menu_registro(id);
489 Color(id, "!yActualmente no tienes una cuenta registrada en la !tbase de datos.");
490 return PLUGIN_HANDLED;
491 }
492 client_cmd(id, "messagemode INGRESA_TU_PASSWORD")
493 client_print(id, print_center, "Ingresa la password de tu cuenta")
494 }
495 case 2: {
496 client_cmd(id, "disconnect")
497 }
498 }
499 menu_destroy(menu)
500 return PLUGIN_HANDLED;
501}
502public Guardar(id) {
503 if(g_logeado[id] != USER_LOGEADO) return;
504
505 g_query = SQL_PrepareQuery(g_tuple, "UPDATE 'Cuentas' SET Nivel='%d', Exp='%d', Reset='%d', Puntos='%d', hgrav='%d', hspeed='%d', harmor='%d', Armadura='%d', Gravedad='%0.2f', Velocidad='%0.2f' WHERE Nombre = ^"%s^"", gNivel[id], gExp[id], gResets[id], gPuntos[id], gHabilidades[id][0], gHabilidades[id][1], gHabilidades[id][2], Armadura[id], Gravedad[id], Speed[id], g_playername[id])
506 SQL_Execute(g_query)
507}
508public CheckTabla() {
509 g_query = SQL_PrepareQuery
510 (
511 g_tuple,
512 "CREATE TABLE IF NOT EXISTS 'Cuentas' \
513 ( \
514 Nombre varchar(33) NOT NULL default '' PRIMARY KEY, \
515 Password varchar(192) NOT NULL default '', \
516 Nivel int NOT NULL default '1', \
517 Exp int NOT NULL DEFAULT '0', \
518 Reset int NOT NULL DEFAULT '0', \
519 Puntos int NOT NULL DEFAULT '0', \
520 hgrav int NOT NULL DEFAULT '0', \
521 hspeed int NOT NULL DEFAULT '0', \
522 harmor int NOT NULL DEFAULT '0', \
523 Armadura int NOT NULL DEFAULT '0', \
524 Gravedad float NOT NULL DEFAULT '1.00', \
525 Velocidad float NOT NULL DEFAULT '250.00' \
526 )"
527 )
528 SQL_Execute(g_query)
529}
530public SQLXInit() {
531 new get_type[12];
532 SQL_SetAffinity("sqlite")
533 SQL_GetAffinity(get_type, sizeof(get_type))
534
535 if (!equali(get_type, "sqlite")) {
536 log_to_file("SQLX.log", "Driver no encontrado");
537 pause("a");
538 }
539 else {
540 static error, szError[300];
541 g_query = SQL_MakeDbTuple("", "", "", SQLX_DATABASE)
542 g_tuple = SQL_Connect(g_query, error, szError, 300)
543
544 if(strlen(szError)) {
545 log_to_file("ErrorSQL.log", szError)
546 pause("a")
547 }
548 CheckTabla()
549 }
550}
551ForceJoinTeam(index)
552{
553 static teammsg_block, teammsg_block_vgui, restore, vgui;
554
555 restore = get_pdata_int(index, 510);
556 vgui = restore & (1<<0);
557
558 if (vgui) set_pdata_int(index, 510, restore & ~(1<<0));
559
560 teammsg_block = get_msg_block(g_iMsgShowMenu);
561 teammsg_block_vgui = get_msg_block(g_iMsgVguiMenu);
562
563 set_msg_block(g_iMsgShowMenu, BLOCK_ONCE);
564 set_msg_block(g_iMsgVguiMenu, BLOCK_ONCE);
565
566 engclient_cmd(index, "jointeam", "5");
567 engclient_cmd(index, "joinclass", "5");
568
569 set_msg_block(g_iMsgShowMenu, teammsg_block);
570 set_msg_block(g_iMsgVguiMenu, teammsg_block_vgui);
571
572 if (vgui) { set_pdata_int(index, 510, restore); }
573
574 remove_task(index + TASK_KICK);
575}
576public Info(id) {
577 if(!(g_logeado[id] == USER_LOGEADO)) return;
578
579 Color(id, "Nivel: !t%d!y | EXP: !t%d!y | Resets: !t%d!y | Skin: !t%s!y | !yExp restante : !t%d.", gNivel[id], gExp[id], gResets[id], Knifes[gKnife[id]][KNIFE_NAME], LevelNext(gNivel[id]) - gExp[id])
580}
581public ShowMenuKnifes(id) {
582 static text[1000], menu;
583 menu = menu_create("\r[Knife Mod Chile] \ySelecciona tu skin:", "handler_knife");
584
585 for(new i = 0; i < sizeof Knifes; ++i) {
586 if(gNivel[id] >= Knifes[i][LVL] && gResets[id] >= Knifes[i][RR]) {
587 formatex(text, charsmax(text), "\y%s \r%s", Knifes[i][KNIFE_NAME], (gKnife[id] == i) ? "[ESCOGIDO]" : "");
588 }
589 else {
590 formatex(text, charsmax(text), "\d%s \r[Nivel: %d | Resets: %d]", Knifes[i][KNIFE_NAME], Knifes[i][LVL], Knifes[i][RR]);
591 }
592 menu_additem(menu, text, "");
593 }
594 menu_setprop(menu, MPROP_EXITNAME, "Salir");
595 menu_display(id, menu);
596}
597public handler_knife(id, menu, item) {
598 if(item == MENU_EXIT) { menu_destroy(menu); return PLUGIN_HANDLED; }
599
600 if(gKnife[id] == item) {
601 Color(id, "!yYa tienes esta skin!");
602 return PLUGIN_HANDLED;
603 }
604 if(gNivel[id] < Knifes[item][LVL] || gResets[id] < Knifes[item][RR]) {
605 ShowMenuKnifes(id);
606 Color(id, "!yPara elegir la skin de !g%s !ynecesitas ser nivel !t%d !yy tener !t%d !yresets.", Knifes[item][KNIFE_NAME], Knifes[item][LVL], Knifes[item][RR]);
607 return PLUGIN_HANDLED;
608 }
609 gKnife[id] = item;
610 engclient_cmd(id, "weapon_knife");
611
612 menu_destroy(menu);
613 return PLUGIN_HANDLED;
614}
615public plugin_end() { SQL_FreeHandle(g_tuple); }
616stock Color(const id, const Text[ ], any:... ) {
617
618 new count = 1, players[32];
619 static msg[191], len, i;
620
621 len = formatex( msg, charsmax(msg), "!g[Knife Mod Chile]!y ");
622 vformat(msg[len], 190 - len, Text, 3);
623
624 replace_all(msg, 190, "!g", "^4" );
625 replace_all(msg, 190, "!y", "^1" );
626 replace_all(msg, 190, "!t", "^3" );
627
628 static iLen = sizeof( msg );
629
630 replace_all(msg, iLen, "á", "á");
631 replace_all(msg, iLen, "Ã", "Ã");
632 replace_all(msg, iLen, "é", "é");
633 replace_all(msg, iLen, "É", "É");
634 replace_all(msg, iLen, "Ã", "Ã*");
635 replace_all(msg, iLen, "Ã", "Ã");
636 replace_all(msg, iLen, "ó", "ó");
637 replace_all(msg, iLen, "Ó", "Ó");
638 replace_all(msg, iLen, "ú", "ú");
639 replace_all(msg, iLen, "Ú", "Ú");
640 replace_all(msg, iLen, "ñ", "ñ");
641 replace_all(msg, iLen, "Ñ", "Ñ");
642
643 if(id)
644 players[ 0 ] = id;
645 else
646 get_players(players, count, "ch");
647
648 for(i = 0; i < count; ++i) {
649 if( is_user_connected(players[i]))
650 writeMessage(players[i], msg);
651 }
652}
653stock writeMessage( player, message[ ] ) {
654 message_begin(MSG_ONE, get_user_msgid("SayText"), { 0, 0, 0 }, player);
655 write_byte(player);
656 write_string(message);
657 message_end();
658}
659stock get_weapon_ent_owner(ent) {
660 if(pev_valid(ent) != 2) {
661 return -1;
662 }
663 return get_pdata_cbase(ent, 41, 4);
664}