Raised This Month: $ Target: $400
 0% 

loop emit_sound optimize


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
adbajota
New Member
Join Date: Jun 2012
Old 06-29-2012 , 00:39   loop emit_sound optimize
Reply With Quote #1

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
adbajota is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 06-29-2012 , 00:47   Re: loop emit_sound optimize
Reply With Quote #2

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
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 06-29-2012 at 00:48.
Liverwiz is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-29-2012 , 01:01   Re: loop emit_sound optimize
Reply With Quote #3

"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.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Reply


Thread Tools
Display Modes

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 15:21.


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