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