Thread: Detect teammate
View Single Post
Tote
Senior Member
Join Date: Jul 2023
Old 04-23-2024 , 15:14   Re: Detect teammate
Reply With Quote #9

Code:
#include <amxmodx>
#include <fakemeta>
#include <engine>
#include <hamsandwich>
#include <fun>
#include <cstrike>

new MsgScreenShake 
new exploSpr
new g_effected[33]
new bool: g_roundend

#define grenadeeffect "items/blastgrenade_hit.wav"

#define message_begin_fl(%1,%2,%3,%4) engfunc(EngFunc_MessageBegin, %1, %2, %3, %4)
#define write_coord_fl(%1) engfunc(EngFunc_WriteCoord, %1)

//#define RADIUS 189.0
const Float: RADIUS = 189.0  
#define JUMP_EXP 199.0
#define WEAPON_DEFAULT "weapon_flashbang"

new const SPRITE_EXPLO[] = "sprites/shockwave.spr";

new const FLASH_SOUND[] = "items/blastbomb_explode.wav"

new const BOMB_MODEL[][] = 
{
"models/v_cs_fun_blast.mdl",
"models/p_cs_fun_blast.mdl",
"models/w_cs_fun_blast.mdl"
}

new g_spr_rustler, bool:using_rustler[33], msgScreenFade, amx_kill_fade_amount

public plugin_precache() 
{
static i

for(i = 0; i < sizeof BOMB_MODEL; i++)
	precache_model(BOMB_MODEL[i])
	
	precache_sound(FLASH_SOUND)
	
	exploSpr = precache_model(SPRITE_EXPLO)
	precache_sound(grenadeeffect)
	
	g_spr_rustler = precache_model("sprites/effects/rotating_star.spr")
}

public plugin_init()
{
	register_plugin("Jump Grenade", "1.0", "NoPanicXxX")
	
	register_forward(FM_EmitSound,"fw_emitsound")
	
	MsgScreenShake = get_user_msgid("ScreenShake")
	
	RegisterHam(Ham_Item_Deploy, WEAPON_DEFAULT, "DeployPost", 1)
	register_forward(FM_SetModel, "fw_SetModel")
	RegisterHam(Ham_Spawn, "player", "fw_PlayerSpawn_Post", 1)
	
	register_event ("HLTV", "event_new_round", "a", "1=0", "2=0")
	register_logevent("round_end", 2, "1=Round_End")
	
	RegisterHam(Ham_Killed, "player", "OnKilled", 1)
	
	register_message(get_user_msgid("ScreenFade"), "Message_ScreenFade")
	
	// Screenfade 
	msgScreenFade = get_user_msgid("ScreenFade")
	amx_kill_fade_amount = register_cvar("amx_kill_fade_amount", "240")
}

public Message_ScreenFade(not_used, not_used2, not_used3)
{
	if( get_msg_arg_int(4) != 255 || get_msg_arg_int(5) != 255 || get_msg_arg_int(6) != 255 )
		return PLUGIN_CONTINUE
	
	static iAlpha
	iAlpha = get_msg_arg_int(7)
	if(iAlpha != 200 && iAlpha != 255)
		return PLUGIN_CONTINUE
	
	return PLUGIN_HANDLED
} 

public OnKilled(id, atk, gibs)
{
	if(using_rustler[id] && is_user_connected(id))
	{
		using_rustler[id] = false
	}
}

public client_putinserver(id)
{
	using_rustler[id] = false
}

public client_disconnected(id)
{
	using_rustler[id] = false
}

public event_new_round()
{   
	g_roundend = false
	
	static id;
	for(id = 1 ; id <= get_maxplayers() ; id++)
	{
		using_rustler[id] = false
	}
}

public round_end()
{
	g_roundend = true
	
	static id;
	for(id = 1 ; id <= get_maxplayers() ; id++)
	{
		using_rustler[id] = false
	}
}

public fw_PlayerSpawn_Post(id)
{    
	if(g_effected[id] && is_user_connected(id)) 
	{
		g_effected[id] = 0
	}
}

