AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Emit Sound with Timer (https://forums.alliedmods.net/showthread.php?t=277774)

Vit_amin 01-16-2016 11:28

Emit Sound with Timer
 
Hello where is my mistake ?
PHP Code:

public Event_PlayerDamage(client)
{
    if (
cs_get_user_team(client) == CS_TEAM_T)
    {
        static 
b_StopSound[32] = false
        
if (!b_StopSound[client])
        {
            
b_StopSound[client] = true
            set_task
(0.5"Timer_SoundStopSpam", (clientb_StopSound[client]))
        }
    }
}

public 
Timer_SoundStopSpam(clientSoundOff[])
{
    if (
is_user_connected(client) && is_user_alive(client))
    {
        new 
sound_path[32]
        new 
sound_numb random_num(12)
        
formatex(sound_pathcharsmax(sound_path), "zombie/zo_pain%d.wav"sound_numb)
        
emit_sound(clientCHAN_VOICEsound_pathVOL_NORMATTN_NORM0PITCH_NORM)
        
SoundOff[client] = false
    
}



Bugsy 01-16-2016 11:47

Re: Emit Sound with Timer
 
Try this. SecondsBetweenSounds is the delay in seconds before the sound can be played again.
PHP Code:

public Event_PlayerDamageclient )
{
    static 
iLastSound33 ];
    new 
sound_path[32] , iSystime;
    const 
SecondsBetweenSounds 2;
    
    if ( 
cs_get_user_teamclient ) == CS_TEAM_T )
    {
        
iSystime get_systime();
        if ( !
iLastSoundclient ] || ( ( iSystime iLastSoundclient ] ) > SecondsBetweenSounds ) )
        {
            
iLastSoundclient ] = iSystime;
            
formatexsound_path charsmax(sound_path) , "zombie/zo_pain%d.wav" random_num(12) )
            
emit_sound(clientCHAN_VOICEsound_pathVOL_NORMATTN_NORM0PITCH_NORM)
        }
    }



Vit_amin 01-16-2016 11:56

Re: Emit Sound with Timer
 
This doen't work

Bugsy 01-16-2016 11:57

Re: Emit Sound with Timer
 
Explain better what you are trying to do, I was making assumptions with this.

A topic titled "Emit sound with timer" and "Hello where is my mistake ?" doesnt give much guidance.

One thing you can try with your code is declare b_StopSound[32] as global, and you need to size it 33 not 32. So at the top of all of your code, under the includes, put new bool:b_StopSound[33]. It is false by default so you do not need = false. Remove static b_StopSound[32] from the damage forward.

Add client_disconnect( id ) and use remove_task( id ) and b_StopSound[ id ] = false there.

SoundOff[client] = false has no effect to the variable you declared in the damage event. This only works when the variable is passed by reference, which it is not when passed with set_task().

Vit_amin 01-16-2016 11:58

Re: Emit Sound with Timer
 
More precisely, it works, but sometimes the sound is not played to the end (disappear). Maybe the fact CHAN_ *?

Vit_amin 01-16-2016 22:36

Re: Emit Sound with Timer
 
Your method it's work, but why sound somites dissapear
P.S. When in Half-Life fire at Zombie him Pain sound play norm

Vit_amin 01-17-2016 14:10

Re: Emit Sound with Timer
 
I have been using set_task with ID as a client for a different purpose, which then set the ID of the set_task?
May be ?
PHP Code:

#define TASKID_STOP_SPAM 128
set_task(2.0"Timer_SoundStopSpam"client TASKID_STOP_SPAM


Bugsy 01-17-2016 14:41

Re: Emit Sound with Timer
 
Its good if you are using set_task() for multiple things. If you use 'id' only, then you cannot tell which task is for what purpose. Just remember to subtract TASKID_STOP_SPAM from the Time_SoundStopSpam function.


All times are GMT -4. The time now is 09:23.

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