Advertisement
Guest User

Untitled

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