AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   loop emit_sound optimize (https://forums.alliedmods.net/showthread.php?t=188657)

adbajota 06-29-2012 00:39

loop emit_sound optimize
 
Hello Am.

I was looking for a repeat of the same sound a number of times (5 seconds):

PHP Code:

emit_sound(0CHAN_VOICE"player/heartbeat1.wav"0.2ATTN_NORM0PITCH_NORM)
emit_sound(0CHAN_VOICE"player/heartbeat1.wav"0.2ATTN_NORM0PITCH_NORM)
emit_sound(0CHAN_VOICE"player/heartbeat1.wav"0.2ATTN_NORM0PITCH_NORM)
emit_sound(0CHAN_VOICE"player/heartbeat1.wav"0.2ATTN_NORM0PITCH_NORM)
emit_sound(0CHAN_VOICE"player/heartbeat1.wav"0.2ATTN_NORM0PITCH_NORM

I made the following code to optimize:

PHP Code:

remove_task(9393939932);
        
timer 5
        
set_task
(1.0"countdown"9393939932);
// [...]

public countdown()
{
    if (
timer >= 0)
    { 
        
emit_sound(0CHAN_VOICE"player/heartbeat1.wav"0.2ATTN_NORM0PITCH_NORM)
    }
    
    --
timer;

    if (
timer 0)
    {
        
set_task(1.0"countdown"9393939932);
    }
    else
    {
        
remove_task(9393939932);
    }


what I want to know is whether it can improve the code otherwise

Thanks in advance

Liverwiz 06-29-2012 00:47

Re: loop emit_sound optimize
 
Code:

set_task(1.0, "countdown", 0, _, _, "a", 5)
Code:
public countdown()         emit_sound(0, CHAN_VOICE, "player/heartbeat1.wav", 0.2, ATTN_NORM, 0, PITCH_NORM)

That will repeat the emit_sound 5 times, once a second. Obviously, removing the need for the timer var, all the checks for iterations, and the decrement.

http://www.amxmodx.org/funcwiki.php?go=func&id=253

ConnorMcLeod 06-29-2012 01:01

Re: loop emit_sound optimize
 
"player/heartbeat1" is already looping by itself, all you have to do is to send ONCE emit_soud.

For custom sounds, edit them with some sound software and add markers at begining and at end of the sounds so sounds gonna auto loop.


All times are GMT -4. The time now is 15:21.

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