· 6 years ago · Dec 16, 2019, 05:08 AM
1#include <amxmodx>
2#include <hamsandwich>
3#include <engine>
4#include <fakemeta>
5#include <cstrike>
6#include <fun>
7#include <sqlx>
8
9#define MAX_PLAYERS 32
10#define LevelNext(%1) (%1 * 25)
11#define NivelMax 10
12#define SQLX_DATABASE "dataknifemod"
13const USER_NO_REGISTRADO = -1;
14const USER_REGISTRADO = 0;
15const USER_LOGEADO = 1;
16
17new g_logeado[33], g_playername[33][32];
18new Handle:g_query, Handle:g_tuple, g_iMsgVguiMenu, g_iMsgShowMenu;
19new gNivel[MAX_PLAYERS+1], gExp[MAX_PLAYERS+1];
20
21public plugin_init() {
22 register_plugin("Knife mod", "1.0.0", "Kross");
23
24 /* CLCMD */
25 register_clcmd("REGISTRE_SU_PASSWORD", "REGISTRE_SU_PASSWORD")
26 register_clcmd("INGRESA_TU_PASSWORD", "INGRESA_TU_PASSWORD")
27
28 /* FORWARDS */
29 register_forward(FM_ClientUserInfoChanged, "fwClientInfoChanged");
30 /* HAMS */
31 RegisterHam(Ham_Spawn, "player", "HamSpawn", true);
32 RegisterHam(Ham_Killed, "player", "hamPlayerKilled", true);
33
34 /* MESSAGE */
35 register_message(get_user_msgid("StatusIcon"), "message_statusicon")
36 g_iMsgVguiMenu = get_user_msgid("VGUIMenu");
37 g_iMsgShowMenu = get_user_msgid("ShowMenu");
38 register_message(g_iMsgVguiMenu, "message_VGUImenu");
39 register_message(g_iMsgShowMenu, "message_VGUImenu");
40
41 SQLXInit()
42}
43public client_putinserver(id) {
44 get_user_name(id, g_playername[id], charsmax(g_playername[]))
45 set_task(0.1, "ShowHUD", id, _, _, "b")
46
47 g_logeado[id] = USER_NO_REGISTRADO
48 g_query = SQL_PrepareQuery(g_tuple, "SELECT Nombre FROM 'Cuentas' WHERE Nombre = ^"%s^"", g_playername[id]);
49
50 if (SQL_Execute(g_query)) {
51 if (SQL_NumResults(g_query)) g_logeado[id] = USER_REGISTRADO
52 }
53 gNivel[id] = 1;
54 gExp[id] = 0;
55}
56public client_disconnect(id) {
57 if(task_exists(id)) { remove_task(id); }
58
59 Guardar(id);
60}
61public HamSpawn(const id) {
62 if(!is_user_alive(id)) return;
63
64 set_task(0.1, "check", id)
65}
66public hamPlayerKilled(victim, attacker, sg) {
67 if(!is_user_connected(victim) || !is_user_connected(attacker) || !attacker || attacker == victim) return HAM_IGNORED;
68
69 if(gNivel[attacker] == NivelMax) {
70 client_print(attacker, print_chat, "No ganas exp estas en tu nivel maximo, hace un resets.")
71 return HAM_IGNORED;
72 }
73 /* SI LA VICTIMA MUERE POR HS LE DA AL ATACANTE 4 de exp */
74 if(get_pdata_int(victim, 75, 5) == HIT_HEAD) {
75 Subir(attacker, 4);
76 }
77 else {
78 Subir(attacker, 2);
79 }
80 return HAM_IGNORED;
81}
82public fwClientInfoChanged(id, buffer) {
83 if(!is_user_connected(id)) return FMRES_IGNORED;
84 if(!(g_logeado[id] == USER_LOGEADO)) return FMRES_IGNORED;
85
86 static OldName[33];
87 engfunc(EngFunc_InfoKeyValue, buffer, "name", OldName, sizeof OldName - 1);
88
89 if(equal(OldName, g_playername[id])) return FMRES_IGNORED;
90
91 set_user_info(id, "name", g_playername[id]);
92 client_cmd(id, "setinfo ^"name^" ^"%s^"", g_playername[id]);
93
94 return FMRES_IGNORED;
95}
96public message_VGUImenu(msgid, dest, index) {
97 if(g_logeado[index] != USER_LOGEADO) {
98 show_menu_registro(index);
99 return PLUGIN_HANDLED;
100 }
101 return PLUGIN_CONTINUE;
102}
103public message_statusicon(msg_id, msg_dest, id) {
104 static szIcon[8]
105 get_msg_arg_string(2, szIcon, charsmax(szIcon))
106
107 if(equal(szIcon, "buyzone") && get_msg_arg_int(1)) {
108 set_pdata_int(id, 235, get_pdata_int(id, 235) & ~(1<<0))
109 return PLUGIN_HANDLED;
110 }
111 return PLUGIN_CONTINUE;
112}
113public ShowHUD(id) {
114 if(!is_user_alive(id)) return;
115
116 set_hudmessage(0, 255, 255, 0.0, 0.20, 1, 6.0, 1.0);
117 show_hudmessage(id, "- Vida : %d^n- Nivel : %d/%d^n- Exp : %d/%d", get_user_health(id), gNivel[id], NivelMax, gExp[id], LevelNext(gNivel[id]))
118}
119Subir(id, ammo) {
120 gExp[id] += ammo;
121
122 new iUploaded = false;
123 while(gExp[id] >= LevelNext(gNivel[id]) && gNivel[id] < NivelMax) {
124 ++gNivel[id];
125 iUploaded = true;
126 }
127 if(iUploaded) {
128 client_print( id, print_chat, "Felicidades subiste al nivel: %d.", gNivel[id]);
129 iUploaded = false;
130 }
131}
132public check(id) {
133 strip_user_weapons(id);
134 give_item(id, "weapon_knife");
135
136 if(user_has_weapon(id, CSW_C4)) { ham_strip_weapon(id, "weapon_c4"); }
137}
138public REGISTRE_SU_PASSWORD(id) {
139 if(g_logeado[id] != USER_NO_REGISTRADO) return
140
141 static szArg[192]; read_args(szArg, 191);
142 remove_quotes(szArg); trim(szArg);
143
144 if(equal(szArg, "")) {
145 client_cmd(id, "messagemode REGISTRE_SU_PASSWORD");
146 client_cmd(id, "spk ^"buttons/button11.wav^"");
147 client_print(id, print_center, "No has introducido una password.");
148 return;
149 }
150 if(contain(szArg, " ") != -1) {
151 client_cmd(id, "messagemode REGISTRE_SU_PASSWORD");
152 client_cmd(id, "spk ^"buttons/button11.wav^"");
153 client_print(id, print_center, "La password tiene que contener una palabra.");
154 return;
155 }
156 if (containi(szArg, "^"") != -1) {
157 client_cmd(id, "messagemode REGISTRE_SU_PASSWORD");
158 client_cmd(id, "spk ^"buttons/button11.wav^"");
159 client_print(id, print_center, "No puedes usar comillas")
160 return;
161 }
162 g_query = SQL_PrepareQuery(g_tuple, "INSERT INTO 'Cuentas' (Nombre, Password) VALUES (^"%s^", ^"%s^")", g_playername[id], szArg)
163
164 if (SQL_Execute(g_query)) {
165 g_logeado[id] = USER_LOGEADO
166 ForceJoinTeam(id)
167 client_print(id, print_center, "Te has registrado correctamente!")
168 }
169 else {
170 client_cmd(id, "spk ^"buttons/button11.wav^"");
171 client_print(id, print_center, "Error al registrarte :(")
172 }
173}
174public INGRESA_TU_PASSWORD(id) {
175 if(g_logeado[id] != USER_REGISTRADO) return
176
177 static szArg[192]; read_args(szArg, 191);
178 remove_quotes(szArg); trim(szArg);
179
180 if(equal(szArg, "")) {
181 client_cmd(id, "messagemode INGRESA_TU_PASSWORD");
182 client_cmd(id, "spk ^"buttons/button11.wav^"");
183 client_print(id, print_center, "No has introducido una password.");
184 return;
185 }
186 if(contain(szArg, " ") != -1) {
187 client_cmd(id, "messagemode INGRESA_TU_PASSWORD");
188 client_cmd(id, "spk ^"buttons/button11.wav^"");
189 client_print(id, print_center, "La password tiene que contener una palabra.");
190 return;
191 }
192 if (containi(szArg, "^"") != -1) {
193 client_print(id, print_center, "No puedes usar comillas")
194 client_cmd(id, "spk ^"buttons/button11.wav^"");
195 client_cmd(id, "messagemode INGRESA_TU_PASSWORD")
196 return;
197 }
198 g_query = SQL_PrepareQuery(g_tuple, "SELECT Password, Nivel, Exp FROM 'Cuentas' WHERE Nombre = ^"%s^"", g_playername[id]);
199
200 if(SQL_Execute(g_query)) {
201 static szPass[192]; SQL_ReadResult(g_query, 0, szPass, 191);
202
203 if (equal(szPass, szArg)) {
204 gNivel[id] = SQL_ReadResult(g_query, 1);
205 gExp[id] = SQL_ReadResult(g_query, 2);
206 g_logeado[id] = USER_LOGEADO
207 ForceJoinTeam(id);
208 client_print(id, print_center, "Te has logeado correctamente!")
209 }
210 else {
211 client_cmd(id, "messagemode INGRESA_TU_PASSWORD")
212 client_print(id, print_center, "Password incorrecta")
213 }
214 }
215 else {
216 client_cmd(id, "spk ^"buttons/button11.wav^"");
217 client_print(id, print_center, "Error al logearte :(")
218 }
219}
220public show_menu_registro(id) {
221 if(g_logeado[id] == USER_LOGEADO) return PLUGIN_CONTINUE;
222
223 static text[299];
224 formatex(text, charsmax(text), "\rKnife Mod Chile^n\wVersion \y1.0.0\w creado por \ySeeRiouS'^n^n\r-\w Bienvenido : \y%s^n\r-\w Estado : \y%s", g_playername[id], (g_logeado[id] == USER_NO_REGISTRADO) ? "No Registrado" : "Registrado");
225 new menu = menu_create(text, "Handler")
226
227 menu_additem(menu, (g_logeado[id] == USER_NO_REGISTRADO) ? "\wCrear \ycuenta" : "\dCrear cuenta", "1")
228 menu_additem(menu, (g_logeado[id] == USER_REGISTRADO) ? "\wIniciar \ysesion" : "\dIniciar sesion", "2")
229
230 menu_setprop(menu, MPROP_EXIT, MEXIT_NEVER)
231 menu_display(id, menu)
232
233 return PLUGIN_HANDLED;
234}
235public Handler(id, menu, item) {
236 switch (item) {
237 case 0: {
238 if(g_logeado[id] == USER_REGISTRADO) {
239 show_menu_registro(id);
240 Color(id, "Ya tienes una cuenta registrada en la !tbase de datos!y.");
241 return PLUGIN_HANDLED;
242 }
243 client_cmd(id, "messagemode REGISTRE_SU_PASSWORD")
244 client_print(id, print_center, "Elije una password para tu cuenta")
245 }
246 case 1: {
247 if(g_logeado[id] == USER_NO_REGISTRADO) {
248 show_menu_registro(id);
249 Color(id, "No tienes una cuenta registrada en la !tbase de datos!y.");
250 return PLUGIN_HANDLED;
251 }
252 client_cmd(id, "messagemode INGRESA_TU_PASSWORD")
253 client_print(id, print_center, "Ingresa la password de tu cuenta")
254 }
255 }
256 menu_destroy(menu)
257 return PLUGIN_HANDLED;
258}
259public Guardar(id) {
260 if(g_logeado[id] != USER_LOGEADO) return;
261
262 g_query = SQL_PrepareQuery(g_tuple, "UPDATE 'Cuentas' SET Nivel='%d', Exp='%d' WHERE Nombre = ^"%s^"", gNivel[id], gExp[id], g_playername[id])
263 SQL_Execute(g_query)
264}
265public CheckTabla() {
266 g_query = SQL_PrepareQuery
267 (
268 g_tuple,
269 "CREATE TABLE IF NOT EXISTS 'Cuentas' \
270 ( \
271 Nombre varchar(33) NOT NULL default '' PRIMARY KEY, \
272 Password varchar(192) NOT NULL default '', \
273 Nivel int NOT NULL default '1', \
274 Exp int NOT NULL DEFAULT '0' \
275 )"
276 )
277 SQL_Execute(g_query)
278}
279public SQLXInit() {
280 new get_type[12];
281 SQL_SetAffinity("sqlite")
282 SQL_GetAffinity(get_type, sizeof(get_type))
283
284 if (!equali(get_type, "sqlite")) {
285 log_to_file("SQLX.log", "Driver no encontrado");
286 pause("a");
287 }
288 else {
289 static error, szError[300];
290 g_query = SQL_MakeDbTuple("", "", "", SQLX_DATABASE)
291 g_tuple = SQL_Connect(g_query, error, szError, 300)
292
293 if(strlen(szError)) {
294 log_to_file("ErrorSQL.log", szError)
295 pause("a")
296 }
297 CheckTabla()
298 }
299}
300ForceJoinTeam(index)
301{
302 static teammsg_block, teammsg_block_vgui, restore, vgui;
303
304 restore = get_pdata_int(index, 510);
305 vgui = restore & (1<<0);
306
307 if (vgui) set_pdata_int(index, 510, restore & ~(1<<0));
308
309 teammsg_block = get_msg_block(g_iMsgShowMenu);
310 teammsg_block_vgui = get_msg_block(g_iMsgVguiMenu);
311
312 set_msg_block(g_iMsgShowMenu, BLOCK_ONCE);
313 set_msg_block(g_iMsgVguiMenu, BLOCK_ONCE);
314
315 engclient_cmd(index, "jointeam", "5");
316 engclient_cmd(index, "joinclass", "5");
317
318 set_msg_block(g_iMsgShowMenu, teammsg_block);
319 set_msg_block(g_iMsgVguiMenu, teammsg_block_vgui);
320
321 if (vgui) set_pdata_int(index, 510, restore);
322}
323public plugin_end() { SQL_FreeHandle(g_tuple); }
324stock ham_strip_weapon(id,weapon[])
325{
326 if(!equal(weapon,"weapon_",7)) return 0;
327
328 new wId = get_weaponid(weapon);
329 if(!wId) return 0;
330
331 new wEnt;
332 while((wEnt = engfunc(EngFunc_FindEntityByString,wEnt,"classname",weapon)) && pev(wEnt,pev_owner) != id) {}
333 if(!wEnt) return 0;
334
335 if(get_user_weapon(id) == wId) ExecuteHamB(Ham_Weapon_RetireWeapon,wEnt);
336
337 if(!ExecuteHamB(Ham_RemovePlayerItem,id,wEnt)) return 0;
338 ExecuteHamB(Ham_Item_Kill,wEnt);
339
340 set_pev(id,pev_weapons,pev(id,pev_weapons) & ~(1<<wId));
341
342 // this block should be used for Counter-Strike:
343 if(wId == CSW_C4)
344 {
345 cs_set_user_plant(id,0,0);
346 cs_set_user_bpammo(id, CSW_C4 ,0);
347 }
348 else if(wId == CSW_SMOKEGRENADE || wId == CSW_FLASHBANG || wId == CSW_HEGRENADE)
349 cs_set_user_bpammo(id,wId,0);
350
351 return 1;
352}
353stock Color(const id, const Text[ ], any:... ) {
354
355 new count = 1, players[32];
356 static msg[191], len, i;
357
358 len = formatex( msg, charsmax(msg), "!g[Knife Mod]!y ");
359 vformat(msg[len], 190 - len, Text, 3);
360
361 replace_all(msg, 190, "!g", "^4" );
362 replace_all(msg, 190, "!y", "^1" );
363 replace_all(msg, 190, "!t", "^3" );
364
365 static iLen = sizeof( msg );
366
367 replace_all(msg, iLen, "á", "á");
368 replace_all(msg, iLen, "Á", "Ã");
369 replace_all(msg, iLen, "é", "é");
370 replace_all(msg, iLen, "É", "É");
371 replace_all(msg, iLen, "í", "Ã*");
372 replace_all(msg, iLen, "Í", "Ã");
373 replace_all(msg, iLen, "ó", "ó");
374 replace_all(msg, iLen, "Ó", "Ó");
375 replace_all(msg, iLen, "ú", "ú");
376 replace_all(msg, iLen, "Ú", "Ú");
377 replace_all(msg, iLen, "ñ", "ñ");
378 replace_all(msg, iLen, "Ñ", "Ñ");
379
380 if(id)
381 players[ 0 ] = id;
382 else
383 get_players(players, count, "ch");
384
385 for(i = 0; i < count; ++i) {
386 if( is_user_connected(players[i]))
387 writeMessage(players[i], msg);
388 }
389}
390stock writeMessage( player, message[ ] ) {
391 message_begin(MSG_ONE, get_user_msgid("SayText"), { 0, 0, 0 }, player);
392 write_byte(player);
393 write_string(message);
394 message_end();
395}