|
Junior Member
|

05-25-2021
, 06:53
Re: Play custom sounds from distance
|
#3
|
This was suggested by Hellmonja:
PHP Code:
//Checks players around you
find_sphere_class(weapon, "player", DIST_DISTSND * 2.0, players, 32, src_origin);
and
PHP Code:
//Play sound when a distant gunshots were detected from afar, especially from players who were around you
client_cmd(iplayer, "spk %s", snd);
I found this one as well:
Quote:
Originally Posted by hellmonja
Sorry for the late reply guys. Was busy with work. I was also tinkering with the code Crazy. gave me. It seem it has some problems listing all of the players or something related to that. I haven't explored Bugsy's recommendation yet. But I ended up using find_sphere_class like HamletEagle suggested. I didn't use it before because I didn't know what to put in the entity parameter. I didn't know you can actually put -1 there if there's no entity to base the radius around. Haven't done a hard test but so far it's working well. Here's the code:
PHP Code:
RegisterHam(Ham_TraceAttack, "worldspawn", "SotB_Sniper_Warning", false);
...
public SotB_Sniper_Warning(victim, attacker, Float:damage, Float:direction[3], prt, damage_bits)
{
if(g_sniperspotted_time[attacker] + 10.0 > get_gametime())
return HAM_IGNORED
new wpn_id = get_user_weapon(attacker);
new team = get_user_team(attacker);
if(CSW_ALL_SNIPERRIFLES & 1 << wpn_id)
{
new players[MAX_PLAYERS], iplayer, num;
new spotters[MAX_PLAYERS], Float:origin[3];
get_tr2(prt, TR_vecEndPos, origin);
find_sphere_class(-1, "player", 350.0, players, MAX_PLAYERS, origin);
for(new i = 0; i < MAX_PLAYERS; i++)
{
iplayer = players[i];
if(is_user_alive(iplayer) && iplayer != attacker
&& get_user_team(iplayer) != team && !g_is_sneaking[iplayer])
{
spotters[num] = iplayer;
num++;
}
}
if(num <= 0) return HAM_IGNORED
new audio_id = random_num(0, sizeof SND_SNIPER_WARNING - 1);
emit_sound(spotters[0], CHAN_VOICE, SND_SNIPER_WARNING[audio_id], VOL_NORM, ATTN_NORM, 0, PITCH_NORM);
g_sniperspotted_time[attacker] = get_gametime();
}
return HAM_IGNORED
}
Basically what it does is when an enemy player fires a sniper rifle somewhere near you, it takes everyone around where the shot landed then picks a player to yell, "There's a sniper!"
|
Basically what I want to happen is to play sound when someone shoots you (with any gun) from a configurable distance, whether the shot misses or hits you
I'm not sure if this could be applied to Bullet_Whiz (Optimized by Connor)
Quote:
Originally Posted by ConnorMcLeod
I think i remember that conversion had a bug, can't remember, but yeah, excepted the fact i had put cvars pointers in it, there is no advantage in a fakemeta conversion, do not use (*removed*).
It was that time when lot of people were thinking that fakemeta only was better than engine only or than engine + fakemeta.
Should be some possible optimization though.
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <xs>
new g_szBulletSounds[][] =
{
"misc/whizz1.wav",
"misc/whizz2.wav",
"misc/whizz3.wav",
"misc/whizz4.wav",
"misc/whizz5.wav"
}
new g_LastWeapon[33]
new g_LastAmmo[33]
new PLUGIN_NAME[] = "Bullet Whizz"
new PLUGIN_AUTHOR[] = "Cheap_Suit"
new PLUGIN_VERSION[] = "1.4.1"
new amx_bulletwhizz, amx_bulletwhizz_dis
public plugin_init()
{
register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
register_event("CurWeapon", "Event_CurWeapon", "be", "1=1")
amx_bulletwhizz_dis = register_cvar("amx_bulletwhizz_dis", "40")
amx_bulletwhizz = register_cvar("amx_bulletwhizz", "1")
}
public plugin_precache()
{
for(new i = 0; i < sizeof(g_szBulletSounds); ++i)
{
precache_sound(g_szBulletSounds[i])
}
}
public Event_CurWeapon(id)
{
if(!get_pcvar_num(amx_bulletwhizz) || !is_user_alive(id))
{
return
}
new WeaponID = read_data(2)
switch(WeaponID)
{
case CSW_HEGRENADE, CSW_FLASHBANG, CSW_SMOKEGRENADE, CSW_C4, CSW_KNIFE: return
}
new Clip = read_data(3)
if(g_LastWeapon[id] == WeaponID && g_LastAmmo[id] > Clip)
{
new Players[32], iNum, Float:origin[3], Float:targetOrigin[3], temp[3], Float:fAim[3], target, Float:flDistance
pev(id, pev_origin, origin)
get_user_origin(id, temp, 3)
IVecFVec(temp, fAim)
get_players(Players, iNum, "a")
for(--iNum; iNum >= 0; iNum--)
{
target = Players[iNum]
if( id == target )
{
continue
}
pev(target, pev_origin, targetOrigin)
flDistance = get_distance_to_line_f(origin, targetOrigin, fAim)
if( flDistance < 0.0 || flDistance > get_pcvar_float(amx_bulletwhizz_dis) || !fm_is_ent_visible(id, target))
{
continue
}
new RandomSound[64]
formatex(RandomSound, charsmax(RandomSound), "%s", g_szBulletSounds[random(sizeof(g_szBulletSounds))])
client_cmd(target, "spk %s", RandomSound)
}
}
g_LastWeapon[id] = WeaponID
g_LastAmmo[id] = Clip
}
Float:get_distance_to_line_f(Float:pos_start[3], Float:pos_end[3], Float:pos_object[3])
{
new Float:vec_start_end[3], Float:vec_start_object[3], Float:vec_end_object[3], Float:vec_end_start[3]
xs_vec_sub(pos_end, pos_start, vec_start_end) // vector from start to end
xs_vec_sub(pos_object, pos_start, vec_start_object) // vector from end to object
xs_vec_sub(pos_start, pos_end, vec_end_start) // vector from end to start
xs_vec_sub(pos_end, pos_object, vec_end_object) // vector object to end
new Float:len_start_object = vector_length(vec_start_object)
new Float:angle_start = floatacos(xs_vec_dot(vec_start_end, vec_start_object) / (vector_length(vec_start_end) * len_start_object), degrees)
new Float:angle_end = floatacos(xs_vec_dot(vec_end_start, vec_end_object) / (vector_length(vec_end_start) * vector_length(vec_end_object)), degrees)
if(angle_start <= 90.0 && angle_end <= 90.0)
return len_start_object * floatsin(angle_start, degrees)
return -1.0
}
bool:fm_is_ent_visible(index, entity)
{
new Float:origin[3], Float:view_ofs[3], Float:eyespos[3]
pev(index, pev_origin, origin)
pev(index, pev_view_ofs, view_ofs)
xs_vec_add(origin, view_ofs, eyespos)
new Float:entpos[3]
pev(entity, pev_origin, entpos)
engfunc(EngFunc_TraceLine, eyespos, entpos, 0, index)
switch (pev(entity, pev_solid)) {
case SOLID_BBOX..SOLID_BSP: return global_get(glb_trace_ent) == entity
}
new Float:fraction
global_get(glb_trace_fraction, fraction)
if (fraction == 1.0)
return true
return false
}
Edit : You can use this attachment, no big changes excepted little optimizations (Note that engine has been removed but that was not wanted).
|
Any helps are appreciated, thanks in advance
|
|