Raised This Month: $51 Target: $400
 12% 

Emit Sound with Timer


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Vit_amin
Senior Member
Join Date: Dec 2015
Location: Russian Federation
Old 01-16-2016 , 11:28   Emit Sound with Timer
Reply With Quote #1

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
    
}

Vit_amin is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-16-2016 , 11:47   Re: Emit Sound with Timer
Reply With Quote #2

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)
        }
    }

__________________

Last edited by Bugsy; 01-16-2016 at 11:50.
Bugsy is offline
Vit_amin
Senior Member
Join Date: Dec 2015
Location: Russian Federation
Old 01-16-2016 , 11:56   Re: Emit Sound with Timer
Reply With Quote #3

This doen't work
Vit_amin is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-16-2016 , 11:57   Re: Emit Sound with Timer
Reply With Quote #4

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().
__________________

Last edited by Bugsy; 01-16-2016 at 12:03.
Bugsy is offline
Vit_amin
Senior Member
Join Date: Dec 2015
Location: Russian Federation
Old 01-16-2016 , 11:58   Re: Emit Sound with Timer
Reply With Quote #5

More precisely, it works, but sometimes the sound is not played to the end (disappear). Maybe the fact CHAN_ *?
Vit_amin is offline
Vit_amin
Senior Member
Join Date: Dec 2015
Location: Russian Federation
Old 01-16-2016 , 22:36   Re: Emit Sound with Timer
Reply With Quote #6

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 is offline
Vit_amin
Senior Member
Join Date: Dec 2015
Location: Russian Federation
Old 01-17-2016 , 14:10   Re: Emit Sound with Timer
Reply With Quote #7

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
Vit_amin is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-17-2016 , 14:41   Re: Emit Sound with Timer
Reply With Quote #8

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.
__________________
Bugsy is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:39.


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