Advertisement
Guest User

Untitled

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