#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <colorchat>
#include <fakemeta>
#include <fakemeta_util>
#include <hamsandwich>
#include <engine>
 
new const gszPrefix[]   = "[VIP]^x01"
new const VIP_FLAG[]    = "t" //Flaga Vipa
new const SVIP_FLAG[]   = "n"  //Flaga SVipa
//new const STRAZNIK_FLAG[]   = "r"  //Flaga SVipa
 
new const g_Prefix[] = "Vip Chat"
 
new static PrecacheModels[][] = {
        "models/vip_zwykly_ultra/p_baseball.mdl",
        "models/vip_zwykly_ultra/v_baseball.mdl",
        "models/super_vip_ultra/p_lom.mdl",
        "models/super_vip_ultra/v_lom.mdl"
}
new const MDL_P_PALKA[]  = "models/vip_zwykly_ultra/p_baseball.mdl";
new const MDL_V_PALKA[]  = "models/vip_zwykly_ultra/v_baseball.mdl";
new const MDL_P_LOM[]  = "models/super_vip_ultra/p_lom.mdl";
new const MDL_V_LOM[]  = "models/super_vip_ultra/v_lom.mdl";
 
new Podskok_VIP[33], Podskok_SVIP[33], UserSpam[33], MamFlageVipa[33], MamFlageSvipa[33]
new GetMaxPlayers, PodskokiGr, SPodskokiGr, g_Hudmsg
 
public plugin_precache()
{
        static MDL;
       
        for(MDL=0; MDL<sizeof PrecacheModels; MDL++) engfunc(EngFunc_PrecacheModel, PrecacheModels[MDL]);
}
 
public plugin_init(){
        register_plugin("VIP & SuperVIP", "a", "Author")
 
        register_logevent("Nowa_Runda", 2, "1=Round_Start")
        register_forward(FM_CmdStart, "StartRealCMD")
        register_event("CurWeapon", "event_modele", "be", "1=1")
        RegisterHam(Ham_TakeDamage, "player", "player_damage")
       
        register_clcmd("say /vgcsfghip", "mShowvip")
        register_clcmd("say /sfhjfsgjsthvip", "mShowsvip")
        register_clcmd("say /vips", "pokaz_vip_menu")
        register_clcmd("say /vipy", "pokaz_vip_menu")
         
        register_clcmd("say_team", "VipChat");
                 
        PodskokiGr = register_cvar("vip_max_podskokow", "1")
        SPodskokiGr = register_cvar("svip_max_podskokow", "2")
 
        register_message(get_user_msgid("ScoreAttrib"), "Message_ScoreAttrib")
 
        GetMaxPlayers = get_maxplayers()
               
        register_message(get_user_msgid("SayText"),"handleSayText")
        g_Hudmsg=CreateHudSyncObj()
        register_event("Damage", "damage", "b", "2!0", "3=0", "4!0");
               
        return 0
}
 
public plugin_end() remove_task(616)
 
public client_putinserver(id) {
        UserSpam[id] = 0
}
public client_connect(id) {
        new Name[33]; get_user_name(id, Name, 32)
        UserSpam[id] = 0
 
        if(has_flag(id, VIP_FLAG)) {
                set_hudmessage(255, 0, 0, 0.01, 0.4, 0, 5.0)
                show_hudmessage(0, "Wchodzi VIP: %s", Name)
                return HAM_HANDLED
        }
        else if(has_flag(id, SVIP_FLAG)) {
                set_hudmessage(0, 255, 0, 0.01, 0.4, 0, 5.0)
                show_hudmessage(0, "Wchodzi SVIP: %s", Name)
        }
        return HAM_HANDLED
}
public client_disconnect(id) {
        new Name[33]; get_user_name(id, Name, 32)
        if(has_flag(id, VIP_FLAG)) {
                set_hudmessage(255, 0, 0, 0.01, 0.4, 0, 5.0)
                show_hudmessage(0, "Wychodzi VIP: %s", Name)
                return HAM_HANDLED
        }
        else if(has_flag(id, SVIP_FLAG)) {
                set_hudmessage(0, 255, 0, 0.01, 0.4, 0, 5.0)
                show_hudmessage(0, "Wychodzi SVIP: %s", Name)
        }
        return HAM_HANDLED
}
 
