Advertisement
Guest User

Untitled

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