Approved Block Damage

Gameplay Addons
User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1755
Joined: 2 Years Ago
Location: Egypt
Has thanked: 30 times
Been thanked: 87 times
Age: 21
Contact:

Block Damage

#1

Post by Raheem » 6 Months Ago

Block Damage

Description:
  • This plugin will block damage to zombie in two cases:

    1. If he frozen in the pre-release time
    2. If he has madness
    3. If player frozen by frost nade
    4. Fire zombies during pre-release time

    This is useful to block some extra-items which make damage in these cases. This will block any plugin that use ExecuteHamB() function.
Code:
    1. #include <zombie_escape>
    2.  
    3. new bool:g_bBlockDamage
    4.  
    5. public plugin_init ()
    6. {
    7.     register_plugin("Block Damage", "1.0", "Raheem")
    8.    
    9.     RegisterHam(Ham_TakeDamage, "player", "Fw_TakeDamage_Pre", 0)
    10. }
    11.  
    12. public ze_zombie_appear()
    13. {
    14.     g_bBlockDamage = true
    15. }
    16.  
    17. public ze_zombie_release()
    18. {
    19.     g_bBlockDamage = false
    20. }
    21.  
    22. public ze_fire_pre(id)
    23. {
    24.     if (g_bBlockDamage)
    25.         return 1;
    26.    
    27.     return 0;
    28. }
    29.  
    30. public Fw_TakeDamage_Pre(iVictim, iInflictor, iAttacker, Float:flDamage, bitsDamage)
    31. {
    32.     if (is_user_alive(iVictim))
    33.     {
    34.         if (ze_is_user_zombie(iVictim))
    35.         {
    36.             if (ze_zombie_in_madness(iVictim) || g_bBlockDamage || ze_zombie_in_forst(iVictim))
    37.             {
    38.                 return HAM_SUPERCEDE
    39.             }
    40.         }
    41.     }
    42.    
    43.     return HAM_IGNORED
    44. }
Ideas:
  • If you need to make any exception for any weapon or add more block cases, just comment down and i'll add it.
You don't know? Learn and you will know.

User avatar
Spir0x
Veteran Member
Veteran Member
Tunisia
Posts: 575
Joined: 2 Years Ago
Location: Tunisia
Has thanked: 14 times
Been thanked: 6 times
Age: 19
Contact:

#2

Post by Spir0x » 6 Months Ago

with Plasma Gun i can damage zombies when they are frozen by frost nade and "ze_freeze_damage 0" so this plugin will fix it ?
I trynna make money, not friends.

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1755
Joined: 2 Years Ago
Location: Egypt
Has thanked: 30 times
Been thanked: 87 times
Age: 21
Contact:

#3

Post by Raheem » 6 Months Ago

I don't add the frost nade support, you need me to add this case also?
You don't know? Learn and you will know.

User avatar
Spir0x
Veteran Member
Veteran Member
Tunisia
Posts: 575
Joined: 2 Years Ago
Location: Tunisia
Has thanked: 14 times
Been thanked: 6 times
Age: 19
Contact:

#4

Post by Spir0x » 6 Months Ago

I think yes becuz all players can damage the zombies when they are frozen and the cvar of damage is disabled too.
I trynna make money, not friends.

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1755
Joined: 2 Years Ago
Location: Egypt
Has thanked: 30 times
Been thanked: 87 times
Age: 21
Contact:

#5

Post by Raheem » 6 Months Ago

Yes can take damage from weapons like plasma gun. OK i added support also for zombies if they are frozen by frost nade.
You don't know? Learn and you will know.

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1755
Joined: 2 Years Ago
Location: Egypt
Has thanked: 30 times
Been thanked: 87 times
Age: 21
Contact:

#6

Post by Raheem » 6 Months Ago

UPDATED: Added fire case.
You don't know? Learn and you will know.

User avatar
th3_king
VIP
VIP
Egypt
Posts: 31
Joined: 1 Year Ago
Location: Egypt
Has thanked: 9 times
Been thanked: 2 times
Age: 16
Contact:

#7

Post by th3_king » 6 Months Ago

Hey,
If you will use this plugin you must use Trigger Hurt Control Plugin then but use this source code:

  1. #include <zombie_escape>
  2.  
  3. // Cvars
  4. new Cvar_Damage
  5.  
  6. public plugin_init()
  7. {
  8.     register_plugin("[ZE] Map-Damage Control", "1.0", "Raheem")
  9.    
  10.     // Hams
  11.     RegisterHam(Ham_Touch, "trigger_hurt", "Fw_TouchTrigger_Post", 1)
  12.    
  13.     // Cvars
  14.     Cvar_Damage = register_cvar("ze_trigger_hurt_more_dmg", "20000")
  15. }
  16.  
  17. public Fw_TouchTrigger_Post(iEnt, id)
  18. {
  19.     if(!is_user_alive(id) || !pev_valid(iEnt))
  20.         return HAM_IGNORED
  21.    
  22.    
  23.     if (pev(iEnt, pev_dmg) > 4200)
  24.     {
  25.         ExecuteHam(Ham_TakeDamage, id, iEnt, iEnt, get_pcvar_float(Cvar_Damage), DMG_MORTAR)
  26.     }
  27.  
  28.     return HAM_IGNORED
  29. }

and you won't face any problems after doing this :D
Join Our Server
Image

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 446
Joined: 2 Years Ago
Has thanked: 18 times
Been thanked: 1 time
Contact:

#8

Post by czirimbolo » 6 Months Ago

Raheem, these two guns have their special second attacks. And that seconds attacks can damage zombies on freezetime, can you block this?

Code: Select all

#include <zombie_escape>
#include <engine>
#include <fakemeta_util>
#include <cstrike>
#include <fun>
#include <xs>

#define PLUGIN "[CSO] Thanatos-3"
#define VERSION "1.0"
#define AUTHOR "Dias no Pendragon"

#define DAMAGE 25 // 45 for zombie
#define CLIP 60
#define BPAMMO 240

#define SCYTHE_SLASHTIME 7.0

#define STAGE_AMMO 10 // every x ammo -> stage up
#define RELOAD_TIME 3.25
#define ANIME_EXT "onehanded"

#define V_MODEL "models/v_thanatos3.mdl"
#define P_MODEL "models/p_thanatos3.mdl"
#define W_MODEL "models/w_thanatos3.mdl"
#define W_MODEL2 "models/w_thanatos3b.mdl"
#define S_MODEL "models/thanatos3_knife.mdl"
#define S_MODEL2 "models/thanatos3_wind.mdl"

new const WeaponSounds[29][] =
{
	"weapons/thanatos3-1.wav",
	"weapons/thanatos3_fly_shoot.wav",
	"weapons/thanatos3_fly_w2.wav",
	"weapons/thanatos3_fly_w3.wav",
	"weapons/thanatos3_ilde_w1.wav",
	"weapons/thanatos3_ilde_w2.wav",
	"weapons/thanatos3_ilde_w3.wav",
	"weapons/thanatos3_draw.wav",
	"weapons/thanatos3_draw_w1.wav",
	"weapons/thanatos3_draw_w2.wav",
	"weapons/thanatos3_draw_w3.wav",
	"weapons/thanatos3_boltpull.wav",
	"weapons/thanatos3_clipin.wav",
	"weapons/thanatos3_clipout.wav",
	"weapons/thanatos3_knife_hit1.wav",
	"weapons/thanatos3_knife_hit2.wav",
	"weapons/thanatos3_knife_swish.wav",
	"weapons/thanatos3_metal1.wav",
	"weapons/thanatos3_metal2.wav",
	"weapons/thanatos3_reload_w1.wav",
	"weapons/thanatos3_reload_w2.wav",
	"weapons/thanatos3_reload_w3.wav",
	"weapons/thanatos3_spread_w1.wav",
	"weapons/thanatos3_spread_w2.wav",
	"weapons/thanatos3_spread_w3.wav",
	"weapons/thanatos3_stone1.wav",
	"weapons/thanatos3_stone2.wav",
	"weapons/thanatos3_wood1.wav",
	"weapons/thanatos3_wood2.wav"
}

enum
{
	ANIME_IDLE = 0,
	ANIME_IDLE_W1,
	ANIME_IDLE_W2,
	ANIME_IDLE_W3,
	ANIME_SHOOT,
	ANIME_SHOOT_W1,
	ANIME_SHOOT_W2,
	ANIME_SHOOT_W3,
	ANIME_FLY_W1,
	ANIME_FLY_W2,
	ANIME_FLY_W3,
	ANIME_RELOAD,
	ANIME_RELOAD_W1,
	ANIME_RELOAD_W2,
	ANIME_RELOAD_W3,
	ANIME_SPREAD_W1,
	ANIME_SPREAD_W2,
	ANIME_SPREAD_W3,
	ANIME_DRAW,
	ANIME_DRAW_W1,
	ANIME_DRAW_W2,
	ANIME_DRAW_W3
}

enum
{
	STAGE_NONE = 0,
	STAGE_ULTIMATE,
	STAGE_OMEGA,
	STAGE_METATRON
}

#define SCYTHE_CLASSNAME "saisu"

#define CSW_THANATOS3 CSW_MP5NAVY
#define weapon_thanatos3 "weapon_mp5navy"

// Fire Start
#define THANATOS3_OLDMODEL "models/w_mp5.mdl"

const PRIMARY_WEAPONS_BIT_SUM = (1<<CSW_SCOUT)|(1<<CSW_XM1014)|(1<<CSW_MAC10)|(1<<CSW_AUG)|(1<<CSW_UMP45)|(1<<CSW_SG550)|(1<<CSW_GALIL)|(1<<CSW_FAMAS)|(1<<CSW_AWP)|(1<<CSW_MP5NAVY)|(1<<CSW_M249)|(1<<CSW_M3)|(1<<CSW_M4A1)|(1<<CSW_TMP)|(1<<CSW_G3SG1)|(1<<CSW_SG552)|(1<<CSW_AK47)|(1<<CSW_P90)
const SECONDARY_WEAPONS_BIT_SUM = (1<<CSW_P228)|(1<<CSW_ELITE)|(1<<CSW_FIVESEVEN)|(1<<CSW_USP)|(1<<CSW_GLOCK18)|(1<<CSW_DEAGLE)

// MACROS
#define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
#define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
#define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))

new g_Had_Thanatos3, g_Thanatos3_Clip[33], g_Thanatos3_Stage[33], g_Thanatos3_Count[33]
new g_MsgCurWeapon, g_InTempingAttack
new g_Event_Thanatos3, g_ShellId, g_SmokePuff_SprId, g_HamBot, g_iItemID

public plugin_init() 
{
	register_plugin(PLUGIN, VERSION, AUTHOR)
	
	register_event("HLTV", "Event_NewRound", "a", "1=0", "2=0")
	register_think(SCYTHE_CLASSNAME, "fw_Scythe_Think")
	register_touch(SCYTHE_CLASSNAME, "*", "fw_Scythe_Touch")
	
	register_forward(FM_UpdateClientData,"fw_UpdateClientData_Post", 1)	
	register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")	
	register_forward(FM_SetModel, "fw_SetModel")		
	register_forward(FM_CmdStart, "fw_CmdStart")
	register_forward(FM_EmitSound, "fw_EmitSound")
	register_forward(FM_TraceLine, "fw_TraceLine")
	register_forward(FM_TraceHull, "fw_TraceHull")	
	
	RegisterHam(Ham_Item_Deploy, weapon_thanatos3, "fw_Item_Deploy_Post", 1)	
	RegisterHam(Ham_Item_AddToPlayer, weapon_thanatos3, "fw_Item_AddToPlayer_Post", 1)
	RegisterHam(Ham_Item_PostFrame, weapon_thanatos3, "fw_Item_PostFrame")	
	RegisterHam(Ham_Weapon_Reload, weapon_thanatos3, "fw_Weapon_Reload")
	RegisterHam(Ham_Weapon_Reload, weapon_thanatos3, "fw_Weapon_Reload_Post", 1)	
	RegisterHam(Ham_Weapon_WeaponIdle, weapon_thanatos3, "fw_Weapon_WeaponIdle_Post", 1)
	RegisterHam(Ham_Weapon_PrimaryAttack, weapon_thanatos3, "fw_Weapon_PrimaryAttack_Post", 1)	
	
	RegisterHam(Ham_TraceAttack, "worldspawn", "fw_TraceAttack_World")
	RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Player")	
	
	g_MsgCurWeapon = get_user_msgid("CurWeapon")
	
    g_iItemID = ze_register_item("Thanatos-3", 0, 0)
}

