View Single Post
asdian
Member
Join Date: Sep 2016
Location: Indonesia
Old 02-27-2023 , 00:20   Re: Play Sound - spk vs emit_sound
Reply With Quote #10

Quote:
Originally Posted by AnimalMonster View Post
Just put all the multilingual audios into one .wav file and do it like "spk sound(s10e14)". And the directory limitation is that you can only put them into the folder sound/. but i can be kinda hard since you have to put percentage and i don't think that floating points are allowed.

I have something like this in mind:
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <engine>
#include <fakemeta>
#include <xs>

const MaxSoundAtOnce 2;
const 
MaxSoundLen 128;

enum SoundData
{
    
SD_Sound[MaxSoundLen], // String
    
Float:SD_Start// Percentage/100
    
Float:SD_End// Percentage/100
    
Float:SD_Duration// Seconds
    
Float:SD_Volume// Percentage/100
    
Float:SD_Distance
}

enum PlayerData
{
    
Float:PD_Pos,
    
Float:PD_Volume,
    
Float:PD_StartTime,
    
PD_Id
}

new 
g_Sounds[][SoundData] = {
    {
"hello"0.01.02.01.0100.0}
}

new 
g_PlayerSound[MAX_PLAYERS 1][MaxSoundAtOnce][PlayerData],
    
g_iPlaying[MAX_PLAYERS 1],
    
g_iChangeSound[MAX_PLAYERS 1][2]; // {Which, With}

public plugin_init()
{
    
register_clcmd("say hello""cmdStart");
}

public 
cmdStart(id)
{
    if(
g_iPlaying[id] == MaxSoundAtOnce)
    {
        if(
g_iChangeSound[id][0] == MaxSoundAtOnce)
            
g_iChangeSound[id][0] = 0;

        
g_iChangeSound[id][1] = 0;
    }
    else
    {
        
g_PlayerSound[id][g_iPlaying[id]][PD_Volume] = g_Sounds[0][SD_Volume];
        
g_PlayerSound[id][g_iPlaying[id]][PD_StartTime] = get_gametime();
        
g_PlayerSound[id][g_iPlaying[id]][PD_Id] = 0;
        
g_iPlaying[id]++;
    }
}

public 
client_PreThink(pId)
{
    if(!
g_iPlaying[pId])
        return;

    new 
players[MAX_PLAYERS], numidiz;
    
get_players(playersnum"i");

    new 
Float:startPossoundFloat:volume;
    new 
Float:distanceFloat:flVec[3], Float:flVec2[3];

    static 
Float:gametimegametime get_gametime();

    for(
0MaxSoundAtOncei++)
    {
        for(
0numz++)
        {
            
id players[z];

            
sound g_PlayerSound[id][i][PD_Id];

            if(
sound == -1)
                continue;

            if(
g_iChangeSound[i][0] == && g_iChangeSound[i][1] > -1)
            {
                
client_cmd(id"spk ^"%s(v0)^""g_Sounds[sound][SD_Sound]);
                
g_PlayerSound[id][i][PD_Volume] = g_Sounds[g_iChangeSound[id][1]][SD_Volume];
                
g_PlayerSound[id][i][PD_StartTime] = gametime;
                
g_PlayerSound[id][i][PD_Id] = g_iChangeSound[id][1];
                
g_iChangeSound[id][1] = -1;
                continue;
            }

            
startPos g_Sounds[sound][SD_Start];

            
g_PlayerSound[id][i][PD_Pos] = startPos gametime g_PlayerSound[id][i][PD_StartTime];

            if(
g_PlayerSound[id][i][PD_Pos] >= g_Sounds[sound][SD_Duration])
            {
                
g_PlayerSound[id][i][PD_Id] = -1;
                
g_iPlaying[id]--;
                continue;
            }

            
startPos g_PlayerSound[id][i][PD_Pos] / g_Sounds[sound][SD_Duration] * 100.0;

            if(
id == pId)
            {
                
volume g_PlayerSound[id][i][PD_Volume] * g_Sounds[sound][SD_Volume] * 100.0;
            }
            else
            {
                
pev(idpev_originflVec);
                
pev(pIdpev_originflVec2);

                if((
distance xs_vec_distance(flVecflVec2)) > g_Sounds[sound][SD_Distance])
                {
                    
client_cmd(id"spk ^"%s(v0)^""g_Sounds[sound][SD_Sound]);
                    continue;
                }

                
volume = (g_PlayerSound[id][i][PD_Volume] * g_Sounds[sound][SD_Volume]) * distance/g_Sounds[sound][SD_Distance] * 100.0;
            }

            
client_cmd(id"spk ^"%s(v%.2fs%.2fe%.2f)^""g_Sounds[sound][SD_Sound], volumestartPosstartPos+1.0);
        }
    }

Edit: P.S. It's an idea code not exactly a working one i assume.
nice idea. but putting put all the 4 multilingual audios into one .wav file for 10 total files from 30+ characters each is too much time to consume i think
asdian is offline