AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   Play custom sounds from distance (https://forums.alliedmods.net/showthread.php?t=332600)

Agent3554 05-21-2021 19:33

Play custom sounds from distance
 
2 Attachment(s)
Do anyone know how to make one similar to Bullet Whizz, except there are some changes like this:
  • Each custom (.wav) audio plays to corresponding events such as gunshots or explosions (C4 & grenade, had separated audios for them)
  • You can hear it in any direction, unlike Bullet Whizz, where the audio only plays when both attacker and you are facing towards each other
  • The exceptions are silenced weapons such as (TMP, USP and M4A1)

I unfortunately have no experience with scripting to make one, or modify the other existing script

Agent3554 05-21-2021 21:05

Re: Play custom sounds from distance
 
Here is my technical explanation when it comes with the code, I don't know how to code in C#, only in lua, sorry

Code:

#include <amxmodx>
#include <fakemeta>
#include <engine>
#include <xs>

#define MAX_SOUNDS        5

new plugin_name[]        = "Distant sounds"

new g_Sounds[MAX_SOUNDS][] =
{
        "misc/gun_echo_auto.wav",                        // 0
        "misc/gun_echo_semiauto.wav",                // 1
        "misc/explosion_c4.wav",                        // 2
        "misc/explosion_grenade.wav"                // 3
}

//Listener == Player <-- You

//Configuration:
//        Detect_Distance = "1000" <-- Let's just say, in meters, as an example

//Event_Explosive()
//{
//        If (C4.Explode == true), then
//                If (Listener == Exist) and (Listener.DistanceBetweenEvent == Detect_Distance), then
//                        ClientSide.Audio.Play(MAX_SOUNDS[2])
//                end
//        end
//}

//Event_Gun()
//{
//        If Listener.Gun.Fired == true, then
//                If (Listener == Exist) and (Listener.DistanceBetweenEvent == Detect_Distance), then
//                        If (Listener.Gun.Type("Semi-Auto")) == true, then
//                                ClientSide.Audio.Play(MAX_SOUNDS[1])
//                        else
//                                ClientSide.Audio.Play(MAX_SOUNDS[0])
//                        end
//                end
//        end
//}

//Server.WaitForEvent(Event_Explosive, Event_Gun)


Agent3554 05-25-2021 06:53

Re: Play custom sounds from distance
 
This was suggested by Hellmonja:
PHP Code:

//Checks players around you
find_sphere_class(weapon"player"DIST_DISTSND 2.0players32src_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 (Post 2666518)
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(victimattackerFloat:damageFloat:direction[3], prtdamage_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 << wpn_id)
    {
        new 
players[MAX_PLAYERS], iplayernum;
        new 
spotters[MAX_PLAYERS], Float:origin[3];
        
        
get_tr2(prtTR_vecEndPosorigin);
        
find_sphere_class(-1"player"350.0playersMAX_PLAYERSorigin);
        
        for(new 
0MAX_PLAYERSi++)
        {
            
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(0sizeof SND_SNIPER_WARNING 1);
        
emit_sound(spotters[0], CHAN_VOICESND_SNIPER_WARNING[audio_id], VOL_NORMATTN_NORM0PITCH_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 (Post 1931111)
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_bulletwhizzamx_bulletwhizz_dis

public plugin_init() 
{
    
register_plugin(PLUGIN_NAMEPLUGIN_VERSIONPLUGIN_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 
0sizeof(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_HEGRENADECSW_FLASHBANGCSW_SMOKEGRENADECSW_C4CSW_KNIFE: return
    }

    new 
Clip read_data(3)
    if(
g_LastWeapon[id] == WeaponID && g_LastAmmo[id] > Clip)
    {
        new 
Players[32], iNumFloat:origin[3], Float:targetOrigin[3], temp[3], Float:fAim[3], targetFloat:flDistance

        pev
(idpev_originorigin)

        
get_user_origin(idtemp3)
        
IVecFVec(tempfAim)

        
get_players(PlayersiNum"a")

        for(--
iNumiNum >= 0iNum--)
        {
            
target Players[iNum]
            if( 
id == target )
            {
                continue
            }
            
pev(targetpev_origintargetOrigin)

            
flDistance get_distance_to_line_f(origintargetOriginfAim)
            if( 
flDistance 0.0 || flDistance get_pcvar_float(amx_bulletwhizz_dis) || !fm_is_ent_visible(idtarget))
            {
                continue
            }

            new 
RandomSound[64]
            
formatex(RandomSoundcharsmax(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_endpos_startvec_start_end// vector from start to end 
    
xs_vec_sub(pos_objectpos_startvec_start_object// vector from end to object 
    
xs_vec_sub(pos_startpos_endvec_end_start// vector from end to start 
    
xs_vec_sub(pos_endpos_objectvec_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_endvec_start_object) / (vector_length(vec_start_end) * len_start_object), degrees)  
    new 
Float:angle_end floatacos(xs_vec_dot(vec_end_startvec_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_startdegrees)
    return -
1.0
}

bool:fm_is_ent_visible(indexentity
{
    new 
Float:origin[3], Float:view_ofs[3], Float:eyespos[3]
    
pev(indexpev_originorigin)
    
pev(indexpev_view_ofsview_ofs)
    
xs_vec_add(originview_ofseyespos)

    new 
Float:entpos[3]
    
pev(entitypev_originentpos)
    
engfunc(EngFunc_TraceLineeyesposentpos0index)

    switch (
pev(entitypev_solid)) {
        case 
SOLID_BBOX..SOLID_BSP: return global_get(glb_trace_ent) == entity
    
}

    new 
Float:fraction
    global_get
(glb_trace_fractionfraction)
    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


All times are GMT -4. The time now is 19:58.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.