public plugin_precache()
{
	precache_model(V_MODEL)
	precache_model(P_MODEL)
	precache_model(W_MODEL)
	precache_model(W_MODEL2)
	precache_model(S_MODEL)
	precache_model(S_MODEL2)
	
	for(new i = 0; i < sizeof(WeaponSounds); i++)
		precache_sound(WeaponSounds[i])
	
	g_ShellId = precache_model("models/rshell.mdl")
	g_SmokePuff_SprId = precache_model("sprites/wall_puff1.spr")
	
	register_forward(FM_PrecacheEvent, "fw_PrecacheEvent_Post", 1)
}

public fw_PrecacheEvent_Post(type, const name[])
{
	if(equal("events/mp5n.sc", name)) g_Event_Thanatos3 = get_orig_retval()		
}

public client_putinserver(id)
{
	if(!g_HamBot && is_user_bot(id))
	{
		g_HamBot = 1
		set_task(0.1, "Do_Register_HamBot", id)
	}
}

public Do_Register_HamBot(id)
{
	RegisterHamFromEntity(Ham_TraceAttack, id, "fw_TraceAttack_Player")
}

public Event_NewRound() remove_entity_name(SCYTHE_CLASSNAME)

public ze_select_item_pre(id, itemid)
{
    if (itemid != g_iItemID)
        return ZE_ITEM_AVAILABLE
 
    if (ze_is_user_zombie(id))
        return ZE_ITEM_DONT_SHOW
 
    return ZE_ITEM_AVAILABLE
}
 
public ze_select_item_post(id, itemid)
{
    if (itemid != g_iItemID)
        return
 
    Get_Thanatos3(id)
}

public Get_Thanatos3(id)
{
	g_Thanatos3_Count[id] = 0
	g_Thanatos3_Stage[id] = STAGE_NONE
	Set_BitVar(g_Had_Thanatos3, id)
	give_item(id, weapon_thanatos3)
	
	static Ent; Ent = fm_get_user_weapon_entity(id, CSW_THANATOS3)
	if(pev_valid(Ent)) cs_set_weapon_ammo(Ent, CLIP)
	
	Update_Ammo(id, CLIP)
	cs_set_user_bpammo(id, CSW_THANATOS3, BPAMMO)
}

public Remove_Thanatos3(id)
{
	g_Thanatos3_Count[id] = 0
	g_Thanatos3_Stage[id] = STAGE_NONE
	UnSet_BitVar(g_Had_Thanatos3, id)
}

public Update_Ammo(id, Ammo)
{
	if(!is_user_alive(id))
		return
	
	engfunc(EngFunc_MessageBegin, MSG_ONE_UNRELIABLE, g_MsgCurWeapon, {0, 0, 0}, id)
	write_byte(1)
	write_byte(CSW_THANATOS3)
	write_byte(Ammo)
	message_end()
}

public fw_UpdateClientData_Post(id, sendweapons, cd_handle)
{
	if(!is_user_alive(id))
		return FMRES_IGNORED	
	if(get_user_weapon(id) == CSW_THANATOS3 && Get_BitVar(g_Had_Thanatos3, id))
		set_cd(cd_handle, CD_flNextAttack, get_gametime() + 0.001) 
	
	return FMRES_HANDLED
}

public fw_PlaybackEvent(flags, invoker, eventid, Float:delay, Float:origin[3], Float:angles[3], Float:fparam1, Float:fparam2, iParam1, iParam2, bParam1, bParam2)
{
	if (!is_user_connected(invoker))
		return FMRES_IGNORED	
	if(get_user_weapon(invoker) != CSW_THANATOS3 || !Get_BitVar(g_Had_Thanatos3, invoker))
		return FMRES_IGNORED
	if(eventid != g_Event_Thanatos3)
		return FMRES_IGNORED
	
	engfunc(EngFunc_PlaybackEvent, flags | FEV_HOSTONLY, invoker, eventid, delay, origin, angles, fparam1, fparam2, iParam1, iParam2, bParam1, bParam2)
	
	switch(g_Thanatos3_Stage[invoker])
	{
		case STAGE_NONE: Set_WeaponAnim(invoker, ANIME_SHOOT)
		case STAGE_ULTIMATE: Set_WeaponAnim(invoker, ANIME_SHOOT_W1)
		case STAGE_OMEGA: Set_WeaponAnim(invoker, ANIME_SHOOT_W2)
		case STAGE_METATRON: Set_WeaponAnim(invoker, ANIME_SHOOT_W3)
	}
	
	emit_sound(invoker, CHAN_WEAPON, WeaponSounds[0], 1.0, 0.4, 0, 94 + random_num(0, 15))
	Eject_Shell(invoker, g_ShellId, 0.01)
	
	// Check Stage
	g_Thanatos3_Count[invoker]++
	if(g_Thanatos3_Count[invoker] >= STAGE_AMMO)
	{
		if(g_Thanatos3_Stage[invoker] < STAGE_METATRON)
		{
			g_Thanatos3_Stage[invoker]++
			
			switch(g_Thanatos3_Stage[invoker])
			{
				case STAGE_ULTIMATE: Set_WeaponAnim(invoker, ANIME_SPREAD_W1)
				case STAGE_OMEGA: Set_WeaponAnim(invoker, ANIME_SPREAD_W2)
				case STAGE_METATRON: Set_WeaponAnim(invoker, ANIME_SPREAD_W3)
			}
		}
		
		g_Thanatos3_Count[invoker] = 0
	}

	return FMRES_IGNORED
}

public fw_SetModel(entity, model[])
{
	if(!pev_valid(entity))
		return FMRES_IGNORED
	
	static Classname[32]
	pev(entity, pev_classname, Classname, sizeof(Classname))
	
	if(!equal(Classname, "weaponbox"))
		return FMRES_IGNORED
	
	static iOwner
	iOwner = pev(entity, pev_owner)
	
	if(equal(model, THANATOS3_OLDMODEL))
	{
		static weapon; weapon = find_ent_by_owner(-1, weapon_thanatos3, entity)
		
		if(!pev_valid(weapon))
			return FMRES_IGNORED;
		
		if(Get_BitVar(g_Had_Thanatos3, iOwner))
		{
			set_pev(weapon, pev_impulse, 25112015)
			set_pev(weapon, pev_iuser3, g_Thanatos3_Count[iOwner])
			set_pev(weapon, pev_iuser4, g_Thanatos3_Stage[iOwner])
			
			engfunc(EngFunc_SetModel, entity, g_Thanatos3_Stage[iOwner] ? W_MODEL2 : W_MODEL)
			Remove_Thanatos3(iOwner)
			
			return FMRES_SUPERCEDE
		}
	}

	return FMRES_IGNORED;
}

public fw_CmdStart(id, uc_handle, seed)
{
	if(!is_user_alive(id))
		return FMRES_IGNORED
	if(get_user_weapon(id) != CSW_THANATOS3 || !Get_BitVar(g_Had_Thanatos3, id))
		return FMRES_IGNORED
		
	static PressedButton
	PressedButton = get_uc(uc_handle, UC_Buttons)
	
	if(PressedButton & IN_ATTACK2)
	{
		if(get_pdata_float(id, 83, 5) > 0.0)
			return FMRES_IGNORED
		
		PressedButton &= ~IN_ATTACK2
		set_uc(uc_handle, UC_Buttons, PressedButton)
		
		if(g_Thanatos3_Stage[id]) Check_Scythe(id)
	}
		
	return FMRES_HANDLED
}