public Nowa_Runda() {
        for(new id = 1; id <= GetMaxPlayers; id++) {
                if(is_user_admin(id) && is_user_connected(id) && is_user_alive(id)) {
                        new nick[32]; get_user_name(id, nick, 31)
 
                        if(has_flag(id, VIP_FLAG))
                        {
                                fm_set_user_health(id, get_user_health(id) + 50)
                                fm_set_user_armor(id, 100)
                                fm_set_nofootsteps(id, 1)
                                ColorChat(id, GREEN, "%s^x03 %s^x01 Dostales(as) darmowy ekwipunek dla^x03 VIP^x01'a!", gszPrefix, nick)
                        }
                        else if(has_flag(id, SVIP_FLAG))
                        {
                                fm_set_user_health(id, get_user_health(id) + 100)
                                fm_set_user_armor(id, 100)
                                fm_set_nofootsteps(id, 1)
                                ColorChat(id, GREEN, "%s^x03 %s^x01 Dostales(as) darmowy ekwipunek dla^x03 SVIP^x01'a!", gszPrefix, nick)
                        }
 
 
                }      
        }
        return HAM_HANDLED
}
public event_modele(id)
{
        switch(get_user_weapon(id))
        {
                case CSW_KNIFE:
                {
                        switch(get_user_team(id))
                        {
                                case 1:
                                {
                                        if(has_flag(id, VIP_FLAG))
                                        {
                                                entity_set_string(id, EV_SZ_viewmodel, MDL_V_PALKA);
                                                entity_set_string(id, EV_SZ_weaponmodel, MDL_P_PALKA);
                                                return HAM_HANDLED;
                                        }
                                        else if (has_flag(id, SVIP_FLAG))
                                        {
                                                entity_set_string(id, EV_SZ_viewmodel, MDL_V_LOM);
                                                entity_set_string(id, EV_SZ_weaponmodel, MDL_P_LOM);
                                                return HAM_HANDLED;
                                        }
                                       
                                }
                        }
                }
        }
        return HAM_HANDLED;
}
public player_damage(this, idinflictor, idattacker, Float:damage, damagebits)
{
        if(!is_user_connected(this) || !is_user_connected(idinflictor)) return HAM_IGNORED;
       
        if(idattacker != 0 && has_flag(idattacker, VIP_FLAG) && is_user_alive(idattacker) && get_user_team(idattacker) != get_user_team(this))
        {
                if(get_user_weapon(idattacker) == CSW_KNIFE)
                {
                        SetHamParamFloat(4, damage*1.6);
                        return HAM_HANDLED;
                }
        }
        else if(idattacker != 0 && has_flag(idattacker, SVIP_FLAG) && is_user_alive(idattacker) && get_user_team(idattacker) != get_user_team(this))
        {
                if(get_user_weapon(idattacker) == CSW_KNIFE)
                {
                        SetHamParamFloat(4, damage*2.4);
                        return HAM_HANDLED;
                }
        }
        return HAM_IGNORED;
}
public StartRealCMD(id, uc_handle) {
        if(is_user_alive(id) && is_user_connected(id) && is_user_admin(id)) {
                new button = get_uc(uc_handle, UC_Buttons)
                new oldbutton = get_user_oldbutton(id)
                new flags = get_entity_flags(id)
 
                if(has_flag(id, VIP_FLAG))
                {
                        if(((button & IN_JUMP) && !(flags & FL_ONGROUND) && !(oldbutton & IN_JUMP) && Podskok_VIP[id] > 0)) {
                                Podskok_VIP[id]--
       
                                new Float:velocity[3]
                                entity_get_vector(id,EV_VEC_velocity, velocity)
                                velocity[2] = random_float(265.0, 285.0)
                                entity_set_vector(id,EV_VEC_velocity, velocity)
                        }
                        else if(flags & FL_ONGROUND) Podskok_VIP[id] = get_pcvar_num(PodskokiGr)
                }
                if(has_flag(id, SVIP_FLAG))
                {
                        if(((button & IN_JUMP) && !(flags & FL_ONGROUND) && !(oldbutton & IN_JUMP) && Podskok_SVIP[id] > 0)) {
                                Podskok_SVIP[id]--
       
                                new Float:velocity[3]
                                entity_get_vector(id,EV_VEC_velocity, velocity)
                                velocity[2] = random_float(265.0, 285.0)
                                entity_set_vector(id,EV_VEC_velocity, velocity)
                        }
                        else if(flags & FL_ONGROUND) Podskok_SVIP[id] = get_pcvar_num(SPodskokiGr)
                }
        }
        else return FMRES_IGNORED
 
        return 0
}

