Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <amxmodx>
- #include <hamsandwich>
- #include <engine>
- #include <fakemeta>
- #include <cstrike>
- #include <fun>
- #include <sqlx>
- #define MAX_PLAYERS 32
- #define LevelNext(%1) (%1 * 25)
- #define NivelMax 10
- #define SQLX_DATABASE "dataknifemod"
- const USER_NO_REGISTRADO = -1;
- const USER_REGISTRADO = 0;
- const USER_LOGEADO = 1;
- const TASK_KICK = 987654;
- new g_logeado[33], g_playername[33][32];
- new Handle:g_query, Handle:g_tuple, g_iMsgVguiMenu, g_iMsgShowMenu;
- new gNivel[MAX_PLAYERS+1], gExp[MAX_PLAYERS+1];
- public plugin_init() {
- register_plugin("Knife mod", "1.0.0", "Kross");
- /* CLCMD */
- register_clcmd("REGISTRE_SU_PASSWORD", "REGISTRE_SU_PASSWORD")
- register_clcmd("INGRESA_TU_PASSWORD", "INGRESA_TU_PASSWORD")
- /* FORWARDS */
- register_forward(FM_ClientUserInfoChanged, "fwClientInfoChanged");
- /* HAMS */
- RegisterHam(Ham_Spawn, "player", "HamSpawn", true);
- RegisterHam(Ham_Killed, "player", "hamPlayerKilled", true);
- /* MESSAGE */
- register_message(get_user_msgid("StatusIcon"), "message_statusicon")
- g_iMsgVguiMenu = get_user_msgid("VGUIMenu");
- g_iMsgShowMenu = get_user_msgid("ShowMenu");
- register_message(g_iMsgVguiMenu, "message_VGUImenu");
- register_message(g_iMsgShowMenu, "message_VGUImenu");
- SQLXInit()
- }
- public client_putinserver(id) {
- get_user_name(id, g_playername[id], charsmax(g_playername[]))
- set_task(0.1, "ShowHUD", id, _, _, "b")
- set_task(50.0, "taskKickPlayer", id + TASK_KICK);
- g_logeado[id] = USER_NO_REGISTRADO
- g_query = SQL_PrepareQuery(g_tuple, "SELECT Nombre FROM 'Cuentas' WHERE Nombre = ^"%s^"", g_playername[id]);
- if (SQL_Execute(g_query)) {
- if (SQL_NumResults(g_query)) g_logeado[id] = USER_REGISTRADO
- }
- gNivel[id] = 1;
- gExp[id] = 0;
- }
- public client_disconnect(id) {
- if(task_exists(id)) { remove_task(id); }
- remove_task(id + TASK_KICK);
- Guardar(id);
- }
- public HamSpawn(const id) {
- if(!is_user_alive(id)) return;
- set_task(0.1, "check", id)
- }
- public hamPlayerKilled(victim, attacker, sg) {
- if(!is_user_connected(victim) || !is_user_connected(attacker) || !attacker || attacker == victim) return HAM_IGNORED;
- if(gNivel[attacker] == NivelMax) {
- client_print(attacker, print_chat, "No ganas exp estas en tu nivel maximo, hace un resets.")
- return HAM_IGNORED;
- }
- /* SI LA VICTIMA MUERE POR HS LE DA AL ATACANTE 4 de exp */
- if(get_pdata_int(victim, 75, 5) == HIT_HEAD) {
- Subir(attacker, 4);
- }
- else {
- Subir(attacker, 2);
- }
- return HAM_IGNORED;
- }
- public fwClientInfoChanged(id, buffer) {
- if(!is_user_connected(id)) return FMRES_IGNORED;
- if(!(g_logeado[id] == USER_LOGEADO)) return FMRES_IGNORED;
- static OldName[33];
- engfunc(EngFunc_InfoKeyValue, buffer, "name", OldName, sizeof OldName - 1);
- if(equal(OldName, g_playername[id])) return FMRES_IGNORED;
- set_user_info(id, "name", g_playername[id]);
- client_cmd(id, "setinfo ^"name^" ^"%s^"", g_playername[id]);
- return FMRES_IGNORED;
- }
- public message_VGUImenu(msgid, dest, index) {
- if(g_logeado[index] != USER_LOGEADO) {
- show_menu_registro(index);
- return PLUGIN_HANDLED;
- }
- return PLUGIN_CONTINUE;
- }
- public message_statusicon(msg_id, msg_dest, id) {
- static szIcon[8]
- get_msg_arg_string(2, szIcon, charsmax(szIcon))
- if(equal(szIcon, "buyzone") && get_msg_arg_int(1)) {
- set_pdata_int(id, 235, get_pdata_int(id, 235) & ~(1<<0))
- return PLUGIN_HANDLED;
- }
- return PLUGIN_CONTINUE;
- }
- public taskKickPlayer(id) {
- id -= TASK_KICK;
- server_cmd("kick #%d ^"Has sido expulsado por no ingresar!^"", get_user_userid(id));
- }
- public ShowHUD(id) {
- if(!is_user_alive(id)) return;
- set_hudmessage(0, 255, 255, 0.0, 0.20, 1, 6.0, 1.0);
- 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]))
- }
- Subir(id, ammo) {
- gExp[id] += ammo;
- new iUploaded = false;
- while(gExp[id] >= LevelNext(gNivel[id]) && gNivel[id] < NivelMax) {
- ++gNivel[id];
- iUploaded = true;
- }
- if(iUploaded) {
- client_print( id, print_chat, "Felicidades subiste al nivel: %d.", gNivel[id]);
- iUploaded = false;
- }
- }
- public check(id) {
- strip_user_weapons(id);
- give_item(id, "weapon_knife");
- if(user_has_weapon(id, CSW_C4)) { ham_strip_weapon(id, "weapon_c4"); }
- }
- public REGISTRE_SU_PASSWORD(id) {
- if(g_logeado[id] != USER_NO_REGISTRADO) return
- static szArg[192]; read_args(szArg, 191);
- remove_quotes(szArg); trim(szArg);
- if(equal(szArg, "")) {
- client_cmd(id, "messagemode REGISTRE_SU_PASSWORD");
- client_cmd(id, "spk ^"buttons/button11.wav^"");
- client_print(id, print_center, "No has introducido una password.");
- return;
- }
- if(contain(szArg, " ") != -1) {
- client_cmd(id, "messagemode REGISTRE_SU_PASSWORD");
- client_cmd(id, "spk ^"buttons/button11.wav^"");
- client_print(id, print_center, "La password tiene que contener una palabra.");
- return;
- }
- if (containi(szArg, "^"") != -1) {
- client_cmd(id, "messagemode REGISTRE_SU_PASSWORD");
- client_cmd(id, "spk ^"buttons/button11.wav^"");
- client_print(id, print_center, "No puedes usar comillas")
- return;
- }
- g_query = SQL_PrepareQuery(g_tuple, "INSERT INTO 'Cuentas' (Nombre, Password) VALUES (^"%s^", ^"%s^")", g_playername[id], szArg)
- if (SQL_Execute(g_query)) {
- g_logeado[id] = USER_LOGEADO
- ForceJoinTeam(id)
- client_print(id, print_center, "Te has registrado correctamente!")
- }
- else {
- client_cmd(id, "spk ^"buttons/button11.wav^"");
- client_print(id, print_center, "Error al registrarte :(")
- }
- }
- public INGRESA_TU_PASSWORD(id) {
- if(g_logeado[id] != USER_REGISTRADO) return
- static szArg[192]; read_args(szArg, 191);
- remove_quotes(szArg); trim(szArg);
- if(equal(szArg, "")) {
- client_cmd(id, "messagemode INGRESA_TU_PASSWORD");
- client_cmd(id, "spk ^"buttons/button11.wav^"");
- client_print(id, print_center, "No has introducido una password.");
- return;
- }
- if(contain(szArg, " ") != -1) {
- client_cmd(id, "messagemode INGRESA_TU_PASSWORD");
- client_cmd(id, "spk ^"buttons/button11.wav^"");
- client_print(id, print_center, "La password tiene que contener una palabra.");
- return;
- }
- if (containi(szArg, "^"") != -1) {
- client_print(id, print_center, "No puedes usar comillas")
- client_cmd(id, "spk ^"buttons/button11.wav^"");
- client_cmd(id, "messagemode INGRESA_TU_PASSWORD")
- return;
- }
- g_query = SQL_PrepareQuery(g_tuple, "SELECT Password, Nivel, Exp FROM 'Cuentas' WHERE Nombre = ^"%s^"", g_playername[id]);
- if(SQL_Execute(g_query)) {
- static szPass[192]; SQL_ReadResult(g_query, 0, szPass, 191);
- if (equal(szPass, szArg)) {
- gNivel[id] = SQL_ReadResult(g_query, 1);
- gExp[id] = SQL_ReadResult(g_query, 2);
- g_logeado[id] = USER_LOGEADO
- ForceJoinTeam(id);
- client_print(id, print_center, "Te has logeado correctamente!")
- }
- else {
- client_cmd(id, "messagemode INGRESA_TU_PASSWORD")
- client_print(id, print_center, "Password incorrecta")
- }
- }
- else {
- client_cmd(id, "spk ^"buttons/button11.wav^"");
- client_print(id, print_center, "Error al logearte :(")
- }
- }
- public show_menu_registro(id) {
- if(g_logeado[id] == USER_LOGEADO) return PLUGIN_CONTINUE;
- static text[299];
- 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");
- new menu = menu_create(text, "Handler")
- menu_additem(menu, (g_logeado[id] == USER_NO_REGISTRADO) ? "\wCrear \ycuenta" : "\dCrear cuenta", "1")
- menu_additem(menu, (g_logeado[id] == USER_REGISTRADO) ? "\wIniciar \ysesion^n" : "\dIniciar sesion^n", "2")
- menu_additem(menu, "\wDesconectarse^n^n\dSi no te registras/logueas en \r1 minuto\d seras kickeado.", "3");
- menu_setprop(menu, MPROP_EXIT, MEXIT_NEVER)
- menu_display(id, menu)
- return PLUGIN_HANDLED;
- }
- public Handler(id, menu, item) {
- switch (item) {
- case 0: {
- if(g_logeado[id] == USER_REGISTRADO) {
- show_menu_registro(id);
- Color(id, "Ya tienes una cuenta registrada en la !tbase de datos!y.");
- return PLUGIN_HANDLED;
- }
- client_cmd(id, "messagemode REGISTRE_SU_PASSWORD")
- client_print(id, print_center, "Elije una password para tu cuenta")
- }
- case 1: {
- if(g_logeado[id] == USER_NO_REGISTRADO) {
- show_menu_registro(id);
- Color(id, "No tienes una cuenta registrada en la !tbase de datos!y.");
- return PLUGIN_HANDLED;
- }
- client_cmd(id, "messagemode INGRESA_TU_PASSWORD")
- client_print(id, print_center, "Ingresa la password de tu cuenta")
- }
- case 2: {
- client_cmd(id, "disconnect")
- }
- }
- menu_destroy(menu)
- return PLUGIN_HANDLED;
- }
- public Guardar(id) {
- if(g_logeado[id] != USER_LOGEADO) return;
- g_query = SQL_PrepareQuery(g_tuple, "UPDATE 'Cuentas' SET Nivel='%d', Exp='%d' WHERE Nombre = ^"%s^"", gNivel[id], gExp[id], g_playername[id])
- SQL_Execute(g_query)
- }
- public CheckTabla() {
- g_query = SQL_PrepareQuery
- (
- g_tuple,
- "CREATE TABLE IF NOT EXISTS 'Cuentas' \
- ( \
- Nombre varchar(33) NOT NULL default '' PRIMARY KEY, \
- Password varchar(192) NOT NULL default '', \
- Nivel int NOT NULL default '1', \
- Exp int NOT NULL DEFAULT '0' \
- )"
- )
- SQL_Execute(g_query)
- }
- public SQLXInit() {
- new get_type[12];
- SQL_SetAffinity("sqlite")
- SQL_GetAffinity(get_type, sizeof(get_type))
- if (!equali(get_type, "sqlite")) {
- log_to_file("SQLX.log", "Driver no encontrado");
- pause("a");
- }
- else {
- static error, szError[300];
- g_query = SQL_MakeDbTuple("", "", "", SQLX_DATABASE)
- g_tuple = SQL_Connect(g_query, error, szError, 300)
- if(strlen(szError)) {
- log_to_file("ErrorSQL.log", szError)
- pause("a")
- }
- CheckTabla()
- }
- }
- ForceJoinTeam(index)
- {
- static teammsg_block, teammsg_block_vgui, restore, vgui;
- restore = get_pdata_int(index, 510);
- vgui = restore & (1<<0);
- if (vgui) set_pdata_int(index, 510, restore & ~(1<<0));
- teammsg_block = get_msg_block(g_iMsgShowMenu);
- teammsg_block_vgui = get_msg_block(g_iMsgVguiMenu);
- set_msg_block(g_iMsgShowMenu, BLOCK_ONCE);
- set_msg_block(g_iMsgVguiMenu, BLOCK_ONCE);
- engclient_cmd(index, "jointeam", "5");
- engclient_cmd(index, "joinclass", "5");
- set_msg_block(g_iMsgShowMenu, teammsg_block);
- set_msg_block(g_iMsgVguiMenu, teammsg_block_vgui);
- if (vgui) { set_pdata_int(index, 510, restore); }
- remove_task(index + TASK_KICK);
- }
- public plugin_end() { SQL_FreeHandle(g_tuple); }
- stock ham_strip_weapon(id,weapon[])
- {
- if(!equal(weapon,"weapon_",7)) return 0;
- new wId = get_weaponid(weapon);
- if(!wId) return 0;
- new wEnt;
- while((wEnt = engfunc(EngFunc_FindEntityByString,wEnt,"classname",weapon)) && pev(wEnt,pev_owner) != id) {}
- if(!wEnt) return 0;
- if(get_user_weapon(id) == wId) ExecuteHamB(Ham_Weapon_RetireWeapon,wEnt);
- if(!ExecuteHamB(Ham_RemovePlayerItem,id,wEnt)) return 0;
- ExecuteHamB(Ham_Item_Kill,wEnt);
- set_pev(id,pev_weapons,pev(id,pev_weapons) & ~(1<<wId));
- // this block should be used for Counter-Strike:
- if(wId == CSW_C4)
- {
- cs_set_user_plant(id,0,0);
- cs_set_user_bpammo(id, CSW_C4 ,0);
- }
- else if(wId == CSW_SMOKEGRENADE || wId == CSW_FLASHBANG || wId == CSW_HEGRENADE)
- cs_set_user_bpammo(id,wId,0);
- return 1;
- }
- stock Color(const id, const Text[ ], any:... ) {
- new count = 1, players[32];
- static msg[191], len, i;
- len = formatex( msg, charsmax(msg), "!g[Knife Mod]!y ");
- vformat(msg[len], 190 - len, Text, 3);
- replace_all(msg, 190, "!g", "^4" );
- replace_all(msg, 190, "!y", "^1" );
- replace_all(msg, 190, "!t", "^3" );
- static iLen = sizeof( msg );
- replace_all(msg, iLen, "á", "á");
- replace_all(msg, iLen, "Á", "Ã");
- replace_all(msg, iLen, "é", "é");
- replace_all(msg, iLen, "É", "É");
- replace_all(msg, iLen, "í", "Ã*");
- replace_all(msg, iLen, "Í", "Ã");
- replace_all(msg, iLen, "ó", "ó");
- replace_all(msg, iLen, "Ó", "Ó");
- replace_all(msg, iLen, "ú", "ú");
- replace_all(msg, iLen, "Ú", "Ú");
- replace_all(msg, iLen, "ñ", "ñ");
- replace_all(msg, iLen, "Ñ", "Ñ");
- if(id)
- players[ 0 ] = id;
- else
- get_players(players, count, "ch");
- for(i = 0; i < count; ++i) {
- if( is_user_connected(players[i]))
- writeMessage(players[i], msg);
- }
- }
- stock writeMessage( player, message[ ] ) {
- message_begin(MSG_ONE, get_user_msgid("SayText"), { 0, 0, 0 }, player);
- write_byte(player);
- write_string(message);
- message_end();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement