#include <amxmodx>
#include <hamsandwich>
#include <reapi>
#include <vip_system>
#define MAX_TITLE_LENGTH 64
#define MAX_MODEL_LENGTH 64
#define makeCustomID(%1) (%1 + 100)
#define getCustomID(%1) (get_entvar(%1, var_impulse) - 100)
enum _:CONFIG {
c_title[MAX_TITLE_LENGTH],
WeaponIdType:c_weapon,
c_cost,
c_bpammo,
Float:c_damage,
c_v_model[MAX_MODEL_LENGTH],
c_p_model[MAX_MODEL_LENGTH]
};
new const config[][CONFIG] = {
// { "TITLE", WEAPON_ID, price, bpammo, damage, "V model path", "P model path"
{ "VIP AK-47", WEAPON_AK47, 2500, 100, 1.1, "models/headparty/v_ak47.mdl", "models/headparty/p_ak47.mdl" },
{ "VIP M4A1", WEAPON_M4A1, 3100, 100, 1.1, "models/headparty/v_m4a1.mdl", "models/headparty/p_m4a1.mdl" },
{ "VIP AWP", WEAPON_AWP, 4750, 40, 1.1, "models/headparty/v_awp.mdl", "models/headparty/p_awp.mdl" }
};
new menu, Float:damage[MAX_CLIENTS + 1];
public plugin_precache() {
for (new i = 0; i < sizeof config; i++) {
precache_model(config[i][c_v_model]);
precache_model(config[i][c_p_model]);
}
}
public plugin_init() {
register_plugin("[ReVIP] Custom Weapons", "0.1", "F@nt0M");
RegisterHookChain(RG_CBasePlayer_TakeDamage, "CBasePlayer_TakeDamage", false);
for (new i = 0, name[32]; i < sizeof config; i++) {
rg_get_weapon_info(config[i][c_weapon], WI_NAME, name, charsmax(name));
RegisterHam(Ham_Item_Deploy, name, "Fwd_Item_Deploy", true);
RegisterHam(Ham_Item_Holster, name, "Fwd_Item_Holster", true);
}
new title[128];
formatex(title, charsmax(title), "\r%L \w[\d%L\w]", LANG_SERVER, "CUSTOM_SHOP_NAME", LANG_SERVER, "NAME_SERVER");
menu = menu_create(title, "MenuHandler");
new callback = menu_makecallback("MenuItemCallback");
for (new i = 0, item[32]; i < sizeof config; i++) {
num_to_str(i, item, charsmax(item));
formatex(title, charsmax(title), "%s \r[\y$%d\r]", config[i][c_title], config[i][c_cost]);
menu_additem(menu, title, item, 0, callback);
}
formatex(title, charsmax(title), "%L", LANG_SERVER, "SHOP_NEXT");
menu_setprop(menu, MPROP_NEXTNAME, title);
formatex(title, charsmax(title), "%L", LANG_SERVER, "SHOP_BACK");
menu_setprop(menu, MPROP_BACKNAME, title);
formatex(title, charsmax(title), "%L", LANG_SERVER, "SHOP_EXIT");
menu_setprop(menu, MPROP_EXITNAME, title);
}
public plugin_end() {
menu_destroy(menu);
}
public vip_use_custom_shop(id) {
menu_display(id, menu, 0);
}
public MenuHandler(id, menu, menuItem) {
if (menuItem == MENU_EXIT) {
return;
}
new tmp, tmpStr[1], info[10];
menu_item_getinfo(menu, menuItem, tmp, info, charsmax(info), tmpStr, 0, tmp);
new item = str_to_num(info);
new money = get_member(id, m_iAccount);
if (money >= config[item][c_cost] && giveItem(id, item)) {
rg_add_account(id, money - config[item][c_cost], AS_SET, true);
}
}
public MenuItemCallback(id, menu, menuItem) {
new tmp, tmpStr[1], info[10];
menu_item_getinfo(menu, menuItem, tmp, info, charsmax(info), tmpStr, 0, tmp);
new item = str_to_num(info);
return get_member(id, m_iAccount) >= config[item][c_cost] ? ITEM_ENABLED : ITEM_DISABLED
}
public Fwd_Item_Deploy(weapon) {
new id = get_member(weapon, m_pPlayer);
if (!is_user_connected(id) || !get_flag_access_def(id)) {
return HAM_IGNORED;
}
new item = getItemByWeapon(weapon);
if (item == -1) {
return HAM_IGNORED;
}
setWeaponModel(id, item);
damage[id] = config[item][c_damage];
return HAM_IGNORED;
}
public Fwd_Item_Holster(weapon) {
new id = get_member(weapon, m_pPlayer);
if (!is_user_connected(id)) {
return HAM_IGNORED;
}
damage[id] = 0.0;
return HAM_IGNORED;
}
public CBasePlayer_TakeDamage(const id, const inflictor, const attacker, const Float:dmg) {
#pragma unused inflictor
if (id == attacker || !is_user_connected(attacker) || !rg_is_player_can_takedamage(id, attacker)) {
return HC_CONTINUE;
}
if (damage[attacker] > 0.0) {
SetHookChainArg(4, ATYPE_FLOAT, dmg * damage[attacker]);
}
return HC_CONTINUE;
}
bool:giveItem(const id, const item) {
new name[32];
rg_get_weapon_info(config[item][c_weapon], WI_NAME, name, charsmax(name));
new weapon = rg_give_custom_item(id, name, GT_REPLACE, makeCustomID(item));
if (!is_nullent(weapon)) {
rg_switch_weapon(id, weapon);
rg_set_user_bpammo(id, config[item][c_weapon], config[item][c_bpammo]);
setWeaponModel(id, item);
}
}
getItemByWeapon(const weapon) {
new item = getCustomID(weapon);
return item >= 0 ? item : -1;
}
setWeaponModel(const id, const item) {
set_entvar(id, var_viewmodel, config[item][c_v_model]);
set_entvar(id, var_weaponmodel, config[item][c_p_model]);
}