public Shake(id)
{
	if(!is_user_alive(id))
		return
	
	if(g_roundend)
		return
	
	g_effected[id] = 0
	
	using_rustler[id] = false
	
	new Dura = UTIL_FixedUnsigned16(4.0, 1 << 12)
	new Freq = UTIL_FixedUnsigned16(0.7 , 1 << 8)
	new Ampl = UTIL_FixedUnsigned16(20.0, 1 << 12)
	
	message_begin(MSG_ONE_UNRELIABLE , MsgScreenShake , {0,0,0} ,id)
	write_short( Ampl ) // --| Shake amount.
	write_short( Dura ) // --| Shake lasts this long.
	write_short( Freq ) // --| Shake noise frequency.
	message_end ()       
}

rustler_sprite(id)
{
if(!is_user_alive(id)) return;

static origin[3]
get_user_origin(id, origin)

message_begin(MSG_PVS, SVC_TEMPENTITY, origin)
write_byte(TE_SPRITE)
write_coord(origin[0])
write_coord(origin[1])
write_coord(origin[2]+52)
write_short(g_spr_rustler)
write_byte(2)
write_byte(240)
message_end()
}

public client_PostThink(id)
{
if(!is_user_alive(id))
	return
	
	static Float:Rustler_Time, Float:Rustler_hud_delay[33]
	
	Rustler_Time = get_gametime()
	
	if(Rustler_Time - 0.5 > Rustler_hud_delay[id])
	{
		if(using_rustler[id]) rustler_sprite(id)
		
		Rustler_hud_delay[id] = Rustler_Time
	}
}

public fw_emitsound(entity,channel,const sample[],Float:volume,Float:attenuation,fFlags,pitch)
{
	// not a flashbang exploding
	if(!equali(sample,"weapons/flashbang-1.wav") && !equali(sample,"weapons/flashbang-2.wav"))
		return FMRES_IGNORED
	
	create_blast(entity)      
	JumpBombExplode(entity)
	emit_sound(entity, CHAN_STATIC, FLASH_SOUND, VOL_NORM, ATTN_NORM, 0, PITCH_NORM )
	
	
	return FMRES_IGNORED
}

public JumpBombExplode(Entity)
{       
	
	if(Entity < 0)
		return PLUGIN_HANDLED;
	
	if(g_roundend)
		return PLUGIN_HANDLED;
	
	static Float:Origin[3]
	pev(Entity, pev_origin, Origin)
	
	//emit_sound(Entity, CHAN_WEAPON, g_SoundBombExplode, VOL_NORM, ATTN_NORM, 0, PITCH_NORM)
	static iOwner; iOwner = pev(Entity, pev_owner)
	static iOwnerTeam; iOwnerTeam = get_user_team(iOwner)
	
	for(new victim = 1; victim <= get_maxplayers(); victim++)
	{
		if(!is_user_alive(victim) || g_effected[victim])
			continue;
			
		static victimteam; victimteam = get_user_team(victim)
		
		if(iOwnerTeam == victimteam) {
			return FMRES_SUPERCEDE;
		}
		
		
		new Float:VictimOrigin[3]
		pev(victim, pev_origin, VictimOrigin)
		
		new Float:Distance = get_distance_f(Origin, VictimOrigin)   
		
		if(Distance <= RADIUS)
		{
			//static Float:NewSpeed
			
			//NewSpeed = JUMP_EXP * (1.0 - (Distance / RADIUS))
			
			//NewSpeed = JUMP_EXP * 5
			
			//static Float:Velocity[3]
			//get_speed_vector(Origin, VictimOrigin, NewSpeed, Velocity)
			
			//set_pev(victim, pev_velocity, Velocity)
			
			set_pev(victim, pev_punchangle, Float:{125.0, 125.0, 125.0})
			set_task(3.0, "Shake", victim)
			g_effected[victim] = 1
			client_cmd(victim, "spk %s", grenadeeffect)
			using_rustler[victim] = true
			fadegreen(victim, get_pcvar_num(amx_kill_fade_amount))
		}
	}
	return FMRES_IGNORED
} 

UTIL_FixedUnsigned16 ( const Float:Value, const Scale ) {
	return clamp( floatround( Value * Scale ), 0, 0xFFFF );
}

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
}

public DeployPost(entity)
{
	static id
	id = get_pdata_cbase(entity, 41, 4)
	
	if(!is_user_alive(id))
		return PLUGIN_CONTINUE
	
	set_pev(id, pev_viewmodel2, BOMB_MODEL[0])
	set_pev(id, pev_weaponmodel2, BOMB_MODEL[1])
	//client_print(id, print_center, "Blast Grenade")
	
	return PLUGIN_CONTINUE
}

