PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
#include <hamsandwich>
#include <xs>
#tryinclude "menu.cfg"
#if !defined _menucfg_included
#assert Menu configuration file required!
#elseif AMXX_VERSION_NUM < 180
#assert AMX Mod X v1.8.0 or greater required!
#endif
#define OFFSET_TEAM 114
#define OFFSET_ARMOR 112
#define OFFSET_CSMONEY 115
#define OFFSET_PRIMARYWEAPON 116
#define OFFSET_WEAPONTYPE 43
#define OFFSET_CLIPAMMO 51
#define EXTRAOFFSET_WEAPONS 4
#define OFFSET_LASTPRIM 368
#define OFFSET_AMMO_338MAGNUM 377
#define OFFSET_AMMO_762NATO 378
#define OFFSET_AMMO_556NATOBOX 379
#define OFFSET_AMMO_556NATO 380
#define OFFSET_AMMO_BUCKSHOT 381
#define OFFSET_AMMO_45ACP 382
#define OFFSET_AMMO_57MM 383
#define OFFSET_AMMO_50AE 384
#define OFFSET_AMMO_357SIG 385
#define OFFSET_AMMO_9MM 386
#define OFFSET_LASTSEC 369
#define TASKID_INITROUND 222
#define TASKID_STARTROUND 153
#define TASKID_BALANCETEAM 375
#define TASKID_WEAPONSMENU 564
#define TASKID_SPAWNDELAY 786
#define EQUIP_PRI (1<<0)
#define EQUIP_SEC (1<<1)
#define EQUIP_GREN (1<<2)
#define EQUIP_ALL (1<<0 | 1<<1 | 1<<2)
#define _random(%1) random_num(0, %1 - 1)
#define fm_get_user_team(%1) get_pdata_int(%1, OFFSET_TEAM)
#define fm_get_user_money(%1) get_pdata_int(%1, OFFSET_CSMONEY)
#define fm_get_weapon_id(%1) get_pdata_int(%1, OFFSET_WEAPONTYPE, EXTRAOFFSET_WEAPONS)
#define fm_get_weapon_ammo(%1) get_pdata_int(%1, OFFSET_CLIPAMMO, EXTRAOFFSET_WEAPONS)
#define fm_set_weapon_ammo(%1,%2) set_pdata_int(%1, OFFSET_CLIPAMMO, %2, EXTRAOFFSET_WEAPONS)
#define fm_lastprimary(%1) get_pdata_cbase(id, OFFSET_LASTPRIM)
#define fm_lastsecondry(%1) get_pdata_cbase(id, OFFSET_LASTSEC)
new const g_weapon_ammo[][] =
{
{ -1, -1 },
{ 13, 52 },
{ -1, -1 },
{ 10, 90 },
{ -1, -1 },
{ 7, 32 },
{ -1, -1 },
{ 30, 100 },
{ 30, 90 },
{ -1, -1 },
{ 30, 120 },
{ 20, 100 },
{ 25, 100 },
{ 30, 90 },
{ 35, 90 },
{ 25, 90 },
{ 12, 100 },
{ 20, 120 },
{ 10, 30 },
{ 30, 120 },
{ 100, 200 },
{ 8, 32 },
{ 30, 90 },
{ 30, 120 },
{ 20, 90 },
{ -1, -1 },
{ 7, 35 },
{ 30, 90 },
{ 30, 90 },
{ -1, -1 },
{ 50, 100 }
}
enum
{
MAX_CLIP = 0,
MAX_AMMO
}
enum
{
MENU_PRIMARY = 1,
MENU_SECONDARY
}
enum
{
CS_TEAM_UNASSIGNED = 0,
CS_TEAM_T,
CS_TEAM_CT,
CS_TEAM_SPECTATOR
}
new cvar_weaponsmenu, cvar_enabled
new bool:g_showmenu[33], bool:g_menufailsafe[33], g_player_weapons[33][2], g_menuposition[33], g_maxplayers
new bool:g_roundstarted
public plugin_init()
{
register_plugin("Menu", "0", "KIL & kam1kadze")
register_dictionary("menu.txt")
cvar_enabled = register_cvar("bh_enabled", "1")
cvar_weaponsmenu = register_cvar("bh_weaponsmenu", "1")
if(!get_pcvar_num(cvar_enabled))
return
register_clcmd("say /guns", "cmd_enablemenu")
register_menu("Equipment", 1023, "action_equip")
register_menu("Primary", 1023, "action_prim")
register_menu("Secondary", 1023, "action_sec")
g_maxplayers = get_maxplayers()
}
public client_connect(id)
{
g_showmenu[id] = true
g_player_weapons[id][0] = -1
g_player_weapons[id][1] = -1
g_menufailsafe[id] = false
}
public client_disconnect(id)
{
remove_task(TASKID_WEAPONSMENU + id)
}
public logevent_round_start()
{
g_roundstarted = true
if(get_pcvar_num(cvar_weaponsmenu))
{
static id, team
for(id = 1; id <= g_maxplayers; id++) if(is_user_alive(id))
{
team = fm_get_user_team(id)
if(team == CS_TEAM_T || team == CS_TEAM_CT)
{
if(g_showmenu[id])
{
add_delay(id, "display_equipmenu")
g_menufailsafe[id] = true
set_task(10.0, "task_weaponsmenu", TASKID_WEAPONSMENU + id)
}
else
equipweapon(id, EQUIP_ALL)
}
}
}
}
public task_spawned(taskid)
{
static id
id = taskid - TASKID_SPAWNDELAY
if(is_user_alive(id))
{
if(get_pcvar_num(cvar_weaponsmenu) && g_roundstarted && g_showmenu[id])
display_equipmenu(id)
}
}
public task_weaponsmenu(taskid)
{
static id
id = taskid - TASKID_WEAPONSMENU
if(is_user_alive(id) && g_menufailsafe[id])
display_equipmenu(id)
}
public display_equipmenu(id)
{
static menubody[512], len
len = formatex(menubody, 511, "\y%L^n^n", id, "MENU_TITLE1")
static bool:hasweap
hasweap = ((g_player_weapons[id][0]) != -1 && (g_player_weapons[id][1] != -1)) ? true : false
len += formatex(menubody[len], 511 - len,"\w1. %L^n", id, "MENU_NEWWEAPONS")
len += formatex(menubody[len], 511 - len,"%s2. %L^n", hasweap ? "\w" : "\d", id, "MENU_PREVSETUP")
len += formatex(menubody[len], 511 - len,"%s3. %L^n^n", hasweap ? "\w" : "\d", id, "MENU_DONTSHOW")
len += formatex(menubody[len], 511 - len,"\w5. %L^n", id, "MENU_EXIT")
static keys
keys = (MENU_KEY_1|MENU_KEY_5)
if(hasweap)
keys |= (MENU_KEY_2|MENU_KEY_3)
show_menu(id, keys, menubody, -1, "Equipment")
}
public action_equip(id, key)
{
if(!is_user_alive(id))
return PLUGIN_HANDLED
switch(key)
{
case 0: display_weaponmenu(id, MENU_PRIMARY, g_menuposition[id] = 0)
case 1: equipweapon(id, EQUIP_ALL)
case 2:
{
g_showmenu[id] = false
equipweapon(id, EQUIP_ALL)
client_print(id, print_chat, "%L", id, "MENU_CMDENABLE")
}
}
if(key > 0)
{
g_menufailsafe[id] = false
remove_task(TASKID_WEAPONSMENU + id)
}
return PLUGIN_HANDLED
}
public display_weaponmenu(id, menuid, pos)
{
if(pos < 0 || menuid < 0)
return
static start
start = pos * 8
static maxitem
maxitem = menuid == MENU_PRIMARY ? sizeof g_primaryweapons : sizeof g_secondaryweapons
if(start >= maxitem)
start = pos = g_menuposition[id]
static menubody[512], len
len = formatex(menubody, 511, "\y%L\w^n^n", id, menuid == MENU_PRIMARY ? "MENU_TITLE2" : "MENU_TITLE3")
static end
end = start + 8
if(end > maxitem)
end = maxitem
static keys
keys = MENU_KEY_0
static a, b
b = 0
for(a = start; a < end; ++a)
{
keys |= (1<<b)
len += formatex(menubody[len], 511 - len,"%d. %s^n", ++b, menuid == MENU_PRIMARY ? g_primaryweapons[a][0]: g_secondaryweapons[a][0])
}
if(end != maxitem)
{
formatex(menubody[len], 511 - len, "^n9. %L^n0. %L", id, "MENU_MORE", id, pos ? "MENU_BACK" : "MENU_EXIT")
keys |= MENU_KEY_9
}
else
formatex(menubody[len], 511 - len, "^n0. %L", id, pos ? "MENU_BACK" : "MENU_EXIT")
show_menu(id, keys, menubody, -1, menuid == MENU_PRIMARY ? "Primary" : "Secondary")
}
public action_prim(id, key)
{
if(!is_user_alive(id))
return PLUGIN_HANDLED
switch(key)
{
case 8: display_weaponmenu(id, MENU_PRIMARY, ++g_menuposition[id])
case 9: display_weaponmenu(id, MENU_PRIMARY, --g_menuposition[id])
default:
{
g_player_weapons[id][0] = g_menuposition[id] * 8 + key
equipweapon(id, EQUIP_PRI)
display_weaponmenu(id, MENU_SECONDARY, g_menuposition[id] = 0)
}
}
return PLUGIN_HANDLED
}
public action_sec(id, key)
{
if(!is_user_alive(id))
return PLUGIN_HANDLED
switch(key)
{
case 8: display_weaponmenu(id, MENU_SECONDARY, ++g_menuposition[id])
case 9: display_weaponmenu(id, MENU_SECONDARY, --g_menuposition[id])
default:
{
g_menufailsafe[id] = false
remove_task(TASKID_WEAPONSMENU + id)
g_player_weapons[id][1] = g_menuposition[id] * 8 + key
equipweapon(id, EQUIP_SEC)
equipweapon(id, EQUIP_GREN)
}
}
return PLUGIN_HANDLED
}
stock fm_strip_user_weapons(index)
{
static stripent
if(!pev_valid(stripent))
{
stripent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "player_weaponstrip"))
dllfunc(DLLFunc_Spawn, stripent), set_pev(stripent, pev_solid, SOLID_NOT)
}
dllfunc(DLLFunc_Use, stripent, index)
return 1
}
stock bacon_give_weapon(index, weapon[])
{
if(!equal(weapon,"weapon_", 7))
return 0
static ent
ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, weapon))
if(!pev_valid(ent))
return 0
set_pev(ent, pev_spawnflags, SF_NORESPAWN)
dllfunc(DLLFunc_Spawn, ent)
if(!ExecuteHamB(Ham_AddPlayerItem, index, ent))
{
if(pev_valid(ent)) set_pev(ent, pev_flags, pev(ent, pev_flags) | FL_KILLME)
return 0
}
ExecuteHamB(Ham_Item_AttachToPlayer, ent, index)
return 1
}
stock bacon_strip_weapon(index, weapon[])
{
if(!equal(weapon, "weapon_", 7))
return 0
static weaponid
weaponid = get_weaponid(weapon)
if(!weaponid)
return 0
static weaponent
weaponent = fm_find_ent_by_owner(-1, weapon, index)
if(!weaponent)
return 0
if(get_user_weapon(index) == weaponid)
ExecuteHamB(Ham_Weapon_RetireWeapon, weaponent)
if(!ExecuteHamB(Ham_RemovePlayerItem, index, weaponent))
return 0
ExecuteHamB(Ham_Item_Kill, weaponent)
set_pev(index, pev_weapons, pev(index, pev_weapons) & ~(1<<weaponid))
return 1
}
stock fm_get_user_bpammo(index, weapon)
{
static offset
switch(weapon)
{
case CSW_AWP: offset = OFFSET_AMMO_338MAGNUM
case CSW_SCOUT, CSW_AK47, CSW_G3SG1: offset = OFFSET_AMMO_762NATO
case CSW_M249: offset = OFFSET_AMMO_556NATOBOX
case CSW_FAMAS, CSW_M4A1, CSW_AUG,
CSW_SG550, CSW_GALI, CSW_SG552: offset = OFFSET_AMMO_556NATO
case CSW_M3, CSW_XM1014: offset = OFFSET_AMMO_BUCKSHOT
case CSW_USP, CSW_UMP45, CSW_MAC10: offset = OFFSET_AMMO_45ACP
case CSW_FIVESEVEN, CSW_P90: offset = OFFSET_AMMO_57MM
case CSW_DEAGLE: offset = OFFSET_AMMO_50AE
case CSW_P228: offset = OFFSET_AMMO_357SIG
case CSW_GLOCK18, CSW_TMP, CSW_ELITE,
CSW_MP5NAVY: offset = OFFSET_AMMO_9MM
default: offset = 0
}
return offset ? get_pdata_int(index, offset) : 0
}
stock fm_set_user_bpammo(index, weapon, amount)
{
static offset
switch(weapon)
{
case CSW_AWP: offset = OFFSET_AMMO_338MAGNUM
case CSW_SCOUT, CSW_AK47, CSW_G3SG1: offset = OFFSET_AMMO_762NATO
case CSW_M249: offset = OFFSET_AMMO_556NATOBOX
case CSW_FAMAS, CSW_M4A1, CSW_AUG,
CSW_SG550, CSW_GALI, CSW_SG552: offset = OFFSET_AMMO_556NATO
case CSW_M3, CSW_XM1014: offset = OFFSET_AMMO_BUCKSHOT
case CSW_USP, CSW_UMP45, CSW_MAC10: offset = OFFSET_AMMO_45ACP
case CSW_FIVESEVEN, CSW_P90: offset = OFFSET_AMMO_57MM
case CSW_DEAGLE: offset = OFFSET_AMMO_50AE
case CSW_P228: offset = OFFSET_AMMO_357SIG
case CSW_GLOCK18, CSW_TMP, CSW_ELITE,
CSW_MP5NAVY: offset = OFFSET_AMMO_9MM
default: offset = 0
}
if(offset)
set_pdata_int(index, offset, amount)
return 1
}
stock fm_find_ent_by_owner(index, const classname[], owner)
{
static ent
ent = index
while((ent = engfunc(EngFunc_FindEntityByString, ent, "classname", classname)) && pev(ent, pev_owner) != owner) {}
return ent
}
stock equipweapon(id, weapon)
{
if(!is_user_alive(id))
return
static weaponid[2], weaponent, weapname[32]
if(weapon & EQUIP_PRI)
{
weaponent = fm_lastprimary(id)
weaponid[1] = get_weaponid(g_primaryweapons[g_player_weapons[id][0]][1])
if(pev_valid(weaponent))
{
weaponid[0] = fm_get_weapon_id(weaponent)
if(weaponid[0] != weaponid[1])
{
get_weaponname(weaponid[0], weapname, 31)
bacon_strip_weapon(id, weapname)
}
}
else
weaponid[0] = -1
if(weaponid[0] != weaponid[1])
bacon_give_weapon(id, g_primaryweapons[g_player_weapons[id][0]][1])
fm_set_user_bpammo(id, weaponid[1], g_weapon_ammo[weaponid[1]][MAX_AMMO])
}
if(weapon & EQUIP_SEC)
{
weaponent = fm_lastsecondry(id)
weaponid[1] = get_weaponid(g_secondaryweapons[g_player_weapons[id][1]][1])
if(pev_valid(weaponent))
{
weaponid[0] = fm_get_weapon_id(weaponent)
if(weaponid[0] != weaponid[1])
{
get_weaponname(weaponid[0], weapname, 31)
bacon_strip_weapon(id, weapname)
}
}
else
weaponid[0] = -1
if(weaponid[0] != weaponid[1])
bacon_give_weapon(id, g_secondaryweapons[g_player_weapons[id][1]][1])
fm_set_user_bpammo(id, weaponid[1], g_weapon_ammo[weaponid[1]][MAX_AMMO])
}
if(weapon & EQUIP_GREN)
{
static i
for(i = 0; i < sizeof g_grenades; i++) if(!user_has_weapon(id, get_weaponid(g_grenades[i])))
bacon_give_weapon(id, g_grenades[i])
}
}
stock add_delay(index, const task[])
{
switch(index)
{
case 1..8: set_task(0.1, task, index)
case 9..16: set_task(0.2, task, index)
case 17..24: set_task(0.3, task, index)
case 25..32: set_task(0.4, task, index)
}
}
public cmd_enablemenu(id)
{
if(get_pcvar_num(cvar_weaponsmenu))
{
client_print(id, print_chat, "%L", id, g_showmenu[id] == false ? "MENU_REENABLED" : "MENU_ALENABLED")
g_showmenu[id] = true
}
}
public bot_weapons(id)
{
g_player_weapons[id][0] = _random(sizeof g_primaryweapons)
g_player_weapons[id][1] = _random(sizeof g_secondaryweapons)
equipweapon(id, EQUIP_ALL)
}