public mShowvip(id)
{      
        if(!is_user_connected(id)) return PLUGIN_HANDLED;
       
        if(is_user_connected(id))
        {
                new menu_vipinfo = menu_create("\rCo otrzymuje VIP?", "menu_vip");
               
                menu_setprop(menu_vipinfo, MPROP_TITLE, "Co otrzymuje VIP?^n- Losowo od 40 do 60hp + kamizelke na start!^n- Dodatkowy Skok^n- Baseball (50% wiecej zadawanych obrazen)^n- Darmowe granaty^n- Bonusy w Ruletce^n- I Wiele wiecej!");
                               
                menu_additem(menu_vipinfo, "Zobacz pelny opis VIP");
                menu_additem(menu_vipinfo, "Jak kupic VIP? - Poradnik");
                menu_additem(menu_vipinfo, "Lista VIP Online");
                menu_setprop(menu_vipinfo, MPROP_BACKNAME, "Poprzednia strona");
                menu_setprop(menu_vipinfo, MPROP_NEXTNAME, "Nastepna strona");
                menu_setprop(menu_vipinfo, MPROP_EXITNAME, "Wyjdz");
                menu_setprop(menu_vipinfo, MPROP_EXIT, MEXIT_ALL);
                menu_display(id, menu_vipinfo);
               
                return PLUGIN_HANDLED;
        }
        return PLUGIN_HANDLED;
}
 
public menu_vip(id, menu, item)
{
        if(!is_user_connected(id) || !is_user_alive(id)) return PLUGIN_HANDLED;
       
        if(item != MENU_EXIT && item != MENU_BACK && item != MENU_MORE)
        {
                switch(item)
                {
                        case 0: show_motd(id, "vip.txt", "Informacje o Vipie")
                        case 1: show_motd(id, "jakvip.txt", "Jak Kupic VIPa?")
                                                case 2: pokaz_vip_menu(id)
                        case 9: return PLUGIN_HANDLED;
                }
        }
        return PLUGIN_HANDLED;
}
 
public mShowsvip(id)
{      
        if(!is_user_connected(id)) return PLUGIN_HANDLED;
       
        if(is_user_connected(id))
        {
                new menu_server = menu_create("\rCo otrzymuje SuperVIP?", "menu_svip");
               
                menu_setprop(menu_server, MPROP_TITLE, "Co otrzymuje SuperVIP?^n- Losowo od 190 do 210hp + Kamizelke na start!^n-Trzy skoki^n- Lom (3x wiecej zadawanych obrazen)^n- Granaty^n- Bonusy w Ruletce^n- I Wiele wiecej!");
                               
                menu_additem(menu_server, "Zobacz pelny opis SuperVIP");
                menu_additem(menu_server, "Jak kupic SuperVIP? - Poradnik");
                menu_additem(menu_server, "Lista VIP Online");
                menu_setprop(menu_server, MPROP_BACKNAME, "Poprzednia strona");
                menu_setprop(menu_server, MPROP_NEXTNAME, "Nastepna strona");
                menu_setprop(menu_server, MPROP_EXITNAME, "Wyjdz");
                menu_setprop(menu_server, MPROP_EXIT, MEXIT_ALL);
                menu_display(id, menu_server);
               
                return PLUGIN_HANDLED;
        }
        return PLUGIN_HANDLED;
}
 
public menu_svip(id, menu, item)
{
        if(!is_user_connected(id) || !is_user_alive(id)) return PLUGIN_HANDLED;
       
        if(item != MENU_EXIT && item != MENU_BACK && item != MENU_MORE)
        {
                switch(item)
                {
                        case 0: show_motd(id, "svip.txt", "Informacje o SVipie")
                        case 1: show_motd(id, "jakvip.txt", "Jak Kupic VIPa?")
                        case 2: pokaz_vip_menu(id)
                        case 9: return PLUGIN_HANDLED;
                }
        }
        return PLUGIN_HANDLED;
}
 