public fw_SetModel(Entity, const Model[])
{
	if(Entity < 0)
		return FMRES_IGNORED
	
	if(pev(Entity, pev_dmgtime) == 0.0)
		return FMRES_IGNORED
	
	new iOwner = pev(Entity, pev_owner)
	
	if(!is_user_connected(iOwner)) return FMRES_IGNORED
	
	/*static model[32];
	pev(ent, pev_model, model, 31)*/
	
	if(equal(Model, "models/w_flashbang.mdl"))
	{    
		
		set_pev(Entity, pev_body, 23)        
		
		engfunc(EngFunc_SetModel, Entity, BOMB_MODEL[2])               
		
		return FMRES_SUPERCEDE    
	}
	return FMRES_IGNORED
}

// make the explosion effects
create_blast(entity)
{ 
new Float:origin[3]
pev(entity,pev_origin,origin)

// smallest ring
message_begin_fl(MSG_PVS,SVC_TEMPENTITY,origin,0);
write_byte(TE_BEAMCYLINDER);
write_coord_fl(origin[0]); // x
write_coord_fl(origin[1]); // y
write_coord_fl(origin[2]); // z
write_coord_fl(origin[0]); // x axis
write_coord_fl(origin[1]); // y axis
write_coord_fl(origin[2] + 385.0); // z axis
write_short(exploSpr); // sprite
write_byte(0); // start frame
write_byte(0); // framerate
write_byte(4); // life
write_byte(60); // width
write_byte(0); // noise
write_byte(31); // red
write_byte(255); // green
write_byte(127); // blue
write_byte(100); // brightness
write_byte(0); // speed
message_end();

// medium ring
message_begin_fl(MSG_PVS,SVC_TEMPENTITY,origin,0);
write_byte(TE_BEAMCYLINDER);
write_coord_fl(origin[0]); // x
write_coord_fl(origin[1]); // y
write_coord_fl(origin[2]); // z
write_coord_fl(origin[0]); // x axis
write_coord_fl(origin[1]); // y axis
write_coord_fl(origin[2] + 470.0); // z axis
write_short(exploSpr); // sprite
write_byte(0); // start frame
write_byte(0); // framerate
write_byte(4); // life
write_byte(60); // width
write_byte(0); // noise
write_byte(31); // red
write_byte(255); // green
write_byte(127); // blue
write_byte(100); // brightness
write_byte(0); // speed
message_end();

// largest ring
message_begin_fl(MSG_PVS,SVC_TEMPENTITY,origin,0);
write_byte(TE_BEAMCYLINDER);
write_coord_fl(origin[0]); // x
write_coord_fl(origin[1]); // y
write_coord_fl(origin[2]); // z
write_coord_fl(origin[0]); // x axis
write_coord_fl(origin[1]); // y axis
write_coord_fl(origin[2] + 555.0); // z axis
write_short(exploSpr); // sprite
write_byte(0); // start frame
write_byte(0); // framerate
write_byte(4); // life
write_byte(60); // width
write_byte(0); // noise
write_byte(31); // red
write_byte(255); // green
write_byte(127); // blue
write_byte(100); // brightness
write_byte(0); // speed
message_end();

/*// light effect
message_begin_fl(MSG_PAS,SVC_TEMPENTITY,origin,0);
write_byte(TE_DLIGHT);
write_coord_fl(origin[0]); // x
write_coord_fl(origin[1]); // y
write_coord_fl(origin[2]); // z
write_byte(50); // radius
write_byte(31); // red
write_byte(255); // green
write_byte(127); // blue
write_byte(8); // life
write_byte(60); // decay rate
message_end();*/      
}

stock fadegreen(id, amount)
{    
//FADE OUT FROM GREEN
if (amount > 255)
	amount = 255
	
	message_begin(MSG_ONE_UNRELIABLE, msgScreenFade, {0,0,0}, id)
	write_short(amount * 100)    //Durration
	write_short(0)        //Hold
	write_short(0)        //Type
	write_byte(0)    //R
	write_byte(150)    //G
	write_byte(0)    //B
	write_byte(amount)    //B
	message_end()
}
Tote is offline