#include <amxmodx>
#include <hamsandwich>
#include <fakemeta_util>
const iMoney = 115;
const iMenu = 205;
const iTeam = 114;
const idRifleMenu = 6;
const idNoMenu = 0;
const OFFSET_LINUX_WEAPONS = 4;
const OFFSET_WEAPONID = 43;
#define MAX_PLAYERS 32
#define get_menuid(%0) get_pdata_int(%0, iMenu)
#define fm_get_user_team(%0) ETEAMS:get_pdata_int(%0, iTeam)
#define fm_get_weaponid(%0) get_pdata_int(%0, OFFSET_WEAPONID, OFFSET_LINUX_WEAPONS)
#define fm_get_user_money(%0) get_pdata_int(%0 , iMoney)
#define IsPlayer(%0) (0 < %0 < 33)
public plugin_init(){
register_plugin("Item AutoSnipers/Shield Off", "1.0", "Fenix & PAffAEJIkA :3");
register_logevent("EventRoundStart", 2, "1=Round_Start");
register_logevent("EventRestartRound", 2, "1&Restart_Round_");
register_menucmd(register_menuid("BuyRifle", true), (1<<4|1<<5), "BuyRifle_Handle");
register_clcmd("menuselect", "MenuSelect");
register_clcmd("sg550", "Sg550Buy");
register_clcmd("g3sg1", "G3sg1Buy");
register_clcmd("shield", "ShieldBuy");
RegisterHam(Ham_AddPlayerItem, "player", "AddItem");
RegisterHam(Ham_RemovePlayerItem, "player", "RemoveItem");
RegisterHam(Ham_Spawn, "player", "SpawnPlayer", true);
}
enum ETEAMS {TEAM_TERRORIST = 1, TEAM_CT, TEAM_SPECTATOR};
enum {SG550_NONE = 0, G3SG1_NONE = 0, SHIELD_NONE = 0, SG550_BUY, G3SG1_BUY, SHIELD_BUY, SG550_PICK_UP, G3SG1_PICK_UP, SHIELD_PICK_UP};
new gBuy = true;
new sSg550[ETEAMS: TEAM_SPECTATOR], sG3sg1[ETEAMS: TEAM_SPECTATOR], gSg550[MAX_PLAYERS + 1], gG3sg1[MAX_PLAYERS + 1], sShield[ETEAMS: TEAM_SPECTATOR], gShield[MAX_PLAYERS + 1], ETEAMS: gTeam[MAX_PLAYERS + 1];
public client_disconnected(id) if(IsPlayer(id)) minus_item(id);
public EventRestartRound(){
sSg550[TEAM_CT] = 0;
sSg550[TEAM_TERRORIST] = 0;
sG3sg1[TEAM_CT] = 0;
sG3sg1[TEAM_TERRORIST] = 0;
sShield[TEAM_CT] = 0;
sShield[TEAM_TERRORIST] = 0;
arrayset(gSg550, SG550_NONE, sizeof gSg550);
arrayset(gG3sg1, G3SG1_NONE, sizeof gG3sg1);
arrayset(gShield, SHIELD_NONE, sizeof gShield);
}
public EventRoundStart() gBuy = true;
public SpawnPlayer(id){
if(!is_user_alive(id))
return HAM_IGNORED;
gTeam[id] = fm_get_user_team(id);
return HAM_IGNORED;
}
public AddItem(id, wId){
if(fm_get_weaponid(wId) != CSW_SG550)
return HAM_IGNORED;
if(fm_get_weaponid(wId) != CSW_G3SG1)
return HAM_IGNORED;
if(fm_get_weaponid(wId) != 38)
return HAM_IGNORED;
if(!check_item(id, SG550_PICK_UP))
set_task(0.1, "delitem", id);
if(!check_item(id, G3SG1_PICK_UP))
set_task(0.1, "delitem", id);
if(!check_item(id, SHIELD_PICK_UP))
set_task(0.1, "delitem", id);
return HAM_IGNORED;
}
public delitem(id){
fm_strip_user_gun(id, CSW_SG550);
fm_strip_user_gun(id, CSW_G3SG1);
fm_strip_user_gun(id, 38);
}
public RemoveItem(id, iEnt){
if(fm_get_weaponid(iEnt) == CSW_SG550)
minus_item(id);
if(fm_get_weaponid(iEnt) == CSW_G3SG1)
minus_item(id);
if(fm_get_weaponid(iEnt) == 38)
minus_item(id);
}
public BuyRifle_Handle(id, key){
if(key != (gTeam[id] == TEAM_TERRORIST ? 4 : 5))
return PLUGIN_CONTINUE;
set_task(0.1, "fix_menu", id);
if(!check_item(id, SG550_BUY))
return PLUGIN_HANDLED;
if(!check_item(id, G3SG1_BUY))
return PLUGIN_HANDLED;
if(!check_item(id, SHIELD_BUY))
return PLUGIN_HANDLED;
return PLUGIN_CONTINUE;
}
public MenuSelect(id){
if(get_menuid(id) != idRifleMenu)
return PLUGIN_CONTINUE;
new szSlot[3], Slot;
read_argv(true, szSlot, charsmax(szSlot));
Slot = str_to_num(szSlot);
if(Slot != (gTeam[id] == TEAM_TERRORIST ? 5 : 6))
return PLUGIN_CONTINUE;
set_task(0.1, "fix_menu", id);
if(!check_item(id, SG550_BUY))
return PLUGIN_HANDLED;
if(!check_item(id, G3SG1_BUY))
return PLUGIN_HANDLED;
if(!check_item(id, SHIELD_BUY))
return PLUGIN_HANDLED;
return PLUGIN_CONTINUE;
}
public fix_menu(id)
set_pdata_int(id, iMenu, idNoMenu);
public Sg550Buy(id){
if(!check_item(id, SG550_BUY))
return PLUGIN_HANDLED;
return PLUGIN_CONTINUE;
}
public G3sg1Buy(id){
if(!check_item(id, G3SG1_BUY))
return PLUGIN_HANDLED;
return PLUGIN_CONTINUE;
}
public ShieldBuy(id){
if(!check_item(id, SHIELD_BUY))
return PLUGIN_HANDLED;
return PLUGIN_CONTINUE;
}
check_item(id, type){
if(gSg550[id] != SG550_NONE || !is_user_valid(id) || !is_user_alive(id))
return true;
if(gG3sg1[id] != G3SG1_NONE || !is_user_valid(id) || !is_user_alive(id))
return true;
if(gG3sg1[id] != SHIELD_NONE || !is_user_valid(id) || !is_user_alive(id))
return true;
if(!gBuy && type == SG550_BUY)
return false;
if(!gBuy && type == G3SG1_BUY)
return false;
if(!gBuy && type == SHIELD_BUY)
return false;
new gMoney = fm_get_user_money(id), SG550_COST = 4200;
if(gMoney < SG550_COST && type == SG550_BUY)
return false;
new G3SG1_COST = 5000;
if(gMoney < G3SG1_COST && type == G3SG1_BUY)
return false;
new SHIELD_COST = 2200;
if(gMoney < SHIELD_COST && type == SHIELD_BUY)
return false;
gSg550[id] = type;
gG3sg1[id] = type;
gShield[id] = type;
gSg550[id] = SG550_NONE;
gG3sg1[id] = G3SG1_NONE;
gShield[id] = SHIELD_NONE;
return false;
}
minus_item(id){
if(!is_user_valid(id) || gSg550[id] == SG550_NONE)
return;
if(!is_user_valid(id) || gG3sg1[id] == G3SG1_NONE)
return;
if(!is_user_valid(id) || gShield[id] == SHIELD_NONE)
return;
gSg550[id] = SG550_NONE;
gG3sg1[id] = G3SG1_NONE;
gShield[id] = SHIELD_NONE;
sSg550[gTeam[id]] --;
sG3sg1[gTeam[id]] --;
sShield[gTeam[id]] --;
}
is_user_valid(id){
if(is_user_bot(id)) return false;
if(is_user_hltv(id)) return false;
return true;
}