· 6 years ago · Dec 19, 2019, 05:52 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 cmdPuntos(id);
426 return PLUGIN_HANDLED;
427}
428public usermenu(id) {
429 static text[299];
430 formatex(text, charsmax(text), "\r[Knife Mod Chile] \wMenu de Usuario");
431 new menu = menu_create(text, "menu_user")
432
433 menu_additem(menu, gHud[id] ? "\wHud: \rON" : "\wHud: \rOFF", "1")
434 menu_additem(menu, (gNivel[id] < NivelMax) ? "\dHacer un Reset" : "\wHacer reset", "2")
435
436 menu_setprop(menu, MPROP_EXITNAME, "Volver al menu principal")
437 menu_display(id, menu, 0)
438}
439public menu_user(id, menu, item) {
440 if(item == MENU_EXIT) { show_menu_game(id); return PLUGIN_HANDLED; }
441
442 switch(item) {
443 case 0: {
444 gHud[id] = !gHud[id]
445 usermenu(id);
446 }
447 case 1: {
448 if(gNivel[id] < NivelMax) {
449 Color(id, "!yNecesitas ser nivel !g%d !ypara poder hacer un !treset.", NivelMax)
450 return PLUGIN_HANDLED;
451 }
452 gResets[id]++
453 gPuntos[id]++
454 gNivel[id] = 1; gExp[id] = 0;
455 }
456 }
457 return PLUGIN_HANDLED;
458}
459public show_menu_registro(id) {
460 static text[299];
461 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");
462 new menu = menu_create(text, "Handler")
463
464 menu_additem(menu, (g_logeado[id] == USER_NO_REGISTRADO) ? "\wCrear \ycuenta" : "\dCrear cuenta", "1")
465 menu_additem(menu, (g_logeado[id] == USER_REGISTRADO) ? "\wIniciar \ysesion^n^n" : "\dIniciar sesion^n^n", "2")
466 menu_additem(menu, "\wDesconectarse del servidor^n^n^n\wSi no te \rRegistras/Logueas \wen ^n\r1 minuto \wseras Kickeado del Servidor", "3");
467
468 menu_setprop(menu, MPROP_EXIT, MEXIT_NEVER)
469 menu_display(id, menu)
470
471 return PLUGIN_HANDLED;
472}
473public Handler(id, menu, item) {
474 switch (item) {
475 case 0: {
476 if(g_logeado[id] == USER_REGISTRADO) {
477 show_menu_registro(id);
478 Color(id, "!yYa tienes una cuenta registrada en la !tbase de datos.");
479 return PLUGIN_HANDLED;
480 }
481 client_cmd(id, "messagemode REGISTRE_SU_PASSWORD")
482 client_print(id, print_center, "Ingresa una password para tu cuenta")
483 }
484 case 1: {
485 if(g_logeado[id] == USER_NO_REGISTRADO) {
486 show_menu_registro(id);
487 Color(id, "!yActualmente no tienes una cuenta registrada en la !tbase de datos.");
488 return PLUGIN_HANDLED;
489 }
490 client_cmd(id, "messagemode INGRESA_TU_PASSWORD")
491 client_print(id, print_center, "Ingresa la password de tu cuenta")
492 }
493 case 2: {
494 client_cmd(id, "disconnect")
495 }
496 }
497 menu_destroy(menu)
498 return PLUGIN_HANDLED;
499}
500public Guardar(id) {
501 if(g_logeado[id] != USER_LOGEADO) return;
502
503 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])
504 SQL_Execute(g_query)
505}
506public CheckTabla() {
507 g_query = SQL_PrepareQuery
508 (
509 g_tuple,
510 "CREATE TABLE IF NOT EXISTS 'Cuentas' \
511 ( \
512 Nombre varchar(33) NOT NULL default '' PRIMARY KEY, \
513 Password varchar(192) NOT NULL default '', \
514 Nivel int NOT NULL default '1', \
515 Exp int NOT NULL DEFAULT '0', \
516 Reset int NOT NULL DEFAULT '0', \
517 Puntos int NOT NULL DEFAULT '0', \
518 hgrav int NOT NULL DEFAULT '0', \
519 hspeed int NOT NULL DEFAULT '0', \
520 harmor int NOT NULL DEFAULT '0', \
521 Armadura int NOT NULL DEFAULT '0', \
522 Gravedad float NOT NULL DEFAULT '1.00', \
523 Velocidad float NOT NULL DEFAULT '250.00' \
524 )"
525 )
526 SQL_Execute(g_query)
527}
528public SQLXInit() {
529 new get_type[12];
530 SQL_SetAffinity("sqlite")
531 SQL_GetAffinity(get_type, sizeof(get_type))
532
533 if (!equali(get_type, "sqlite")) {
534 log_to_file("SQLX.log", "Driver no encontrado");
535 pause("a");
536 }
537 else {
538 static error, szError[300];
539 g_query = SQL_MakeDbTuple("", "", "", SQLX_DATABASE)
540 g_tuple = SQL_Connect(g_query, error, szError, 300)
541
542 if(strlen(szError)) {
543 log_to_file("ErrorSQL.log", szError)
544 pause("a")
545 }
546 CheckTabla()
547 }
548}
549ForceJoinTeam(index)
550{
551 static teammsg_block, teammsg_block_vgui, restore, vgui;
552
553 restore = get_pdata_int(index, 510);
554 vgui = restore & (1<<0);
555
556 if (vgui) set_pdata_int(index, 510, restore & ~(1<<0));
557
558 teammsg_block = get_msg_block(g_iMsgShowMenu);
559 teammsg_block_vgui = get_msg_block(g_iMsgVguiMenu);
560
561 set_msg_block(g_iMsgShowMenu, BLOCK_ONCE);
562 set_msg_block(g_iMsgVguiMenu, BLOCK_ONCE);
563
564 engclient_cmd(index, "jointeam", "5");
565 engclient_cmd(index, "joinclass", "5");
566
567 set_msg_block(g_iMsgShowMenu, teammsg_block);
568 set_msg_block(g_iMsgVguiMenu, teammsg_block_vgui);
569
570 if (vgui) { set_pdata_int(index, 510, restore); }
571
572 remove_task(index + TASK_KICK);
573}
574public Info(id) {
575 if(!(g_logeado[id] == USER_LOGEADO)) return;
576
577 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])
578}
579public ShowMenuKnifes(id) {
580 static text[1000], menu;
581 menu = menu_create("\r[Knife Mod Chile] \ySelecciona tu skin:", "handler_knife");
582
583 for(new i = 0; i < sizeof Knifes; ++i) {
584 if(gNivel[id] >= Knifes[i][LVL] && gResets[id] >= Knifes[i][RR]) {
585 formatex(text, charsmax(text), "\y%s \r%s", Knifes[i][KNIFE_NAME], (gKnife[id] == i) ? "[ESCOGIDO]" : "");
586 }
587 else {
588 formatex(text, charsmax(text), "\d%s \r[Nivel: %d | Resets: %d]", Knifes[i][KNIFE_NAME], Knifes[i][LVL], Knifes[i][RR]);
589 }
590 menu_additem(menu, text, "");
591 }
592 menu_setprop(menu, MPROP_EXITNAME, "Salir");
593 menu_display(id, menu);
594}
595public handler_knife(id, menu, item) {
596 if(item == MENU_EXIT) { menu_destroy(menu); return PLUGIN_HANDLED; }
597
598 if(gKnife[id] == item) {
599 Color(id, "!yYa tienes esta skin!");
600 return PLUGIN_HANDLED;
601 }
602 if(gNivel[id] < Knifes[item][LVL] || gResets[id] < Knifes[item][RR]) {
603 ShowMenuKnifes(id);
604 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]);
605 return PLUGIN_HANDLED;
606 }
607 gKnife[id] = item;
608 engclient_cmd(id, "weapon_knife");
609
610 menu_destroy(menu);
611 return PLUGIN_HANDLED;
612}
613public plugin_end() { SQL_FreeHandle(g_tuple); }
614stock Color(const id, const Text[ ], any:... ) {
615
616 new count = 1, players[32];
617 static msg[191], len, i;
618
619 len = formatex( msg, charsmax(msg), "!g[Knife Mod Chile]!y ");
620 vformat(msg[len], 190 - len, Text, 3);
621
622 replace_all(msg, 190, "!g", "^4" );
623 replace_all(msg, 190, "!y", "^1" );
624 replace_all(msg, 190, "!t", "^3" );
625
626 static iLen = sizeof( msg );
627
628 replace_all(msg, iLen, "á", "á");
629 replace_all(msg, iLen, "Ã", "Ã");
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
641 if(id)
642 players[ 0 ] = id;
643 else
644 get_players(players, count, "ch");
645
646 for(i = 0; i < count; ++i) {
647 if( is_user_connected(players[i]))
648 writeMessage(players[i], msg);
649 }
650}
651stock writeMessage( player, message[ ] ) {
652 message_begin(MSG_ONE, get_user_msgid("SayText"), { 0, 0, 0 }, player);
653 write_byte(player);
654 write_string(message);
655 message_end();
656}
657stock get_weapon_ent_owner(ent) {
658 if(pev_valid(ent) != 2) {
659 return -1;
660 }
661 return get_pdata_cbase(ent, 41, 4);
662}