public pokaz_vip_menu(id) {
        new key[128], info[8], Name[33]
        new OnlMenu = menu_create("\yLista VIP Online", "SelectVIPOnline")
       
        for(new i = 1; i <= GetMaxPlayers; i++) {
                if(is_user_connected(i) && is_user_admin(i) && !is_user_bot(i) && !is_user_hltv(i)) {
                        MamFlageVipa[i] = 0
                        MamFlageSvipa[i] = 0
 
                        if(has_flag(i, VIP_FLAG)) {
                                MamFlageSvipa[i] = 6
                                MamFlageVipa[i] = 9
                        }
                        else if(has_flag(i, SVIP_FLAG)) {
                                MamFlageSvipa[i] = 5
                                MamFlageVipa[i] = 8
                        }
                        if(MamFlageSvipa[i] == 6 && MamFlageVipa[i] == 9 ) {
                                get_user_name(i, Name, 32)
                                formatex(info, 7, "%d", i)
                                formatex(key, 127, "\r%s \d[\yVIP\d]", Name)
                                menu_additem(OnlMenu, key, info)
                        }
                        else if(MamFlageSvipa[i] == 5 && MamFlageVipa[i] == 8 ) {
                                get_user_name(i, Name, 32)
                                formatex(info, 7, "%d", i)
                                formatex(key, 127, "\r%s \d[\ySuperVIP\d]", Name)
                                menu_additem(OnlMenu, key, info)
                        }      
                }
        }
        menu_setprop(OnlMenu, MPROP_NUMBER_COLOR, "\w")
        menu_setprop(OnlMenu, MPROP_BACKNAME, "\yPoprzednia strona")
        menu_setprop(OnlMenu, MPROP_NEXTNAME, "\yNastepna strona")
        menu_setprop(OnlMenu, MPROP_EXITNAME, "\rWyjscie")
        menu_setprop(OnlMenu, MPROP_EXIT, MEXIT_ALL)
        menu_display(id, OnlMenu, 0)
        return 1
}
 
public SelectVIPOnline(id, OnlMenu, item) {
        new konto, info[8], name[63], callback
        menu_item_getinfo(OnlMenu, item, konto, info, 7, name, 63, callback)
        new GetID = str_to_num(info)
 
        if(item == MENU_EXIT) {
                ColorChat(id, GREEN, "%s Menu^x04 VIP Online^x01 zamkniete.", gszPrefix)
                menu_destroy(OnlMenu)
                return HAM_HANDLED
        }
        else if((item == MENU_MORE) || (item == MENU_BACK)) return 0
        else {
                new SteamID[35]; get_user_authid(GetID, SteamID, 34)
                new Name[33]; get_user_name(GetID, Name, 32)
 
                if(is_user_connected(GetID)) {
                        ColorChat(id, GREEN, "%s Nick:^x03 %s^x01 Steam:^x03 %s^x01 IP:^x03 (Ukryte)^x01 Zyje:^x03 %s", gszPrefix, Name, (has_user_steam(GetID) ? SteamID : "Brak"), (is_user_alive(GetID) ? "Tak" : "Nie"))
                        AntySpam(id)
                        pokaz_vip_menu(id)
                } else {
                        ColorChat(id, GREEN, "%s Gracz o nicku:^x03 %s^x01 wyszedl z serwera!", gszPrefix, Name)
                        pokaz_vip_menu(id)
                }
        }
        return HAM_HANDLED
}
 
public AntySpam(id) {
        UserSpam[id]++
        set_task(1.0, "KickOff", id+320)
 
        if(UserSpam[id] > 4) {
                new nick[32]; get_user_name(id, nick, 31)
                server_cmd("kick %s **** Przestan spamowac! ****", nick)
                for(new i=1; i<=10; i++) console_print(id, "**** Przestan spamowac! ****")
        }
        return 0
}
 
public Message_ScoreAttrib() {
        if(is_user_admin(get_msg_arg_int(1)))  set_msg_arg_int(2, ARG_BYTE, is_user_alive(get_msg_arg_int(1)) ? (1<<2) : (1<<0))
}
 
