#include < amxmodx >
#include < cstrike >
#include < engine >
#include < fakemeta >
#include < fakemeta_util >
#include < fun >
#include < hamsandwich >
#include < zombieplague >
#include < client_printcolor >
#define PLUGIN "[ZP] Extra-Item: Silver M4A1"
#define VERSION "1.1"
#define AUTHOR "AlejandroSk / Shidla"
#define ITEM_NAME "Silver M4A1"
#define ITEM_COST 35
// ------------------------------------------------
#define is_valid_player(%1) (1 <= %1 <= 32)
#define ENG_NULLENT -1
#define EV_INT_WEAPONKEY EV_INT_impulse
#define AK_WEAPONKEY 666
new const g_Ent[] = "weapon_m4a1"
const Weapon_Golden = ((1<
// ------------------------------------------------
new g_ItemID
new bool:g_Silver_M4A1[33]
new g_Zoom[33]
new g_Bullets[33]
new m_spriteTexture
new cvar_dmgmultiplier, cvar_silverbullets, cvar_custommodel, cvar_uclip
new VIEW_MODEL[] = "models/v_silver_m4a1.mdl"
new PLAYER_MODEL[] = "models/p_silver_m4a1.mdl"
new WORLD_MODEL[] = "models/w_m4a1.mdl"
new OLDWORLD_MODEL[] = "models/w_m4a1.mdl" // the world model you want replaced
public plugin_init()
{
// Register The Plugin
register_plugin(PLUGIN, VERSION, AUTHOR)
register_dictionary("zp_items_bought.txt")
// Register Zombie Plague Extra Item
g_ItemID = zp_register_extra_item(ITEM_NAME, ITEM_COST, ZP_TEAM_HUMAN)
// CVARS
cvar_custommodel = register_cvar("zp_silver_m4a1_custom_model", "1")
cvar_silverbullets = register_cvar("zp_silver_m4a1_silver_bullets", "1")
cvar_dmgmultiplier = register_cvar("zp_silver_m4a1_dmg_multiplier", "2.5")
cvar_uclip = register_cvar("zp_silver_m4a1_unlimited_clip", "0")
// Death Msg
register_event("DeathMsg", "Death", "a")
// Weapon Pick Up
register_event("WeapPickup","checkModel","b","1=19")
// Current Weapon Event
register_event("CurWeapon","checkWeapon","be","1=1")
register_event("CurWeapon", "make_tracer", "be", "1=1", "3>0")
// Others
RegisterHam(Ham_Spawn, "player", "fwHamPlayerSpawnPost", 1)
RegisterHam(Ham_TakeDamage, "player", "fw_TakeDamage")
register_forward(FM_CmdStart, "fw_CmdStart")
register_forward(FM_SetModel, "fw_SetModel")
RegisterHam(Ham_Item_AddToPlayer, g_Ent, "fw_AddToPlayer")
}
public client_connect(id)
{
g_Silver_M4A1[id] = false
g_Bullets[id] = false
g_Zoom[id] = false
}
public client_disconnect(id)
{
g_Silver_M4A1[id] = false
g_Bullets[id] = false
g_Zoom[id] = false
}
public Death()
{
g_Silver_M4A1[read_data(2)] = false
g_Bullets[read_data(2)] = false
g_Zoom[read_data(2)] = false
}
public fwHamPlayerSpawnPost(id)
{
g_Silver_M4A1[id] = false
g_Bullets[id] = false
g_Zoom[id] = false
}
public event_round_start()
{
for (new id = 1; id <= 32; id++)
{
if (!is_user_connected(id) || !is_user_alive(id))
continue;
if (g_Silver_M4A1[id])
{
g_Silver_M4A1[id] = false
}
if (g_Bullets[id])
{
g_Bullets[id] = false
}
if (g_Zoom[id])
{
g_Zoom[id] = false
}
}
}
public fw_player_killed(victim, attacker, shouldgib)
{
if(g_Silver_M4A1[victim])
{
g_Silver_M4A1[victim] = false
g_Bullets[victim] = false
g_Zoom[victim] = false
}
}
public zp_user_infected_post(infected, infector)
{
if (g_Silver_M4A1[infected])
{
g_Silver_M4A1[infected] = false
g_Bullets[infected] = false
g_Zoom[infected] = false
}
}
public plugin_precache()
{
precache_model(VIEW_MODEL)
precache_model(PLAYER_MODEL)
precache_model(WORLD_MODEL)
precache_sound("weapons/zoom.wav")
m_spriteTexture = precache_model("sprites/dot.spr")
}
public checkModel(id)
{
if ( zp_get_user_zombie(id) )
return PLUGIN_HANDLED
new szWeapID = read_data(2)
if (szWeapID == CSW_M4A1 && g_Silver_M4A1[id] == true && get_pcvar_num(cvar_custommodel))
{
set_pev(id, pev_viewmodel2, VIEW_MODEL)
set_pev(id, pev_weaponmodel2, PLAYER_MODEL)
}
return PLUGIN_HANDLED
}
public checkWeapon(id)
{
new plrClip, plrAmmo, plrWeap[32]
new plrWeapId
plrWeapId = get_user_weapon(id, plrClip , plrAmmo)
if (plrWeapId == CSW_M4A1 && g_Silver_M4A1[id])
{
checkModel(id)
}
else
{
return PLUGIN_CONTINUE
}
if (plrClip == 0 && get_pcvar_num(cvar_uclip))
{
get_weaponname(plrWeapId, plrWeap, 31)
give_item(id, plrWeap)
engclient_cmd(id, plrWeap)
engclient_cmd(id, plrWeap)
engclient_cmd(id, plrWeap)
}
return PLUGIN_HANDLED
}
public fw_TakeDamage(victim, inflictor, attacker, Float:damage)
{
if (is_valid_player(attacker) && get_user_weapon(attacker) == CSW_M4A1 && g_Silver_M4A1[attacker])
{
SetHamParamFloat(4, damage * get_pcvar_float(cvar_dmgmultiplier))
}
}
public fw_CmdStart(id, uc_handle, seed)
{
if(!is_user_alive(id))
return PLUGIN_HANDLED
if( (get_uc(uc_handle, UC_Buttons) & IN_ATTACK2) && !(pev(id, pev_oldbuttons) & IN_ATTACK2))
{
new szClip, szAmmo
new szWeapID = get_user_weapon(id, szClip, szAmmo)
if( szWeapID == CSW_M4A1 && g_Silver_M4A1[id] == true && !g_Zoom[id] == true)
{
g_Zoom[id] = true
cs_set_user_zoom( id, CS_SET_AUGSG552_ZOOM, 0 )
emit_sound(id, CHAN_ITEM, "weapons/zoom.wav", 0.20, 2.40, 0, 100)
}
else if ( szWeapID == CSW_M4A1 && g_Silver_M4A1[id] == true && g_Zoom[id])
{
g_Zoom[id] = false
cs_set_user_zoom(id, CS_RESET_ZOOM, 0)
}
}
return PLUGIN_HANDLED
}
public make_tracer(id)
{
if (get_pcvar_num(cvar_silverbullets))
{
new clip,ammo
new wpnid = get_user_weapon(id,clip,ammo)
new pteam[16]
get_user_team(id, pteam, 15)
if ((g_Bullets[id] > clip) && (wpnid == CSW_M4A1) && g_Silver_M4A1[id])
{
new vec1[3], vec2[3]
get_user_origin(id, vec1, 1)
get_user_origin(id, vec2, 4)
message_begin(MSG_BROADCAST,SVC_TEMPENTITY)
write_byte (0)
write_coord(vec1[0])
write_coord(vec1[1])
write_coord(vec1[2])
write_coord(vec2[0])
write_coord(vec2[1])
write_coord(vec2[2])
write_short(m_spriteTexture)
write_byte(1) // framestart
write_byte(5) // framerate
write_byte(2) // life
write_byte(10) // width
write_byte(0) // noise
write_byte(255) // r, g, b
write_byte(255) // r, g, b
write_byte(255) // r, g, b
write_byte(200) // brightness
write_byte(150) // speed
message_end()
}
g_Bullets[id] = clip
}
}
public zp_extra_item_selected(player, itemid)
{
new player_name[32]
get_user_name(player, player_name, charsmax(player_name))
if (itemid == g_ItemID)
{
if ( user_has_weapon(player, CSW_M4A1) )
{
drop_prim(player)
}
g_Silver_M4A1[player] = true
give_item(player, "weapon_m4a1")
give_item(player, "ammo_556nato")
client_printcolor(player, "%L %L", LANG_PLAYER, "PREFIX", LANG_PLAYER, "BOUGHT_INFO1", ITEM_NAME)
client_printcolor(0, "%L %L", LANG_PLAYER, "PREFIX", LANG_PLAYER, "BOUGHT_INFO2", player_name, ITEM_NAME)
}
}
public fw_SetModel(entity, model[])
{
if(!is_valid_ent(entity))
return FMRES_IGNORED;
if(!equal(model, OLDWORLD_MODEL))
return FMRES_IGNORED;
static szClassName[33]
entity_get_string(entity, EV_SZ_classname, szClassName, charsmax(szClassName))
if(!equal(szClassName, "weaponbox"))
return FMRES_IGNORED
static iOwner, iStoredGalilID
iOwner = entity_get_edict(entity, EV_ENT_owner)
iStoredGalilID = find_ent_by_owner(ENG_NULLENT, "weapon_m4a1", entity)
if(g_Silver_M4A1[iOwner] && is_valid_ent(iStoredGalilID))
{
g_Silver_M4A1[iOwner] = false
entity_set_int(iStoredGalilID, EV_INT_WEAPONKEY, AK_WEAPONKEY)
entity_set_model(entity, WORLD_MODEL)
return FMRES_SUPERCEDE
}
return FMRES_IGNORED
}
public fw_AddToPlayer (AK47, id)
{
if( is_valid_ent(AK47) && is_user_connected(id) && entity_get_int(AK47, EV_INT_WEAPONKEY) == AK_WEAPONKEY)
{
g_Silver_M4A1[id] = true
entity_set_int(AK47, EV_INT_WEAPONKEY, 0)
return HAM_HANDLED
}
return HAM_IGNORED
}
stock drop_prim(id)
{
new weapons[32], num
get_user_weapons(id, weapons, num)
for (new i = 0; i < num; i++) {
if (Weapon_Golden & (1< {
static wname[32]
get_weaponname(weapons[i], wname, sizeof wname - 1)
engclient_cmd(id, "drop", wname)
}
}
}