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

Play sound


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vikvik
Junior Member
Join Date: Apr 2014
Old 04-25-2017 , 17:21   Play sound
Reply With Quote #1

I would like to make a plugin which plays a sound while the user is connecting.

For user1 that is connecting should be played the sound number 1
For user2 that is connecting should be played the sound number 2
For user3 that is connecting should be played the sound number 3
For user4 that is connecting should be played the sound number 4

For user5 that is connecting should be played the sound number 1
For user6 that is connecting should be played the sound number 2
and so on. the counter should stop at 4 and then reset back at 1.



All I know how to do it, is

PHP Code:
public plugin_precache() 
{
  
precache_sound("misc/Cotan/1.wav")
  
precache_sound("misc/Cotan/2.wav")
  
precache_sound("misc/Cotan/3.wav")
  
precache_sound("misc/Cotan/4.wav")

  return 
PLUGIN_CONTINUE

and I know that when you play the sound it should be something like this:

PHP Code:
client_cmd(0,"spk misc/Cotan/1")
client_cmd(0,"spk misc/Cotan/2")
client_cmd(0,"spk misc/Cotan/3")
client_cmd(0,"spk misc/Cotan/4"
But the problem is I don't know all the rest. I appreciate your time for having a look at this.
vikvik is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 04-25-2017 , 19:01   Re: Play sound
Reply With Quote #2

Search for loading music. It's already been made.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
vikvik
Junior Member
Join Date: Apr 2014
Old 04-26-2017 , 21:57   Re: Play sound
Reply With Quote #3

that plugin is only with one soud, not like I want.
vikvik is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 04-27-2017 , 05:02   Re: Play sound
Reply With Quote #4

No, it's not.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 04-27-2017 , 10:56   Re: Play sound
Reply With Quote #5

To make it as dynamic and easy as possible to maintain you need to make it a global array first.
Code:
new const gSounds[][] = {     "misc/Cotan/1.wav",     "misc/Cotan/2.wav",     "misc/Cotan/3.wav",     "misc/Cotan/4.wav" }

Then you need something to keep track of which sound to play, also as global.
Code:
new gCount;

Then you precache it.
Code:
    for ( new i ; i < sizeof gSounds ; i++ )         precache_sound(gSounds[i]);

And finally, to play it
Code:
client_cmd(id, "spk ^"%s^"", gSounds[gCount++ % sizeof gSounds])

You want the ^" surrounding the %s in case there's a space in your sound filepath.
gCount will return 0 in the first run and then increment after the value has been used.
% is modulo which returns the remainder of a division.
sizeof gSounds will return the number of sounds you have in your array, in this case 4.
So this is the result in a more understandable form:
0 % 4 = 0
1 % 4 = 1
2 % 4 = 2
3 % 4 = 3
4 % 4 = 0
5 % 4 = 1
...

Now all you have to do whenever you want to change the sounds is to edit the array at the top. Everything else will adapt to the number of sounds you have chosen.

If you want to test something like this you could just simulate it using a loop and print it out to console to see if the concept works.
Spoiler
__________________
Black Rose is offline
Houssam Benmouna
Senior Member
Join Date: Apr 2016
Old 04-27-2017 , 12:11   Re: Play sound
Reply With Quote #6

Nice Black Rose
Houssam Benmouna is offline
vikvik
Junior Member
Join Date: Apr 2014
Old 04-28-2017 , 08:58   Re: Play sound
Reply With Quote #7

Thank you for helping me with this. What if I want the sounds in a text file in configsdir ?

PHP Code:
#include <amxmodx>
#include <amxmisc>


new const gSounds[][] = {
    
"misc/Cotan/1.wav",
    
"misc/Cotan/2.wav",
    
"misc/Cotan/3.wav",
    
"misc/Cotan/4.wav"
}

new 
gCount;

public 
plugin_precache() 
    {
    for ( new 
sizeof gSounds i++ )
    
precache_sound(gSounds[i]);
    }

public 
client_connect(id)
    {        
    
client_cmd(id"spk ^"%s^""gSounds[gCount++ % sizeof gSounds]);

    } 

Last edited by vikvik; 04-28-2017 at 10:47. Reason: edit
vikvik is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 04-28-2017 , 09:04   Re: Play sound
Reply With Quote #8

Wtf? Where are your functions?
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
vikvik
Junior Member
Join Date: Apr 2014
Old 04-28-2017 , 10:25   Re: Play sound
Reply With Quote #9

edited, sorry

Last edited by vikvik; 04-28-2017 at 10:25.
vikvik is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 04-28-2017 , 13:34   Re: Play sound
Reply With Quote #10

Take a look of some of the plugins in my signature. They all use text files for getting stuff, so you can get an idea on how to do it. Or this - https://forums.alliedmods.net/showthread.php?t=294300
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
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 16:09.


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