public handleSayText(msgId,msgDest,msgEnt){
        new id = get_msg_arg_int(1);
       
        if(is_user_connected(id) && has_flag(id, VIP_FLAG)){
                new szTmp[256],szTmp2[256];
                get_msg_arg_string(2,szTmp, charsmax(szTmp))
               
                new szPrefix[64] = "^x04[VIP]";
               
                if(!equal(szTmp,"#Cstrike_Chat_All")){
                        add(szTmp2,charsmax(szTmp2),szPrefix);
                        add(szTmp2,charsmax(szTmp2)," ");
                        add(szTmp2,charsmax(szTmp2),szTmp);
                }
                else{
                        add(szTmp2,charsmax(szTmp2),szPrefix);
                        add(szTmp2,charsmax(szTmp2),"^x03 %s1^x01 :  %s2");
                }
                set_msg_arg_string(2,szTmp2);
        }
        else if(is_user_connected(id) && has_flag(id, SVIP_FLAG)){
                new szTmp[256],szTmp2[256];
                get_msg_arg_string(2,szTmp, charsmax(szTmp))
               
                new szPrefix[64] = "^x04[SuperVIP]";
               
                if(!equal(szTmp,"#Cstrike_Chat_All")){
                        add(szTmp2,charsmax(szTmp2),szPrefix);
                        add(szTmp2,charsmax(szTmp2)," ");
                        add(szTmp2,charsmax(szTmp2),szTmp);
                }
                else{
                        add(szTmp2,charsmax(szTmp2),szPrefix);
                        add(szTmp2,charsmax(szTmp2),"^x03 %s1^x01 :  %s2");
                }
                set_msg_arg_string(2,szTmp2);
        }
        return PLUGIN_CONTINUE;
}
 
public VipChat(id){
        if(has_flag(id, "ts")){
                new g_Msg[256],
                g_Text[256];
               
                read_args(g_Msg,charsmax(g_Msg));
                remove_quotes(g_Msg);
               
                if(g_Msg[0] == '*' && g_Msg[1]){
                        new g_Name[64];
                        get_user_name(id,g_Name,charsmax(g_Name));
                       
                        formatex(g_Text,charsmax(g_Text),"^x01(%s) ^x03%s : ^x04%s",g_Prefix, g_Name, g_Msg[1]);
                       
                        for(new i=1;i<33;i++){
                                if(is_user_connected(i) && has_flag(i, "ts"))
                                ColorChat(i, GREEN, "%s", g_Text);
                        }
                        return PLUGIN_HANDLED_MAIN;
                }
        }
        return PLUGIN_CONTINUE;
}
 
 // Bullet Damage
public damage(id){
        new attacker=get_user_attacker(id);
        new damage=read_data(2);
       
        if(has_flag(id, "ts")){
                set_hudmessage(255, 0, 0, 0.45, 0.50, 2, 0.1, 4.0, 0.1, 0.1, -1);
                ShowSyncHudMsg(id, g_Hudmsg, "%i^n", damage);
        }
        if(is_user_connected(attacker) && has_flag(attacker, "ts")){
                set_hudmessage(0, 100, 200, -1.0, 0.55, 2, 0.1, 4.0, 0.02, 0.02, -1);
                ShowSyncHudMsg(attacker, g_Hudmsg, "%i^n", damage);
        }
}
 
public client_PreThinkVip(id){
        entity_set_float(id, EV_FL_fuser2, 0.0);
       
        if(entity_get_int(id, EV_INT_button) & 2){
                new flags = entity_get_int(id, EV_INT_flags);
               
                if(flags & FL_WATERJUMP || entity_get_int(id, EV_INT_waterlevel) >= 2 || !(flags & FL_ONGROUND)){
                        return PLUGIN_CONTINUE;
                }
                new Float:velocity[3];
                entity_get_vector(id, EV_VEC_velocity, velocity);
               
                velocity[2] += 250.0;
                entity_set_vector(id, EV_VEC_velocity, velocity);
               
                entity_set_int(id, EV_INT_gaitsequence, 6);
        }
        return PLUGIN_CONTINUE;
}
 
public KickOff(id) {
        id -= 320
 
        UserSpam[id] = 0
        if(task_exists(id+320)) remove_task(id+320)
 
        return HAM_HANDLED
}
 
stock bool:has_user_steam(id) {
        new AuthID[32]; get_user_authid(id, AuthID, 31)
        return containi(AuthID, ":") != -1 ? true : false
}
 
stock fm_get_nofootsteps(index) return pev(index, pev_flTimeStepSound) == 999 ? true : false
stock fm_set_nofootsteps(index, nofootsteps = 0) set_pev(index, pev_flTimeStepSound, nofootsteps ? 999 : 400)