public Check_Scythe(id)
{
	Create_FakeAttackAnim(id)
	
	Set_Player_NextAttack(id, 1.75)
	Set_WeaponIdleTime(id, CSW_THANATOS3, 2.0)
	
	switch(g_Thanatos3_Stage[id])
	{
		case STAGE_ULTIMATE: Set_WeaponAnim(id, ANIME_FLY_W1)
		case STAGE_OMEGA: Set_WeaponAnim(id, ANIME_FLY_W2)
		case STAGE_METATRON: Set_WeaponAnim(id, ANIME_FLY_W3)
	}
	
	emit_sound(id, CHAN_WEAPON, WeaponSounds[1], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
	Shoot_Scyche(id, g_Thanatos3_Stage[id])
	
	// Fake Punch
	static Float:Origin[3]; Origin[0] = -2.5
	set_pev(id, pev_punchangle, Origin)
	
	g_Thanatos3_Stage[id] = STAGE_NONE
}

public Shoot_Scyche(id, Level)
{
	static Float:Origin[6][3], Float:Target[3], LoopTime, Float:Speed[6]
	
	get_position(id, 48.0, -10.0, random_float(-5.0, 5.0), Origin[0]); Speed[0] = random_float(500.0, 1000.0)
	get_position(id, 48.0, 10.0, random_float(-5.0, 5.0), Origin[1]); Speed[1] = random_float(500.0, 1000.0)
	get_position(id, 48.0, -20.0, random_float(-5.0, 5.0), Origin[2]); Speed[2] = random_float(500.0, 1000.0)
	get_position(id, 48.0, 20.0, random_float(-5.0, 5.0), Origin[3]); Speed[3] = random_float(500.0, 1000.0)
	get_position(id, 48.0, -30.0, random_float(-5.0, 5.0), Origin[4]); Speed[4] = random_float(500.0, 1000.0)
	get_position(id, 48.0, 30.0, random_float(-5.0, 5.0), Origin[5]); Speed[5] = random_float(500.0, 1000.0)
	
	get_position(id, 1024.0, 0.0, 0.0, Target)
	
	switch(Level)
	{
		case STAGE_ULTIMATE: LoopTime = 2
		case STAGE_OMEGA: LoopTime = 4
		case STAGE_METATRON: LoopTime = 6
	}
	
	for(new i = 0; i < LoopTime; i++)
		Create_Scythe(id, Origin[i], Target, Speed[i])
}

public Create_Scythe(id, Float:Start[3], Float:End[3], Float:Speed)
{
	static Float:Velocity[3], Float:Angles[3]
	
	pev(id, pev_v_angle, Angles)
	new Ent = create_entity("info_target")
	
	Angles[0] *= -1.0

	// set info for ent
	set_pev(Ent, pev_movetype, MOVETYPE_FLY)
	entity_set_string(Ent, EV_SZ_classname, SCYTHE_CLASSNAME)
	engfunc(EngFunc_SetModel, Ent, S_MODEL)
	
	set_pev(Ent, pev_mins, Float:{-1.0, -1.0, -1.0})
	set_pev(Ent, pev_maxs, Float:{1.0, 1.0, 1.0})
	set_pev(Ent, pev_origin, Start)
	set_pev(Ent, pev_gravity, 0.25)
	set_pev(Ent, pev_angles, Angles)
	set_pev(Ent, pev_solid, SOLID_TRIGGER)
	set_pev(Ent, pev_owner, id)	
	set_pev(Ent, pev_iuser1, get_user_team(id))
	set_pev(Ent, pev_iuser2, 0)
	set_pev(Ent, pev_iuser3, 206)
	set_pev(Ent, pev_fuser1, get_gametime() + SCYTHE_SLASHTIME)

	get_speed_vector(Start, End, Speed, Velocity)
	set_pev(Ent, pev_velocity, Velocity)	
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.1)
	
	// Animation
	set_pev(Ent, pev_animtime, get_gametime())
	set_pev(Ent, pev_framerate, 1.0)
	set_pev(Ent, pev_sequence, 0)
	
	// Sound
	emit_sound(Ent, CHAN_BODY, WeaponSounds[16], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
}

public fw_Scythe_Think(Ent)
{
	if(!pev_valid(Ent))
		return
		
	static Float:Time; pev(Ent, pev_fuser1, Time)
	static Float:Time2; pev(Ent, pev_fuser2, Time2)
	static Owner; Owner = pev(Ent, pev_owner)
	static Team; Team = pev(Ent, pev_iuser1)
	static Target; Target = pev(Ent, pev_iuser2)
	
	if(Time <= get_gametime() || !is_user_connected(Owner))
	{
		set_pev(Ent, pev_flags, FL_KILLME)
		set_pev(Ent, pev_nextthink, get_gametime() + 0.1)
			
		return
	}
	
	if(is_user_alive(Target))
	{
		if(get_user_team(Target) == Team)
		{
			set_pev(Ent, pev_flags, FL_KILLME)
			set_pev(Ent, pev_nextthink, get_gametime() + 0.1)
			
			return
		}
		
		if(get_gametime() - 0.75 > Time2)
		{
			emit_sound(Ent, CHAN_BODY, WeaponSounds[16], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
			set_pev(Ent, pev_fuser2, get_gametime())
		}
		
		ExecuteHamB(Ham_TakeDamage, Target, 0, Owner, float(DAMAGE) / 1.5, DMG_SLASH)
	} else {
		if(Target)
		{
			set_pev(Ent, pev_flags, FL_KILLME)
			set_pev(Ent, pev_nextthink, get_gametime() + 0.1)
				
			return
		}
	}
	
	set_pev(Ent, pev_nextthink, get_gametime() + 0.2)
}

public fw_Scythe_Touch(Ent, id)
{
	if(!pev_valid(Ent))
		return
	if(pev_valid(id) && pev(id, pev_iuser3) == 206)
		return
		
	if(!is_user_alive(id))
	{
		static Float:Origin[3]; pev(Ent, pev_origin, Origin)
		
		set_pev(Ent, pev_fuser1, get_gametime() + random_float(1.0, 3.0))
		
		set_pev(Ent, pev_velocity, {0.0, 0.0, 0.0})
		set_pev(Ent, pev_movetype, MOVETYPE_NONE)
		set_pev(Ent, pev_solid, SOLID_NOT)
		
		// Animation
		set_pev(Ent, pev_animtime, get_gametime())
		set_pev(Ent, pev_framerate, 1.0)
		set_pev(Ent, pev_sequence, 1)
		
		// Bullet Hole
		static Owner; Owner = pev(Ent, pev_owner)
		Make_BulletHole(Owner, Origin, float(DAMAGE))
		
		// Sound
		emit_sound(Ent, CHAN_BODY, WeaponSounds[random_num(25, 28)], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
	} else {
		static Team; Team = pev(Ent, pev_iuser1)
		if(get_user_team(id) == Team)
			return
		static Owner; Owner = pev(Ent, pev_owner)
		if(!is_user_connected(Owner))
			return
		
		if(!pev(Ent, pev_iuser2))
		{
			set_pev(Ent, pev_fuser1, get_gametime() + SCYTHE_SLASHTIME)
			set_pev(Ent, pev_iuser2, id)
			
			set_pev(Ent, pev_velocity, {0.0, 0.0, 0.0})
			set_pev(Ent, pev_movetype, MOVETYPE_FOLLOW)
			set_pev(Ent, pev_solid, SOLID_NOT)
			set_pev(Ent, pev_aiment, id)
			
			engfunc(EngFunc_SetModel, Ent, S_MODEL2)
			
			// Animation
			set_pev(Ent, pev_animtime, get_gametime())
			set_pev(Ent, pev_framerate, random_float(1.0, 5.0))
			set_pev(Ent, pev_sequence, 0)
			
			// Sound
			emit_sound(id, CHAN_STATIC, WeaponSounds[random_num(14, 15)], VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
		}
	}
}

public fw_EmitSound(id, channel, const sample[], Float:volume, Float:attn, flags, pitch)
{
	if(!is_user_connected(id))
		return FMRES_IGNORED
	if(!Get_BitVar(g_InTempingAttack, id))
		return FMRES_IGNORED
		
	if(sample[8] == 'k' && sample[9] == 'n' && sample[10] == 'i')
	{
		if(sample[14] == 's' && sample[15] == 'l' && sample[16] == 'a')
			return FMRES_SUPERCEDE
		if (sample[14] == 'h' && sample[15] == 'i' && sample[16] == 't')
		{
			if (sample[17] == 'w')  return FMRES_SUPERCEDE
			else  return FMRES_SUPERCEDE
		}
		if (sample[14] == 's' && sample[15] == 't' && sample[16] == 'a')
			return FMRES_SUPERCEDE;
	}
	
	return FMRES_IGNORED
}

public fw_TraceLine(Float:vector_start[3], Float:vector_end[3], ignored_monster, id, handle)
{
	if(!is_user_alive(id))
		return FMRES_IGNORED	
	if(!Get_BitVar(g_InTempingAttack, id))
		return FMRES_IGNORED
	
	static Float:vecStart[3], Float:vecEnd[3], Float:v_angle[3], Float:v_forward[3], Float:view_ofs[3], Float:fOrigin[3]
	
	pev(id, pev_origin, fOrigin)
	pev(id, pev_view_ofs, view_ofs)
	xs_vec_add(fOrigin, view_ofs, vecStart)
	pev(id, pev_v_angle, v_angle)
	
	engfunc(EngFunc_MakeVectors, v_angle)
	get_global_vector(GL_v_forward, v_forward)

	xs_vec_mul_scalar(v_forward, 0.0, v_forward)
	xs_vec_add(vecStart, v_forward, vecEnd)
	
	engfunc(EngFunc_TraceLine, vecStart, vecEnd, ignored_monster, id, handle)
	
	return FMRES_SUPERCEDE
}

public fw_TraceHull(Float:vector_start[3], Float:vector_end[3], ignored_monster, hull, id, handle)
{
	if(!is_user_alive(id))
		return FMRES_IGNORED	
	if(!Get_BitVar(g_InTempingAttack, id))
		return FMRES_IGNORED
	
	static Float:vecStart[3], Float:vecEnd[3], Float:v_angle[3], Float:v_forward[3], Float:view_ofs[3], Float:fOrigin[3]
	
	pev(id, pev_origin, fOrigin)
	pev(id, pev_view_ofs, view_ofs)
	xs_vec_add(fOrigin, view_ofs, vecStart)
	pev(id, pev_v_angle, v_angle)
	
	engfunc(EngFunc_MakeVectors, v_angle)
	get_global_vector(GL_v_forward, v_forward)
	
	xs_vec_mul_scalar(v_forward, 0.0, v_forward)
	xs_vec_add(vecStart, v_forward, vecEnd)
	
	engfunc(EngFunc_TraceHull, vecStart, vecEnd, ignored_monster, hull, id, handle)
	
	return FMRES_SUPERCEDE
}

public Create_FakeAttackAnim(id)
{
	Set_BitVar(g_InTempingAttack, id)
	
	static Ent; Ent = fm_get_user_weapon_entity(id, CSW_KNIFE)
	if(pev_valid(Ent)) ExecuteHamB(Ham_Weapon_PrimaryAttack, Ent)
	
	UnSet_BitVar(g_InTempingAttack, id)
}

public fw_Item_Deploy_Post(Ent)
{
	if(pev_valid(Ent) != 2)
		return
	static Id; Id = get_pdata_cbase(Ent, 41, 4)
	if(get_pdata_cbase(Id, 373) != Ent)
		return
	if(!Get_BitVar(g_Had_Thanatos3, Id))
		return
	
	set_pev(Id, pev_viewmodel2, V_MODEL)
	set_pev(Id, pev_weaponmodel2, P_MODEL)
	
	switch(g_Thanatos3_Stage[Id])
	{
		case STAGE_NONE: Set_WeaponAnim(Id, ANIME_DRAW)
		case STAGE_ULTIMATE: Set_WeaponAnim(Id, ANIME_DRAW_W1)
		case STAGE_OMEGA: Set_WeaponAnim(Id, ANIME_DRAW_W2)
		case STAGE_METATRON: Set_WeaponAnim(Id, ANIME_DRAW_W3)
	}
	
	set_pdata_string(Id, (492) * 4, ANIME_EXT, -1 , 20)
}

public fw_Item_AddToPlayer_Post(Ent, id)
{
	if(!pev_valid(Ent))
		return HAM_IGNORED
		
	if(pev(Ent, pev_impulse) == 25112015)
	{
		Set_BitVar(g_Had_Thanatos3, id)
		set_pev(Ent, pev_impulse, 0)
		
		g_Thanatos3_Count[id] = pev(Ent, pev_iuser3)
		g_Thanatos3_Stage[id] = pev(Ent, pev_iuser4)
	}

	return HAM_HANDLED	
}

public fw_Weapon_WeaponIdle_Post( iEnt )
{
	if(pev_valid(iEnt) != 2)
		return
	static Id; Id = get_pdata_cbase(iEnt, 41, 4)
	if(get_pdata_cbase(Id, 373) != iEnt)
		return
	if(!Get_BitVar(g_Had_Thanatos3, Id))
		return
		
	if(get_pdata_float(iEnt, 48, 4) <= 0.1)
	{
		switch(g_Thanatos3_Stage[Id])
		{
			case STAGE_NONE: Set_WeaponAnim(Id, ANIME_IDLE)
			case STAGE_ULTIMATE: Set_WeaponAnim(Id, ANIME_IDLE_W1)
			case STAGE_OMEGA: Set_WeaponAnim(Id, ANIME_IDLE_W2)
			case STAGE_METATRON: Set_WeaponAnim(Id, ANIME_IDLE_W3)
		}
		
		set_pdata_float(iEnt, 48, 20.0, 4)
	}	
}

public fw_TraceAttack_World(Victim, Attacker, Float:Damage, Float:Direction[3], Ptr, DamageBits)
{
	if(!is_user_connected(Attacker))
		return HAM_IGNORED	
	if(get_user_weapon(Attacker) != CSW_THANATOS3 || !Get_BitVar(g_Had_Thanatos3, Attacker))
		return HAM_IGNORED
		
	static Float:flEnd[3], Float:vecPlane[3]
		
	get_tr2(Ptr, TR_vecEndPos, flEnd)
	get_tr2(Ptr, TR_vecPlaneNormal, vecPlane)		
			
	Make_BulletHole(Attacker, flEnd, Damage)
	Make_BulletSmoke(Attacker, Ptr)

	SetHamParamFloat(3, float(DAMAGE))
	
	return HAM_IGNORED
}

public fw_TraceAttack_Player(Victim, Attacker, Float:Damage, Float:Direction[3], Ptr, DamageBits)
{
	if(!is_user_connected(Attacker))
		return HAM_IGNORED	
	if(get_user_weapon(Attacker) != CSW_THANATOS3 || !Get_BitVar(g_Had_Thanatos3, Attacker))
		return HAM_IGNORED
		
	SetHamParamFloat(3, float(DAMAGE))
	
	return HAM_IGNORED
}

public fw_Item_PostFrame(ent)
{
	static id; id = pev(ent, pev_owner)
	if(!is_user_alive(id))
		return HAM_IGNORED
	if(!Get_BitVar(g_Had_Thanatos3, id))
		return HAM_IGNORED	
	
	static Float:flNextAttack; flNextAttack = get_pdata_float(id, 83, 5)
	static bpammo; bpammo = cs_get_user_bpammo(id, CSW_THANATOS3)
	
	static iClip; iClip = get_pdata_int(ent, 51, 4)
	static fInReload; fInReload = get_pdata_int(ent, 54, 4)
	
	if(fInReload && flNextAttack <= 0.0)
	{
		static temp1
		temp1 = min(CLIP - iClip, bpammo)

		set_pdata_int(ent, 51, iClip + temp1, 4)
		cs_set_user_bpammo(id, CSW_THANATOS3, bpammo - temp1)		
		
		set_pdata_int(ent, 54, 0, 4)
		
		fInReload = 0
	}		
	
	return HAM_IGNORED
}

public fw_Weapon_Reload(ent)
{
	static id; id = pev(ent, pev_owner)
	if(!is_user_alive(id))
		return HAM_IGNORED
	if(!Get_BitVar(g_Had_Thanatos3, id))
		return HAM_IGNORED	

	g_Thanatos3_Clip[id] = -1
		
	static BPAmmo; BPAmmo = cs_get_user_bpammo(id, CSW_THANATOS3)
	static iClip; iClip = get_pdata_int(ent, 51, 4)
		
	if(BPAmmo <= 0)
		return HAM_SUPERCEDE
	if(iClip >= CLIP)
		return HAM_SUPERCEDE		
			
	g_Thanatos3_Clip[id] = iClip	
	
	return HAM_HANDLED
}

public fw_Weapon_Reload_Post(ent)
{
	static id; id = pev(ent, pev_owner)
	if(!is_user_alive(id))
		return HAM_IGNORED
	if(!Get_BitVar(g_Had_Thanatos3, id))
		return HAM_IGNORED	
		
	if((get_pdata_int(ent, 54, 4) == 1))
	{ // Reload
		if(g_Thanatos3_Clip[id] == -1)
			return HAM_IGNORED
		
		set_pdata_int(ent, 51, g_Thanatos3_Clip[id], 4)
		set_pdata_float(id, 83, RELOAD_TIME, 5)
		set_pdata_float(ent, 48, 3.5, 4)
		
		switch(g_Thanatos3_Stage[id])
		{
			case STAGE_NONE: Set_WeaponAnim(id, ANIME_RELOAD)
			case STAGE_ULTIMATE: Set_WeaponAnim(id, ANIME_RELOAD_W1)
			case STAGE_OMEGA: Set_WeaponAnim(id, ANIME_RELOAD_W2)
			case STAGE_METATRON: Set_WeaponAnim(id, ANIME_RELOAD_W3)
		}
	}
	
	return HAM_HANDLED
}

public fw_Weapon_PrimaryAttack_Post(Ent)
{
	static id; id = pev(Ent, pev_owner)
	if(!is_user_alive(id))
		return HAM_IGNORED
	if(!Get_BitVar(g_Had_Thanatos3, id))
		return HAM_IGNORED
		
	set_pdata_float(Ent, 48, 0.5, 4)
	return HAM_IGNORED
}

// Drop primary/secondary weapons
stock drop_weapons(id, dropwhat)
{
	// Get user weapons
	static weapons[32], num, i, weaponid
	num = 0 // reset passed weapons count (bugfix)
	get_user_weapons(id, weapons, num)
	
	// Loop through them and drop primaries or secondaries
	for (i = 0; i < num; i++)
	{
		// Prevent re-indexing the array
		weaponid = weapons[i]
		
		if ((dropwhat == 1 && ((1<<weaponid) & PRIMARY_WEAPONS_BIT_SUM)) || (dropwhat == 2 && ((1<<weaponid) & SECONDARY_WEAPONS_BIT_SUM)))
		{
			// Get weapon entity
			static wname[32]; get_weaponname(weaponid, wname, charsmax(wname))
			engclient_cmd(id, "drop", wname)
		}
	}
}

stock Set_Player_NextAttack(id, Float:NextTime) set_pdata_float(id, 83, NextTime, 5)

stock Set_WeaponAnim(id, anim)
{
	set_pev(id, pev_weaponanim, anim)
	
	message_begin(MSG_ONE_UNRELIABLE, SVC_WEAPONANIM, {0, 0, 0}, id)
	write_byte(anim)
	write_byte(pev(id, pev_body))
	message_end()
}

stock Eject_Shell(id, Shell_ModelIndex, Float:Time) // By Dias
{
	static Ent; Ent = get_pdata_cbase(id, 373, 5)
	if(!pev_valid(Ent))
		return

        set_pdata_int(Ent, 57, Shell_ModelIndex, 4)
        set_pdata_float(id, 111, get_gametime() + Time)
}

stock Make_BulletHole(id, Float:Origin[3], Float:Damage)
{
	// Find target
	static Decal; Decal = random_num(41, 45)
	static LoopTime; 
	
	if(Damage > 100.0) LoopTime = 2
	else LoopTime = 1
	
	for(new i = 0; i < LoopTime; i++)
	{
		// Put decal on "world" (a wall)
		message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
		write_byte(TE_WORLDDECAL)
		engfunc(EngFunc_WriteCoord, Origin[0])
		engfunc(EngFunc_WriteCoord, Origin[1])
		engfunc(EngFunc_WriteCoord, Origin[2])
		write_byte(Decal)
		message_end()
		
		// Show sparcles
		message_begin(MSG_BROADCAST, SVC_TEMPENTITY)
		write_byte(TE_GUNSHOTDECAL)
		engfunc(EngFunc_WriteCoord, Origin[0])
		engfunc(EngFunc_WriteCoord, Origin[1])
		engfunc(EngFunc_WriteCoord, Origin[2])
		write_short(id)
		write_byte(Decal)
		message_end()
	}
}

stock Make_BulletSmoke(id, TrResult)
{
	static Float:vecSrc[3], Float:vecEnd[3], TE_FLAG
	
	get_weapon_attachment(id, vecSrc)
	global_get(glb_v_forward, vecEnd)
    
	xs_vec_mul_scalar(vecEnd, 8192.0, vecEnd)
	xs_vec_add(vecSrc, vecEnd, vecEnd)

	get_tr2(TrResult, TR_vecEndPos, vecSrc)
	get_tr2(TrResult, TR_vecPlaneNormal, vecEnd)
    
	xs_vec_mul_scalar(vecEnd, 2.5, vecEnd)
	xs_vec_add(vecSrc, vecEnd, vecEnd)
    
	TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
	TE_FLAG |= TE_EXPLFLAG_NOSOUND
	TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
	
	engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, vecEnd, 0)
	write_byte(TE_EXPLOSION)
	engfunc(EngFunc_WriteCoord, vecEnd[0])
	engfunc(EngFunc_WriteCoord, vecEnd[1])
	engfunc(EngFunc_WriteCoord, vecEnd[2] - 10.0)
	write_short(g_SmokePuff_SprId)
	write_byte(2)
	write_byte(50)
	write_byte(TE_FLAG)
	message_end()
}

stock get_weapon_attachment(id, Float:output[3], Float:fDis = 40.0)
{ 
	static Float:vfEnd[3], viEnd[3] 
	get_user_origin(id, viEnd, 3)  
	IVecFVec(viEnd, vfEnd) 
	
	static Float:fOrigin[3], Float:fAngle[3]
	
	pev(id, pev_origin, fOrigin) 
	pev(id, pev_view_ofs, fAngle)
	
	xs_vec_add(fOrigin, fAngle, fOrigin) 
	
	static Float:fAttack[3]
	
	xs_vec_sub(vfEnd, fOrigin, fAttack)
	xs_vec_sub(vfEnd, fOrigin, fAttack) 
	
	static Float:fRate
	
	fRate = fDis / vector_length(fAttack)
	xs_vec_mul_scalar(fAttack, fRate, fAttack)
	
	xs_vec_add(fOrigin, fAttack, output)
}

stock get_position(id,Float:forw, Float:right, Float:up, Float:vStart[])
{
	new Float:vOrigin[3], Float:vAngle[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
	
	pev(id, pev_origin, vOrigin)
	pev(id, pev_view_ofs,vUp) //for player
	xs_vec_add(vOrigin,vUp,vOrigin)
	pev(id, pev_v_angle, vAngle) // if normal entity ,use pev_angles
	
	angle_vector(vAngle,ANGLEVECTOR_FORWARD,vForward) //or use EngFunc_AngleVectors
	angle_vector(vAngle,ANGLEVECTOR_RIGHT,vRight)
	angle_vector(vAngle,ANGLEVECTOR_UP,vUp)
	
	vStart[0] = vOrigin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
	vStart[1] = vOrigin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
	vStart[2] = vOrigin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
}

stock get_speed_vector(const Float:origin1[3],const Float:origin2[3],Float:speed, Float:new_velocity[3])
{
	new_velocity[0] = origin2[0] - origin1[0]
	new_velocity[1] = origin2[1] - origin1[1]
	new_velocity[2] = origin2[2] - origin1[2]
	new Float:num = floatsqroot(speed*speed / (new_velocity[0]*new_velocity[0] + new_velocity[1]*new_velocity[1] + new_velocity[2]*new_velocity[2]))
	new_velocity[0] *= num
	new_velocity[1] *= num
	new_velocity[2] *= num
	
	return 1;
}

stock Set_WeaponIdleTime(id, WeaponId ,Float:TimeIdle)
{
	static entwpn; entwpn = fm_get_user_weapon_entity(id, WeaponId)
	if(!pev_valid(entwpn)) 
		return
		
	set_pdata_float(entwpn, 46, TimeIdle, 4)
	set_pdata_float(entwpn, 47, TimeIdle, 4)
	set_pdata_float(entwpn, 48, TimeIdle + 0.5, 4)
}
Image

czirimbolo
Veteran Member
Veteran Member
Poland
Posts: 446
Joined: 2 Years Ago
Has thanked: 18 times
Been thanked: 1 time
Contact:

#9

Post by czirimbolo » 6 Months Ago

2nd weapon to block:

Code: Select all

/* Plugin generated by AMXX-Studio */
 
#include <zombie_escape>
#include <fakemeta_util>
#include <engine>
#include <xs>
 
#define PLUGIN "Magnum Lancer"
#define VERSION "2.0"
#define AUTHOR "Bim Bim Cay"

#define VIP_FLAG "VIP_A"
 
// Models
#define v_model "models/v_sgmissile.mdl"
#define w_model "models/w_sgmissile.mdl"
#define p_modela "models/p_sgmissile_a.mdl"
#define p_modelb "models/p_sgmissile_b.mdl"
 
// Sounds
#define attack1_sound "weapons/sgmissile-1.wav"
#define attack2_sound "weapons/sgmissile-2.wav"
#define reload_sound "weapons/sgmissile_reload.wav"
#define explode_sound "weapons/sgmissile_exp.wav"
 
// Sprites
#define ef_ball "sprites/ef_sgmissile_line.spr"
#define ef_explode "sprites/ef_sgmissile.spr"
#define muzzle_flash1 "sprites/muzzleflash64.spr"
#define muzzle_flash2 "sprites/muzzleflash75.spr"
 
// Anims
#define ANIM_IDLE       0
#define ANIM_RELOAD     1
#define ANIM_DRAW       2
#define ANIM_SHOOT      3
#define ANIM_IDLEB      4
#define ANIM_RELOADB        5
#define ANIM_DRAWB      6
#define ANIM_SHOOTB1        7
#define ANIM_SHOOTB2        8
#define ANIM_SHOOTMISSLE    9
#define ANIM_SHOOTMISSLELAST    10
#define ANIM_MISSLEON       11
 
#define ANIM_EXTENSION      "m249"
 
// Entity Classname
#define BALL_CLASSNAME "Magnum_EfBall"
#define LINE_CLASSNAME "Magnum_EfLine"
#define MUZZLEFLASH1_CLASSNAME "Muzzle_MagnumLancer1"
#define MUZZLEFLASH2_CLASSNAME "Muzzle_MagnumLancer2"
 
// Configs
#define WEAPON_NAME         "weapon_sgmissile"
#define WEAPON_BASE     "weapon_m3"
 
#define WEAPON_MAX_CLIP     30
#define WEAPON_DEFAULT_AMMO 90
#define WEAPON_MAX_BATTERY  7
 
#define WEAPON_SHOOT_DAMAGE 30.0
#define WEAPON_EXPLODE_DAMAGE   500.0
#define WEAPON_EXPLODE_RADIUS   75.0
 
#define WEAPON_TIME_NEXT_IDLE   10.0
#define WEAPON_TIME_NEXT_ATTACK 0.25
#define WEAPON_TIME_NEXT_ATTACK2 0.4
#define WEAPON_TIME_DELAY_DEPLOY 1.0
#define WEAPON_TIME_DELAY_RELOAD 2.0
#define WEAPON_TIME_DELAY_CHARGE 3.0
 
// MACROS
#define Get_BitVar(%1,%2) (%1 & (1 << (%2 & 31)))
#define Set_BitVar(%1,%2) %1 |= (1 << (%2 & 31))
#define UnSet_BitVar(%1,%2) %1 &= ~(1 << (%2 & 31))
 
#define INSTANCE(%0) ((%0 == -1) ? 0 : %0)
#define IsValidPev(%0) (pev_valid(%0) == 2)
#define IsObserver(%0) pev(%0,pev_iuser1)
#define OBS_IN_EYE 4
#define MSGID_WEAPONLIST 78
 
new g_iszWeaponKey
new g_iForwardDecalIndex
new g_Fire_SprId
 
// Safety
new g_HamBot
new g_IsConnected, g_IsAlive, g_PlayerWeapon[33]
new g_iItemID
 
public plugin_init()
{
    register_plugin(PLUGIN, VERSION, AUTHOR)
   
    // Safety
    Register_SafetyFunc()
   
    // Forward
    register_forward(FM_UpdateClientData, "fw_UpdateClientData_Post", 1)
    register_forward(FM_TraceLine, "fw_TraceLine_Post", 1)
    register_forward(FM_PlaybackEvent, "fw_PlaybackEvent")
    register_forward(FM_SetModel, "fw_SetModel")
   
    unregister_forward(FM_DecalIndex, g_iForwardDecalIndex, 1)
   
    // Think
    register_think(MUZZLEFLASH1_CLASSNAME, "fw_MuzzleFlash1_Think")
    register_think(MUZZLEFLASH2_CLASSNAME, "fw_MuzzleFlash2_Think")
    register_think(BALL_CLASSNAME, "fw_Ball_Think")
    register_think(LINE_CLASSNAME, "fw_Line_Think")
   
    register_touch(BALL_CLASSNAME, "*", "fw_Ball_Touch")
   
    // Ham
    RegisterHam(Ham_Spawn, "weaponbox", "fw_Weaponbox_Spawn_Post", 1)
   
    RegisterHam(Ham_Item_Deploy, WEAPON_BASE, "fw_Item_Deploy_Post", 1)
    RegisterHam(Ham_Item_AddToPlayer, WEAPON_BASE, "fw_Item_AddToPlayer")
    RegisterHam(Ham_Item_PostFrame, WEAPON_BASE, "fw_Item_PostFrame")
    RegisterHam(Ham_Weapon_Reload, WEAPON_BASE, "fw_Weapon_Reload")
    RegisterHam(Ham_Weapon_WeaponIdle, WEAPON_BASE, "fw_Weapon_WeaponIdle")
    RegisterHam(Ham_Weapon_PrimaryAttack, WEAPON_BASE, "fw_Weapon_PrimaryAttack")
   
    RegisterHam(Ham_TraceAttack, "func_breakable", "fw_TraceAttack_Entity")
    RegisterHam(Ham_TraceAttack, "info_target", "fw_TraceAttack_Entity")
    RegisterHam(Ham_TraceAttack, "player", "fw_TraceAttack_Entity")
   
    g_iItemID = ze_register_item("Magnum", 400, 0)
    ze_set_item_vip(g_iItemID, VIP_FLAG)
}
 
public ze_select_item_pre(id, itemid)
{
    if (itemid != g_iItemID)
        return ZE_ITEM_AVAILABLE
 
    if (ze_is_user_zombie(id))
        return ZE_ITEM_DONT_SHOW
 
    return ZE_ITEM_AVAILABLE
}
 
public ze_select_item_post(id, itemid)
{
    if (itemid != g_iItemID)
        return
 
    Get_MyWeapon(id)
}
 
public plugin_precache()
{
    precache_model(v_model)
    precache_model(w_model)
    precache_model(p_modela)
    precache_model(p_modelb)
   
    precache_model(ef_ball)
    precache_model(muzzle_flash1)
    precache_model(muzzle_flash2)
   
    g_Fire_SprId = precache_model(ef_explode)
   
    precache_sound(attack1_sound)
    precache_sound(attack2_sound)
    precache_sound(reload_sound)
    precache_sound(explode_sound)
   
    new TextFile[32]
    formatex(TextFile, charsmax(TextFile), "sprites/%s.txt", WEAPON_NAME)
   
    precache_generic(TextFile)
   
    g_iszWeaponKey = engfunc(EngFunc_AllocString, WEAPON_NAME)
    g_iForwardDecalIndex = register_forward(FM_DecalIndex, "fw_DecalIndex_Post", 1)
   
    register_message(MSGID_WEAPONLIST, "MsgHook_WeaponList")
}
 
public client_putinserver(iPlayer)
{
    Safety_Connected(iPlayer)
   
    if(!g_HamBot && is_user_bot(iPlayer))
    {
        g_HamBot = 1
        set_task(0.1, "Register_HamBot", iPlayer)
    }
}
 
public Register_HamBot(iPlayer)
{
    Register_SafetyFuncBot(iPlayer)
    RegisterHamFromEntity(Ham_TraceAttack, iPlayer, "fw_TraceAttack_Entity")   
}
 
public client_disconnected(iPlayer)
{
    Safety_Disconnected(iPlayer)
}
 
public Get_MyWeapon(iPlayer)
{
    Weapon_Give(iPlayer)
}
 
public fw_UpdateClientData_Post(iPlayer, sendweapons, CD_Handle)
{
    enum
    {
        SPEC_MODE,
        SPEC_TARGET,
        SPEC_END
    }
     
    static aSpecInfo[33][SPEC_END]
   
    static iTarget
    static iSpecMode
    static iActiveItem
   
    iTarget = (iSpecMode = IsObserver(iPlayer)) ? pev(iPlayer, pev_iuser2) : iPlayer
   
    if(!is_alive(iTarget))
        return FMRES_IGNORED
   
    iActiveItem = get_pdata_cbase(iTarget, 373, 5)
   
    if(!IsValidPev(iActiveItem) || !IsCustomItem(iActiveItem))
        return FMRES_IGNORED
   
    if(iSpecMode)
    {
        if(aSpecInfo[iPlayer][SPEC_MODE] != iSpecMode)
        {
            aSpecInfo[iPlayer][SPEC_MODE] = iSpecMode
            aSpecInfo[iPlayer][SPEC_TARGET] = 0
        }
       
        if(iSpecMode == OBS_IN_EYE && aSpecInfo[iPlayer][SPEC_TARGET] != iTarget)
        {
            aSpecInfo[iPlayer][SPEC_TARGET] = iTarget
           
            if(get_pdata_int(iActiveItem, 30, 4))
            {
                Weapon_SendAnim(iPlayer, iActiveItem, ANIM_IDLEB)
            }
            else
            {
                Weapon_SendAnim(iPlayer, iActiveItem, ANIM_IDLE)
            }
        }
    }
   
    set_cd(CD_Handle, CD_flNextAttack, get_gametime() + 0.001)
   
    return FMRES_HANDLED
}
 
public fw_TraceLine_Post(Float:TraceStart[3], Float:TraceEnd[3], fNoMonsters, iEntToSkip, iTrace) <FireBullets: Enabled>
{
    static Float:vecEndPos[3]
   
    get_tr2(iTrace, TR_vecEndPos, vecEndPos)
    engfunc(EngFunc_TraceLine, vecEndPos, TraceStart, fNoMonsters, iEntToSkip, 0)
   
    UTIL_GunshotDecalTrace(0)
    UTIL_GunshotDecalTrace(iTrace, true)
}
 
public fw_TraceLine_Post() </* Empty statement */>
{
    /* Fallback */
}
 
public fw_TraceLine_Post() <FireBullets: Disabled> 
{
    /* Do notning */
}
 
public fw_PlaybackEvent() <FireBullets: Enabled>
{
    return FMRES_SUPERCEDE
}
 
public fw_PlaybackEvent() </* Empty statement */>      
{
    return FMRES_IGNORED
}
 
public fw_PlaybackEvent() <FireBullets: Disabled>      
{
    return FMRES_IGNORED
}
 
//**********************************************
//* Weaponbox world model.                     *
//**********************************************
public fw_SetModel(iEntity) <WeaponBox: Enabled>
{
    state WeaponBox: Disabled
   
    if(!IsValidPev(iEntity))
        return FMRES_IGNORED
   
    #define MAX_ITEM_TYPES  6
    for(new i, iItem; i < MAX_ITEM_TYPES; i++)
    {
        iItem = get_pdata_cbase(iEntity, 34 + i, 4)
       
        if(IsValidPev(iItem) && IsCustomItem(iItem))
        {
            engfunc(EngFunc_SetModel, iEntity, w_model)
            return FMRES_SUPERCEDE
        }
    }
   
    return FMRES_IGNORED
}
 
public fw_SetModel() </* Empty statement */>   
{
    /*  Fallback  */
    return FMRES_IGNORED
}
public fw_SetModel() <WeaponBox: Disabled> 
{
    /* Do nothing */
    return FMRES_IGNORED
}
 
public fw_Weaponbox_Spawn_Post(iWeaponBox)
{
    if(IsValidPev(iWeaponBox))
    {
        state (IsValidPev(pev(iWeaponBox, pev_owner))) WeaponBox: Enabled
    }
   
    return HAM_IGNORED
}
 
//**********************************************
//* Weapon's codes.                     *
//**********************************************
public fw_Item_Deploy_Post(iItem)
{
    if(!IsCustomItem(iItem))
        return
       
    static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
    static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
 
    //I need to disable because there is no dummy anim
    //static Sex; Sex = 0 //Get your sex: 0 - Male; 1 - Female
    //set_pev(iItem, pev_body, Sex)
   
    set_pev(iPlayer, pev_viewmodel2, v_model)
   
    if(SecondaryAmmo)
    {
        set_pev(iPlayer, pev_weaponmodel2, p_modelb)
        Weapon_SendAnim(iPlayer, iItem, ANIM_DRAWB)
    }
    else
    {
        set_pev(iPlayer, pev_weaponmodel2, p_modela)
        Weapon_SendAnim(iPlayer, iItem, ANIM_DRAW)
    }
 
    Notice(iPlayer, SecondaryAmmo)
   
    set_pdata_float(iItem, 48, WEAPON_TIME_DELAY_DEPLOY, 4)
    set_pdata_float(iItem, 38, get_gametime() + WEAPON_TIME_DELAY_CHARGE + WEAPON_TIME_DELAY_DEPLOY, 4)
   
    set_pdata_string(iPlayer, (492) * 4, ANIM_EXTENSION, -1 , 20)
}
 
public fw_Item_PostFrame(iItem)
{
    if(!IsCustomItem(iItem))
        return HAM_IGNORED
   
    static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
   
    if(get_pdata_int(iItem, 54, 4))
    {
        static iClip; iClip = get_pdata_int(iItem, 51, 4)
        static iPrimaryAmmoIndex; iPrimaryAmmoIndex = PrimaryAmmoIndex(iItem)
        static iAmmoPrimary; iAmmoPrimary = GetAmmoInventory(iPlayer, iPrimaryAmmoIndex)
        static iAmount; iAmount = min(WEAPON_MAX_CLIP - iClip, iAmmoPrimary)
       
        set_pdata_int(iItem, 51, iClip + iAmount, 4)
        SetAmmoInventory(iPlayer, iPrimaryAmmoIndex, iAmmoPrimary - iAmount)
       
        set_pdata_int(iItem, 54, 0, 4)
        set_pdata_float(iItem, 38, get_gametime() + WEAPON_TIME_DELAY_CHARGE, 4)
       
        return HAM_IGNORED
    }  
   
    static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
    static Float:flLastEventCheck; flLastEventCheck = get_pdata_float(iItem, 38, 4)
   
    if(flLastEventCheck < get_gametime())
    {
        flLastEventCheck = get_gametime() + WEAPON_TIME_DELAY_CHARGE
        set_pdata_float(iItem, 38, flLastEventCheck, 4)
       
        if(SecondaryAmmo < WEAPON_MAX_BATTERY)
        {
            if(!SecondaryAmmo)
            {
                set_pdata_float(iItem, 48, 1.0, 4)
                Weapon_SendAnim(iPlayer, iItem, ANIM_MISSLEON)
 
                set_pev(iPlayer, pev_weaponmodel2, p_modelb)
            }
           
            SecondaryAmmo++
            set_pdata_int(iItem, 30, SecondaryAmmo, 4)
           
            Notice(iPlayer, SecondaryAmmo)
            emit_sound(iPlayer, CHAN_ITEM, reload_sound, 1.0, ATTN_NORM, 0, PITCH_NORM)
        }
    }
   
    static iButton; iButton = pev(iPlayer, pev_button)
   
    if(iButton & IN_ATTACK2)
    {
        iButton &= ~IN_ATTACK2
        iButton &= ~IN_ATTACK
        set_pev(iPlayer, pev_button, iButton)
       
        if(!SecondaryAmmo)
            return HAM_IGNORED
           
        if(get_pdata_float(iItem, 47, 4) > 0.0)
            return HAM_IGNORED
           
        set_pdata_float(iItem, 38, get_gametime() + WEAPON_TIME_DELAY_CHARGE, 4)   
       
        set_pdata_float(iItem, 46, WEAPON_TIME_NEXT_ATTACK2, 4)
        set_pdata_float(iItem, 47, WEAPON_TIME_NEXT_ATTACK2, 4)
       
        emit_sound(iPlayer, CHAN_WEAPON, attack2_sound, 1.0, 0.4, 0, 94 + random_num(0, 15))
       
        if(SecondaryAmmo > 1)
        {
            Weapon_SendAnim(iPlayer, iItem, ANIM_SHOOTMISSLE)
            set_pdata_float(iItem, 48, 0.87, 4)
        }
        else
        {
            Weapon_SendAnim(iPlayer, iItem, ANIM_SHOOTMISSLELAST)
            set_pdata_float(iItem, 48, 1.2, 4)
           
            set_pev(iPlayer, pev_weaponmodel2, p_modela)
        }
       
        static szAnimation[64]
       
        if(pev(iPlayer, pev_flags) & FL_DUCKING)
        {
            formatex(szAnimation, charsmax(szAnimation), "crouch_shoot_%s", ANIM_EXTENSION)
        }
        else
        {
            formatex(szAnimation, charsmax(szAnimation), "ref_shoot_%s", ANIM_EXTENSION)
        }
       
        Player_SetAnimation(iPlayer, szAnimation)
       
        SecondaryAmmo--
        set_pdata_int(iItem, 30, SecondaryAmmo, 4)
           
        Notice(iPlayer, SecondaryAmmo)
       
        Attack2(iPlayer)
        MakeMuzzleFlash2(iPlayer)
    }
   
    return HAM_IGNORED
}
 
public fw_Weapon_Reload(iItem)
{
    if(!IsCustomItem(iItem))
        return HAM_IGNORED
       
    static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
   
    static iClip; iClip = get_pdata_int(iItem, 51, 4)
    static iPrimaryAmmoIndex; iPrimaryAmmoIndex = PrimaryAmmoIndex(iItem)
    static iAmmoPrimary; iAmmoPrimary = GetAmmoInventory(iPlayer, iPrimaryAmmoIndex)
   
    if(min(WEAPON_MAX_CLIP - iClip, iAmmoPrimary) <= 0)
        return HAM_SUPERCEDE
   
    set_pdata_int(iItem, 51, 0, 4)
   
    ExecuteHam(Ham_Weapon_Reload, iItem)
   
    //Remove shotgun reload
    set_pdata_int(iItem, 55, 0, 4)
    set_pdata_int(iItem, 54, 1, 4)
   
    set_pdata_int(iItem, 51, iClip, 4)
   
    set_pdata_float(iPlayer, 83, WEAPON_TIME_DELAY_RELOAD, 5)
    set_pdata_float(iItem, 48, WEAPON_TIME_DELAY_RELOAD, 4)
   
    static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
   
    if(SecondaryAmmo)
    {
        Weapon_SendAnim(iPlayer, iItem, ANIM_RELOADB)
    }
    else
    {
        Weapon_SendAnim(iPlayer, iItem, ANIM_RELOAD)
    }
   
    return HAM_SUPERCEDE   
}
 
public fw_Weapon_WeaponIdle(iItem)
{
    if(!IsCustomItem(iItem))
        return HAM_IGNORED
       
    static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
   
    ExecuteHamB(Ham_Weapon_ResetEmptySound, iItem)
 
    if(get_pdata_float(iItem, 48, 4) > 0.0)
        return HAM_SUPERCEDE
   
    set_pdata_float(iItem, 48, WEAPON_TIME_NEXT_IDLE, 4)
   
    static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
   
    if(SecondaryAmmo)
    {
        Weapon_SendAnim(iPlayer, iItem, ANIM_IDLEB)
    }
    else
    {
        Weapon_SendAnim(iPlayer, iItem, ANIM_IDLE)
    }
   
    return HAM_SUPERCEDE
}
 
public fw_Weapon_PrimaryAttack(iItem)
{
    if(!IsCustomItem(iItem))
        return HAM_IGNORED
       
    static iPlayer; iPlayer = get_pdata_cbase(iItem, 41, 4)
    static iClip; iClip = get_pdata_int(iItem, 51, 4)
   
    if(iClip <= 0)
    {
        // No ammo, play empty sound and cancel
        if(get_pdata_int(iItem, 45, 4))
        {
            ExecuteHamB(Ham_Weapon_PlayEmptySound, iItem)
            set_pdata_float(iItem, 46, 0.2, 4)
        }
   
        return HAM_SUPERCEDE
    }
   
    CallOriginalFireBullets(iItem, iPlayer)
   
    static iFlags
    static szAnimation[64], Float:Velocity[3]
 
    iFlags = pev(iPlayer, pev_flags)
   
    if(iFlags & FL_DUCKING)
    {
        formatex(szAnimation, charsmax(szAnimation), "crouch_shoot_%s", ANIM_EXTENSION)
    }
    else
    {
        formatex(szAnimation, charsmax(szAnimation), "ref_shoot_%s", ANIM_EXTENSION)
    }
   
    Player_SetAnimation(iPlayer, szAnimation)
   
    static SecondaryAmmo; SecondaryAmmo = get_pdata_int(iItem, 30, 4)
   
    if(SecondaryAmmo)
    {
        Weapon_SendAnim(iPlayer, iItem, random_num(ANIM_SHOOTB1, ANIM_SHOOTB2))
    }
    else
    {
        Weapon_SendAnim(iPlayer, iItem, ANIM_SHOOT)
    }
   
    set_pdata_float(iItem, 48, 0.7, 4)
    set_pdata_float(iItem, 46, WEAPON_TIME_NEXT_ATTACK, 4)
    set_pdata_float(iItem, 47, WEAPON_TIME_NEXT_ATTACK, 4)
   
    pev(iPlayer, pev_velocity, Velocity)
   
    if(xs_vec_len(Velocity) > 0)
    {
        Weapon_KickBack(iItem, iPlayer, 1.5, 0.45, 0.225, 0.05, 6.5, 2.5, 7)
    }
    else if(!(iFlags & FL_ONGROUND))
    {
        Weapon_KickBack(iItem, iPlayer, 2.0, 1.0, 0.5, 0.35, 9.0, 6.0, 5)
    }
    else if(iFlags & FL_DUCKING)
    {
        Weapon_KickBack(iItem, iPlayer, 0.9, 0.35, 0.15, 0.025, 5.5, 1.5, 9)
    }
    else
    {
        Weapon_KickBack(iItem, iPlayer, 1.0, 0.375, 0.175, 0.0375, 5.75, 1.75, 8)
    }
 
    emit_sound(iPlayer, CHAN_WEAPON, attack1_sound, 1.0, 0.4, 0, 94 + random_num(0, 15))
   
    MakeMuzzleFlash1(iPlayer)
   
    return HAM_SUPERCEDE
}
 
public fw_TraceAttack_Entity(iEntity, iAttacker, Float: flDamage) <FireBullets: Enabled>
{
    SetHamParamFloat(3, WEAPON_SHOOT_DAMAGE)
}
 
public fw_TraceAttack_Entity() </* Empty statement */>     
{
    /* Fallback */
}
 
public fw_TraceAttack_Entity() <FireBullets: Disabled>     
{
    /* Do notning */
}
 
//**********************************************
//* Weapon list update.                        *
//**********************************************
public fw_Item_AddToPlayer(iItem, iPlayer)
{
    if(!IsValidPev(iItem) || !IsValidPev(iPlayer))
        return HAM_IGNORED
   
    MsgHook_WeaponList(MSGID_WEAPONLIST, iItem, iPlayer)
   
    return HAM_IGNORED
}
 
public MsgHook_WeaponList(iMsgID, iMsgDest, iMsgEntity)
{
    static arrWeaponListData[8]
   
    if(!iMsgEntity)
    {
        new szWeaponName[32]
        get_msg_arg_string(1, szWeaponName, charsmax(szWeaponName))
       
        if(!strcmp(szWeaponName, WEAPON_BASE))
        {
            for(new i, a = sizeof arrWeaponListData; i < a; i++)
            {
                arrWeaponListData[i] = get_msg_arg_int(i + 2)
            }
        }
    }
    else
    {
        if(!IsCustomItem(iMsgDest) && pev(iMsgDest, pev_impulse))
            return
       
        engfunc(EngFunc_MessageBegin, MSG_ONE, iMsgID, {0.0, 0.0, 0.0}, iMsgEntity)
        write_string(IsCustomItem(iMsgDest) ? WEAPON_NAME : WEAPON_BASE)
       
        for(new i, a = sizeof arrWeaponListData; i < a; i++)
        {
            write_byte(arrWeaponListData[i])
        }
       
        message_end()
    }
}
 
//**********************************************
//* Effects                                    *
//**********************************************
Notice(iPlayer, SecondaryAmmo)
{
    client_print(iPlayer, print_center, "Fire Ammo: %d", SecondaryAmmo)
}
 
public MakeMuzzleFlash1(iPlayer)
{
    static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
    if(!pev_valid(Ent)) return
   
    set_pev(Ent, pev_classname, MUZZLEFLASH1_CLASSNAME)
   
    set_pev(Ent, pev_owner, iPlayer)
    set_pev(Ent, pev_body, 1)
    set_pev(Ent, pev_skin, iPlayer)
    set_pev(Ent, pev_aiment, iPlayer)
    set_pev(Ent, pev_movetype, MOVETYPE_FOLLOW)
   
    set_pev(Ent, pev_scale, 0.085)
    set_pev(Ent, pev_frame, 0.0)
    set_pev(Ent, pev_rendermode, kRenderTransAdd)
    set_pev(Ent, pev_renderamt, 255.0)
   
    engfunc(EngFunc_SetModel, Ent,  muzzle_flash1)
   
    set_pev(Ent, pev_nextthink, get_gametime() + 0.04)
}
 
public fw_MuzzleFlash1_Think(Ent)
{
    if(!pev_valid(Ent))
        return
   
    static Owner; Owner = pev(Ent, pev_owner)
   
    if(!is_alive(Owner))
    {
        set_pev(Ent, pev_flags, FL_KILLME)
        return
    }
   
    static iActiveItem; iActiveItem = get_pdata_cbase(Owner, 373, 5)
   
    if(!IsValidPev(iActiveItem) || !IsCustomItem(iActiveItem))
    {
        set_pev(Ent, pev_flags, FL_KILLME)
        return
    }
 
    static Float:Frame; pev(Ent, pev_frame, Frame)
    if(Frame > 8.0)
    {
        set_pev(Ent, pev_flags, FL_KILLME)
        return
    }
    else
    {
        Frame += 1.0
        set_pev(Ent, pev_frame, Frame)
    }
   
    set_pev(Ent, pev_nextthink, get_gametime() + 0.04)
}
 
public MakeMuzzleFlash2(iPlayer)
{
    static Ent
   
    for(new i = 2; i < 5; i++)
    {
        Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
        if(!pev_valid(Ent)) continue
   
        set_pev(Ent, pev_classname, MUZZLEFLASH2_CLASSNAME)
   
        set_pev(Ent, pev_owner, iPlayer)
        set_pev(Ent, pev_body, i)
        set_pev(Ent, pev_skin, iPlayer)
        set_pev(Ent, pev_aiment, iPlayer)
        set_pev(Ent, pev_movetype, MOVETYPE_FOLLOW)
   
        set_pev(Ent, pev_scale, 0.02)
        set_pev(Ent, pev_frame, 0.0)
        set_pev(Ent, pev_rendermode, kRenderTransAdd)
        set_pev(Ent, pev_renderamt, 255.0)
   
        engfunc(EngFunc_SetModel, Ent,  muzzle_flash2)
   
        set_pev(Ent, pev_nextthink, get_gametime() + 0.04)
    }
}
 
public fw_MuzzleFlash2_Think(Ent)
{
    if(!pev_valid(Ent))
        return
   
    static Owner; Owner = pev(Ent, pev_owner)
   
    if(!is_alive(Owner))
    {
        set_pev(Ent, pev_flags, FL_KILLME)
        return
    }
   
    static iActiveItem; iActiveItem = get_pdata_cbase(Owner, 373, 5)
   
    if(!IsValidPev(iActiveItem) || !IsCustomItem(iActiveItem))
    {
        set_pev(Ent, pev_flags, FL_KILLME)
        return
    }
   
    static Float:Frame; pev(Ent, pev_frame, Frame)
    if(Frame > 9.0)
    {
        set_pev(Ent, pev_flags, FL_KILLME)
        return
    }
    else
    {
        Frame += 1.0
        set_pev(Ent, pev_frame, Frame)
    }
   
    set_pev(Ent, pev_nextthink, get_gametime() + 0.04)
}
 
public Attack2(iPlayer)
{
    static Float:StartOrigin[3], Float:EndOrigin[9][3]
    Get_WeaponAttachment(iPlayer, StartOrigin, 40.0)
   
    // Left
    Get_Position(iPlayer, 512.0, 50.0, 0.0, EndOrigin[0])
    Get_Position(iPlayer, 512.0, 100.0, 0.0, EndOrigin[1])
    Get_Position(iPlayer, 512.0, 150.0, 0.0, EndOrigin[2])
    Get_Position(iPlayer, 512.0, 200.0, 0.0, EndOrigin[3])
   
    // Center
    Get_Position(iPlayer, 512.0, 0.0, 0.0, EndOrigin[4])
   
    // Right
    Get_Position(iPlayer, 512.0, -50.0, 0.0, EndOrigin[5])
    Get_Position(iPlayer, 512.0, -100.0, 0.0, EndOrigin[6])
    Get_Position(iPlayer, 512.0, -150.0, 0.0, EndOrigin[7])
    Get_Position(iPlayer, 512.0, -200.0, 0.0, EndOrigin[8])
   
    // Create Fire
    for(new i = 0; i < 9; i++) Create_System(iPlayer, StartOrigin, EndOrigin[i])
}
 
public Create_System(iPlayer, Float:StartOrigin[3], Float:EndOrigin[3])
{
    static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
   
    if(!pev_valid(Ent))
        return
       
    set_pev(Ent, pev_classname, BALL_CLASSNAME)
    set_pev(Ent, pev_movetype, MOVETYPE_FLYMISSILE)
    set_pev(Ent, pev_solid, SOLID_TRIGGER)
   
    engfunc(EngFunc_SetModel, Ent, ef_ball)
   
    set_pev(Ent, pev_rendermode, kRenderTransAdd)
    set_pev(Ent, pev_renderamt, 150.0)
    set_pev(Ent, pev_scale, 0.3)
    set_pev(Ent, pev_frame, 0.0)
   
    set_pev(Ent, pev_mins, Float:{-5.0, -5.0, -5.0})
    set_pev(Ent, pev_maxs, Float:{5.0, 5.0, 5.0})
   
    set_pev(Ent, pev_origin, StartOrigin)
   
    set_pev(Ent, pev_owner, iPlayer)   
    set_pev(Ent, pev_iuser3, get_user_team(iPlayer))
    set_pev(Ent, pev_fuser4, get_gametime())
   
    // Create Velocity
    static Float:Velocity[3]
    get_speed_vector(StartOrigin, EndOrigin, 1000.0, Velocity)//Or 750, 1500, 2000, 2500
    set_pev(Ent, pev_velocity, Velocity)   
   
    set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
}
 
public fw_Ball_Think(Ent)
{
    if(!pev_valid(Ent))
        return
       
    static Float:Frame
    pev(Ent, pev_frame, Frame)
   
    if(Frame > 14.0)
    {
        static Float:Amount
        pev(Ent, pev_renderamt, Amount)
       
        if(Amount <= 15.0)
        {
            set_pev(Ent, pev_flags, FL_KILLME)
            return
        }
       
        Amount -= 15.0
        set_pev(Ent, pev_renderamt, Amount)
       
        set_pev(Ent, pev_nextthink, get_gametime() + 0.01)
    }
    else
    {
        Frame += 1.0
        set_pev(Ent, pev_frame, Frame)
       
        static Float:Origin[3]
        pev(Ent, pev_origin, Origin)
       
        static Float:Scale
        pev(Ent, pev_scale, Scale)
       
        Scale += 0.02
        set_pev(Ent, pev_scale, Scale)
       
        static Float:Time
        pev(Ent, pev_fuser4, Time)
       
        Create_Line(Origin)
        set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
    }
}
 
public fw_Ball_Touch(Ent, Touch)
{
    if(!pev_valid(Ent))
        return
   
    static Classname[36]; pev(Touch, pev_classname, Classname, sizeof(Classname))
   
    if(equali(Classname, BALL_CLASSNAME))
        return
   
    static Float:Origin[3]
    pev(Ent, pev_origin, Origin)
   
    static TE_FLAG
   
    TE_FLAG |= TE_EXPLFLAG_NODLIGHTS
    TE_FLAG |= TE_EXPLFLAG_NOSOUND
    TE_FLAG |= TE_EXPLFLAG_NOPARTICLES
   
    message_begin(MSG_BROADCAST ,SVC_TEMPENTITY)
    write_byte(TE_EXPLOSION)
    engfunc(EngFunc_WriteCoord, Origin[0])
    engfunc(EngFunc_WriteCoord, Origin[1])
    engfunc(EngFunc_WriteCoord, Origin[2])
    write_short(g_Fire_SprId)   // sprite index
    write_byte(15)  // scale in 3.4's
    write_byte(15)  // framerate
    write_byte(TE_FLAG) // flags
    message_end()
   
    emit_sound(Ent, CHAN_BODY, explode_sound, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
   
    static Team; Team = pev(Ent, pev_iuser3)
    static Owner; Owner = pev(Ent, pev_owner)
   
    static Victim; Victim = -1
    while((Victim = find_ent_in_sphere(Victim, Origin, WEAPON_EXPLODE_RADIUS)) != 0)
    {
        if(is_alive(Victim))
        {
            if(get_user_team(Victim) == Team)
                continue
        }
        else
        {
            if(pev(Victim, pev_takedamage) == DAMAGE_NO)
                continue
        }
       
        ExecuteHamB(Ham_TakeDamage, Victim, Owner, Owner, WEAPON_EXPLODE_DAMAGE, DMG_BULLET)
    }
   
    set_pev(Ent, pev_flags, FL_KILLME) 
}
 
public Create_Line(Float:Origin[3])
{
    static Ent; Ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "info_target"))
   
    if(!pev_valid(Ent))
        return
   
    set_pev(Ent, pev_classname, LINE_CLASSNAME)
    set_pev(Ent, pev_movetype, MOVETYPE_FLYMISSILE)
    set_pev(Ent, pev_solid, SOLID_NOT)
   
    engfunc(EngFunc_SetModel, Ent, ef_ball)
   
    set_pev(Ent, pev_rendermode, kRenderTransAdd)
    set_pev(Ent, pev_renderamt, 120.0)
    set_pev(Ent, pev_scale, 0.3)
    set_pev(Ent, pev_frame, 0.0)
   
    set_pev(Ent, pev_origin, Origin)
   
    set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
}
 
public fw_Line_Think(Ent)
{
    if(!pev_valid(Ent))
        return
       
    static Float:Amount
    pev(Ent, pev_renderamt, Amount)
   
    if(Amount <= 15.0)
    {
        set_pev(Ent, pev_flags, FL_KILLME)
        return
    }
   
    Amount -= 15.0
    set_pev(Ent, pev_renderamt, Amount)
   
    set_pev(Ent, pev_nextthink, get_gametime() + 0.05)
}
/* ===============================
------------- SAFETY -------------
=================================*/
public Register_SafetyFunc()
{
    register_event("CurWeapon", "Safety_CurWeapon", "be", "1=1")
   
    RegisterHam(Ham_Spawn, "player", "fw_Safety_Spawn_Post", 1)
    RegisterHam(Ham_Killed, "player", "fw_Safety_Killed_Post", 1)
}
 
public Register_SafetyFuncBot(iPlayer)
{
    RegisterHamFromEntity(Ham_Spawn, iPlayer, "fw_Safety_Spawn_Post", 1)
    RegisterHamFromEntity(Ham_Killed, iPlayer, "fw_Safety_Killed_Post", 1)
}
 
public Safety_Connected(iPlayer)
{
    Set_BitVar(g_IsConnected, iPlayer)
    UnSet_BitVar(g_IsAlive, iPlayer)
   
    g_PlayerWeapon[iPlayer] = 0
}
 
public Safety_Disconnected(iPlayer)
{
    UnSet_BitVar(g_IsConnected, iPlayer)
    UnSet_BitVar(g_IsAlive, iPlayer)
   
    g_PlayerWeapon[iPlayer] = 0
}
 
public Safety_CurWeapon(iPlayer)
{
    if(!is_alive(iPlayer))
        return
       
    static CSW; CSW = read_data(2)
    if(g_PlayerWeapon[iPlayer] != CSW) g_PlayerWeapon[iPlayer] = CSW
}
 
public fw_Safety_Spawn_Post(iPlayer)
{
    if(!is_user_alive(iPlayer))
        return
       
    Set_BitVar(g_IsAlive, iPlayer)
}
 
public fw_Safety_Killed_Post(iPlayer)
{
    UnSet_BitVar(g_IsAlive, iPlayer)
}
 
public is_connected(iPlayer)
{
    if(!(1 <= iPlayer <= 32))
        return 0
    if(!Get_BitVar(g_IsConnected, iPlayer))
        return 0
 
    return 1
}
 
public is_alive(iPlayer)
{
    if(!is_connected(iPlayer))
        return 0
    if(!Get_BitVar(g_IsAlive, iPlayer))
        return 0
       
    return 1
}
 
public get_player_weapon(iPlayer)
{
    if(!is_alive(iPlayer))
        return 0
   
    return g_PlayerWeapon[iPlayer]
}
 
/* ===============================
--------- END OF SAFETY  ---------
=================================*/
 
//**********************************************
//* Create and check our custom weapon.        *
//**********************************************
IsCustomItem(iItem)
{
    return (pev(iItem, pev_impulse) == g_iszWeaponKey)
}
 
Weapon_Create(Float: Origin[3] = {0.0, 0.0, 0.0}, Float: Angles[3] = {0.0, 0.0, 0.0})
{
    new iWeapon
 
    static iszAllocStringCached
    if (iszAllocStringCached || (iszAllocStringCached = engfunc(EngFunc_AllocString, WEAPON_BASE)))
    {
        iWeapon = engfunc(EngFunc_CreateNamedEntity, iszAllocStringCached)
    }
   
    if(!IsValidPev(iWeapon))
        return FM_NULLENT
   
    dllfunc(DLLFunc_Spawn, iWeapon)
    set_pev(iWeapon, pev_origin, Origin)
 
    set_pdata_int(iWeapon, 51, WEAPON_MAX_CLIP, 4)
    set_pdata_int(iWeapon, 30, 0, 4)
 
    set_pev_string(iWeapon, pev_classname, g_iszWeaponKey)
    set_pev(iWeapon, pev_impulse, g_iszWeaponKey)
    set_pev(iWeapon, pev_angles, Angles)
   
    engfunc(EngFunc_SetModel, iWeapon, w_model)
 
    return iWeapon
}
 
Weapon_Give(iPlayer)
{
    if(!IsValidPev(iPlayer))
    {
        return FM_NULLENT
    }
   
    new iWeapon, Float: vecOrigin[3]
    pev(iPlayer, pev_origin, vecOrigin)
   
    if((iWeapon = Weapon_Create(vecOrigin)) != FM_NULLENT)
    {
        Player_DropWeapons(iPlayer, ExecuteHamB(Ham_Item_ItemSlot, iWeapon))
       
        set_pev(iWeapon, pev_spawnflags, pev(iWeapon, pev_spawnflags) | SF_NORESPAWN)
        dllfunc(DLLFunc_Touch, iWeapon, iPlayer)
       
        SetAmmoInventory(iPlayer, PrimaryAmmoIndex(iWeapon), WEAPON_DEFAULT_AMMO)
       
        return iWeapon
    }
   
    return FM_NULLENT
}
 
Player_DropWeapons(iPlayer, iSlot)
{
    new szWeaponName[32], iItem = get_pdata_cbase(iPlayer, 367 + iSlot, 5)
 
    while(IsValidPev(iItem))
    {
        pev(iItem, pev_classname, szWeaponName, charsmax(szWeaponName))
        engclient_cmd(iPlayer, "drop", szWeaponName)
 
        iItem = get_pdata_cbase(iItem, 42, 4)
    }
}
 
//**********************************************
//* Ammo Inventory.                            *
//**********************************************
PrimaryAmmoIndex(iItem)
{
    return get_pdata_int(iItem, 49, 4)
}
 
GetAmmoInventory(iPlayer, iAmmoIndex)
{
    if(iAmmoIndex == -1)
        return -1
   
    return get_pdata_int(iPlayer, 376 + iAmmoIndex, 5)
}
 
SetAmmoInventory(iPlayer, iAmmoIndex, iAmount)
{
    if(iAmmoIndex == -1)
        return 0
   
    set_pdata_int(iPlayer, 376 + iAmmoIndex, iAmount, 5)
   
    return 1
}
 
//**********************************************
//* Fire Bullets.                              *
//**********************************************
CallOriginalFireBullets(iItem, iPlayer)
{
    state FireBullets: Enabled
    static Float:g_Recoil[3]
 
    pev(iPlayer, pev_punchangle, g_Recoil)
    ExecuteHam(Ham_Weapon_PrimaryAttack, iItem)
    set_pev(iPlayer, pev_punchangle, g_Recoil)
   
    state FireBullets: Disabled
}
 
//**********************************************
//* Decals.                                    *
//**********************************************
new Array: g_hDecals
 
public fw_DecalIndex_Post()
{
    if(!g_hDecals)
    {
        g_hDecals = ArrayCreate(1, 1)
    }
   
    ArrayPushCell(g_hDecals, get_orig_retval())
}
 
UTIL_GunshotDecalTrace(iTrace, bool: bIsGunshot = false)
{
    static iHit
    static iMessage
    static iDecalIndex
   
    static Float:flFraction
    static Float:vecEndPos[3]
   
    iHit = INSTANCE(get_tr2(iTrace, TR_pHit))
   
    if(iHit && !IsValidPev(iHit) || (pev(iHit, pev_flags) & FL_KILLME))
        return
   
    if(pev(iHit, pev_solid) != SOLID_BSP && pev(iHit, pev_movetype) != MOVETYPE_PUSHSTEP)
        return
   
    iDecalIndex = ExecuteHamB(Ham_DamageDecal, iHit, 0)
   
    if(iDecalIndex < 0 || iDecalIndex >=  ArraySize(g_hDecals))
        return
   
    iDecalIndex = ArrayGetCell(g_hDecals, iDecalIndex)
   
    get_tr2(iTrace, TR_flFraction, flFraction)
    get_tr2(iTrace, TR_vecEndPos, vecEndPos)
   
    if(iDecalIndex < 0 || flFraction >= 1.0)
        return
   
    if(bIsGunshot)
    {
        iMessage = TE_GUNSHOTDECAL
    }
    else
    {
        iMessage = TE_DECAL
       
        if(iHit != 0)
        {
            if(iDecalIndex > 255)
            {
                iMessage = TE_DECALHIGH
                iDecalIndex -= 256
            }
        }
        else
        {
            iMessage = TE_WORLDDECAL
           
            if(iDecalIndex > 255)
            {
                iMessage = TE_WORLDDECALHIGH
                iDecalIndex -= 256
            }
        }
    }
   
    engfunc(EngFunc_MessageBegin, MSG_PAS, SVC_TEMPENTITY, vecEndPos, 0)
    write_byte(iMessage)
    engfunc(EngFunc_WriteCoord, vecEndPos[0])
    engfunc(EngFunc_WriteCoord, vecEndPos[1])
    engfunc(EngFunc_WriteCoord, vecEndPos[2])
 
    if(bIsGunshot)
    {
        write_short(iHit)
        write_byte(iDecalIndex)
    }
    else
    {
        write_byte(iDecalIndex)
       
        if(iHit)
        {
            write_short(iHit)
        }
    }
   
    message_end()
}
 
//**********************************************
//* Set Animations.                            *
//**********************************************
stock Weapon_SendAnim(iPlayer, iItem, iAnim)
{
    static i, iCount, iSpectator, aSpectators[32]
   
    set_pev(iPlayer, pev_weaponanim, iAnim)
 
    message_begin(MSG_ONE, SVC_WEAPONANIM, .player = iPlayer)
    write_byte(iAnim)
    write_byte(pev(iItem, pev_body))
    message_end()
   
    if(IsObserver(iPlayer))
        return
   
    get_players(aSpectators, iCount, "bch")
 
    for(i = 0; i < iCount; i++)
    {
        iSpectator = aSpectators[i]
       
        if(IsObserver(iSpectator) != OBS_IN_EYE || pev(iSpectator, pev_iuser2) != iPlayer)
            continue
       
        set_pev(iSpectator, pev_weaponanim, iAnim)
 
        message_begin(MSG_ONE, SVC_WEAPONANIM, .player = iSpectator)
        write_byte(iAnim)
        write_byte(pev(iItem, pev_body))
        message_end()
    }
}
 
stock Player_SetAnimation(iPlayer, szAnim[])
{
    #define ACT_RANGE_ATTACK1   28
   
    // Linux extra offsets
    #define extra_offset_animating   4
    #define extra_offset_player 5
   
    // CBaseAnimating
    #define m_flFrameRate      36
    #define m_flGroundSpeed      37
    #define m_flLastEventCheck   38
    #define m_fSequenceFinished   39
    #define m_fSequenceLoops   40
   
    // CBaseMonster
    #define m_Activity      73
    #define m_IdealActivity      74
   
    // CBasePlayer
    #define m_flLastAttackTime   220
   
    new iAnimDesired, Float:flFrameRate, Float:flGroundSpeed, bool:bLoops
     
    if((iAnimDesired = lookup_sequence(iPlayer, szAnim, flFrameRate, bLoops, flGroundSpeed)) == -1)
    {
        iAnimDesired = 0
    }
   
    static Float:flGametime; flGametime = get_gametime()
 
    set_pev(iPlayer, pev_frame, 0.0)
    set_pev(iPlayer, pev_framerate, 1.0)
    set_pev(iPlayer, pev_animtime, flGametime)
    set_pev(iPlayer, pev_sequence, iAnimDesired)
   
    set_pdata_int(iPlayer, m_fSequenceLoops, bLoops, extra_offset_animating)
    set_pdata_int(iPlayer, m_fSequenceFinished, 0, extra_offset_animating)
   
    set_pdata_float(iPlayer, m_flFrameRate, flFrameRate, extra_offset_animating)
    set_pdata_float(iPlayer, m_flGroundSpeed, flGroundSpeed, extra_offset_animating)
    set_pdata_float(iPlayer, m_flLastEventCheck, flGametime , extra_offset_animating)
   
    set_pdata_int(iPlayer, m_Activity, ACT_RANGE_ATTACK1, extra_offset_player)
    set_pdata_int(iPlayer, m_IdealActivity, ACT_RANGE_ATTACK1, extra_offset_player)  
    set_pdata_float(iPlayer, m_flLastAttackTime, flGametime , extra_offset_player)
}
 
//**********************************************
//* Kick back.                                 *
//**********************************************
Weapon_KickBack(iItem, iPlayer, Float:upBase, Float:lateralBase, Float:upMod, Float:lateralMod, Float:upMax, Float:lateralMax, directionChange)
{
    static iDirection
    static iShotsFired
   
    static Float: Punchangle[3]
    pev(iPlayer, pev_punchangle, Punchangle)
   
    if((iShotsFired = get_pdata_int(iItem, 64, 4)) != 1)
    {
        upBase += iShotsFired * upMod
        lateralBase += iShotsFired * lateralMod
    }
   
    upMax *= -1.0
    Punchangle[0] -= upBase
 
    if(upMax >= Punchangle[0])
    {
        Punchangle[0] = upMax
    }
   
    if((iDirection = get_pdata_int(iItem, 60, 4)))
    {
        Punchangle[1] += lateralBase
       
        if(lateralMax < Punchangle[1])
        {
            Punchangle[1] = lateralMax
        }
    }
    else
    {
        lateralMax *= -1.0;
        Punchangle[1] -= lateralBase
       
        if(lateralMax > Punchangle[1])
        {
            Punchangle[1] = lateralMax
        }
    }
   
    if(!random_num(0, directionChange))
    {
        set_pdata_int(iItem, 60, !iDirection, 4)
    }
   
    set_pev(iPlayer, pev_punchangle, Punchangle)
}
 
//**********************************************
//* Some useful stocks.                        *
//**********************************************
stock get_speed_vector(Float:Origin1[3], Float:Origin2[3], Float:Speed, Float:NewVelocity[3])
{
    NewVelocity[0] = Origin2[0] - Origin1[0]
    NewVelocity[1] = Origin2[1] - Origin1[1]
    NewVelocity[2] = Origin2[2] - Origin1[2]
    new Float:num = floatsqroot(Speed*Speed / (NewVelocity[0]*NewVelocity[0] + NewVelocity[1]*NewVelocity[1] + NewVelocity[2]*NewVelocity[2]))
    NewVelocity[0] *= num
    NewVelocity[1] *= num
    NewVelocity[2] *= num
   
    return 1
}
 
stock Get_Position(iPlayer, Float:forw, Float:right, Float:up, Float:vStart[])
{
    new Float:Origin[3], Float:Angles[3], Float:vForward[3], Float:vRight[3], Float:vUp[3]
   
    pev(iPlayer, pev_origin, Origin)
    pev(iPlayer, pev_view_ofs,vUp) //for player
    xs_vec_add(Origin, vUp, Origin)
    pev(iPlayer, pev_v_angle, Angles) // if normal entity ,use pev_angles
   
    angle_vector(Angles, ANGLEVECTOR_FORWARD, vForward) //or use EngFunc_AngleVectors
    angle_vector(Angles, ANGLEVECTOR_RIGHT, vRight)
    angle_vector(Angles, ANGLEVECTOR_UP, vUp)
   
    vStart[0] = Origin[0] + vForward[0] * forw + vRight[0] * right + vUp[0] * up
    vStart[1] = Origin[1] + vForward[1] * forw + vRight[1] * right + vUp[1] * up
    vStart[2] = Origin[2] + vForward[2] * forw + vRight[2] * right + vUp[2] * up
}
 
stock Get_WeaponAttachment(iPlayer, Float:Output[3], Float:fDis = 40.0)
{
    static Float:vfEnd[3], viEnd[3]
    get_user_origin(iPlayer, viEnd, 3)  
    IVecFVec(viEnd, vfEnd)
   
    static Float:fOrigin[3], Float:fAngle[3]
   
    pev(iPlayer, pev_origin, fOrigin)
    pev(iPlayer, pev_view_ofs, fAngle)
   
    xs_vec_add(fOrigin, fAngle, fOrigin)
   
    static Float:fAttack[3]
   
    xs_vec_sub(vfEnd, fOrigin, fAttack)
    xs_vec_sub(vfEnd, fOrigin, fAttack)
   
    static Float:fRate
   
    fRate = fDis / vector_length(fAttack)
    xs_vec_mul_scalar(fAttack, fRate, fAttack)
   
    xs_vec_add(fOrigin, fAttack, Output)
}
Image

User avatar
Raheem
Mod Developer
Mod Developer
Egypt
Posts: 1755
Joined: 2 Years Ago
Location: Egypt
Has thanked: 30 times
Been thanked: 87 times
Age: 21
Contact:

#10

Post by Raheem » 6 Months Ago

They are using also ExecuteHamB() so damage should be blocked. You sure player take damage or just he take only knockback?
You don't know? Learn and you will know.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest