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

Solved How to play a sound just one time when a player spawns?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
MihaiGamerXD
Member
Join Date: Aug 2018
Old 08-21-2018 , 15:15   How to play a sound just one time when a player spawns?
Reply With Quote #1

Hello everybody, I wanted to know, How to play a sound just one time when a player spawns!
So I tried this code:

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

new const bird[] = "bird/codcodak!!!.wav"

new spawn_music 1

public plugin_precache() {
    
precache_sound(bird)
}

public 
plugin_init() {
    
RegisterHam(Ham_Spawn,"player","onSpawn",1)
}

public 
onSpawn(id) {
    if (
is_user_alive(id)) {
        if (
spawn_music == 1) {
            
client_cmd(id,"spk %s",bird)
            
spawn_music 0
        
}
    }

And the sound is still playing, but when I respawned back, the sound won't play, good! But the problem is: When I'm spawning in the first try, the other player won't hear the sound!
So I tried another code:

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

new const bird[] = "bird/codcodak!!!.wav"

static spawn_music //To be a variable for each players

public plugin_precache() {
    
precache_sound(bird)
}

public 
plugin_init() {
    
RegisterHam(Ham_Spawn,"player","onSpawn",1)
}

public 
onSpawn(id) {
    if (
is_user_alive(id)) {
        if (
spawn_music == 1) {
            
client_cmd(id,"spk %s",bird)
            
spawn_music 0
        
}
    }

But still the same problem!
Can anyone help me? Please?
MihaiGamerXD is offline
Ghosted
Veteran Member
Join Date: Apr 2015
Location: Georgia
Old 08-21-2018 , 16:35   Re: How to play a sound just one time when a player spawns?
Reply With Quote #2

Code:
static spawn_music = 1 //To be a variable for each players
thats not for each player

=>

Code:
static spawn_music[33] = { 1, ... } //To be a variable for each players
__________________

[MOD] CS Weapon Mod V1.7.1
[MM] MetaMod-C V1.0
[MOD] CS NPC Mod (5%)


Probably Left AM

Last edited by Ghosted; 08-21-2018 at 16:36.
Ghosted is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 08-21-2018 , 21:05   Re: How to play a sound just one time when a player spawns?
Reply With Quote #3

If I understood correctly, it would be something like this ..

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

new const bird[] = "bird/codcodak!!!.wav"

static spawn_music[33]

public 
plugin_precache() {
    
precache_sound(bird)
}

public 
plugin_init() {
    
RegisterHam(Ham_Spawn,"player","onSpawn",1)
}

public 
onSpawn(id) {
    if (
is_user_alive(id)) {
        if (
spawn_music[id]) {
            
emit_sound(idCHAN_AUTObirdVOL_NORMATTN_NORM0PITCH_NORM)
            
spawn_music[id] = false
        
}
    }


public 
client_putinserver(id)
{
    
spawn_music[id] = true


Last edited by iceeedr; 08-21-2018 at 21:07.
iceeedr is offline
Send a message via Skype™ to iceeedr
MihaiGamerXD
Member
Join Date: Aug 2018
Old 08-22-2018 , 11:55   Re: How to play a sound just one time when a player spawns?
Reply With Quote #4

Thank you! It worked! But the problem is:
When I'm going to new round, I can't still hear the sound!

I just tried this code:

PHP Code:
...

public 
plugin_init() {
    ...
    
register_event("HLTV""event_new_round""a""1=0""2=0")
}

public 
event_new_round() {
    
client_cmd("spk %s",bird)
}

... 
I type the "..." code because there's too many codes to type, and the problem is on the event_new_round! The sound is still not playing!
MihaiGamerXD is offline
MihaiGamerXD
Member
Join Date: Aug 2018
Old 08-22-2018 , 12:03   Re: How to play a sound just one time when a player spawns?
Reply With Quote #5

Ops! I mean:

PHP Code:
public event_new_round() {
    
spawn_music[id] = true

MihaiGamerXD is offline
MihaiGamerXD
Member
Join Date: Aug 2018
Old 08-22-2018 , 12:04   Re: How to play a sound just one time when a player spawns?
Reply With Quote #6

Sorry, I was wrong, but still not playing the sound!
MihaiGamerXD is offline
MihaiGamerXD
Member
Join Date: Aug 2018
Old 08-22-2018 , 13:09   Re: How to play a sound just one time when a player spawns?
Reply With Quote #7

Now I'm done! I tried this code, and it worked perfectly!

PHP Code:
#include <cstrike>
#include <amxmodx>
#include <amxmisc>
#include <hamsandwich>
#include <fun>

new const bird[ ] = "bird/codcodak!!!.wav"

static spawn_music[33]
new 
spawn_start 0

public plugin_precache() {
    
precache_sound(bird)
}

public 
plugin_init() {
    
register_plugin("Test Spawn Music","1.0","MihaiGamerXD")
    
RegisterHam(Ham_Spawn,"player","onSpawn")
    
register_logevent("Round_Draw",4,"1=Round_Draw")
    
register_logevent("Game_Commencing",3,"1=Game_Commencing")
    
register_event("HLTV""event_new_round""a""1=0""2=0")
}

public 
Round_Draw() {
    
spawn_start 0
}

public 
Game_Commencing() {
    
spawn_start 0
}

public 
event_new_round() {
    
spawn_start 1
}

public 
onSpawn(id) {
    if (
spawn_start == 1) {
        
spawn_music[id] = true
    
}
    if (
spawn_music[id]) {
        
client_cmd(id,"spk %s",bird)
    }

Thank you very much!
MihaiGamerXD is offline
MihaiGamerXD
Member
Join Date: Aug 2018
Old 08-22-2018 , 13:13   Re: How to play a sound just one time when a player spawns?
Reply With Quote #8

Ops! Forgot to put "spawn_start = 0" to "public onSpawn()"!

PHP Code:
public onSpawn(id) {
    if (
spawn_start == 1) {
        
spawn_music[id] = true
        spawn_start 
0
    
}

MihaiGamerXD is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 08-22-2018 , 13:24   Re: How to play a sound just one time when a player spawns?
Reply With Quote #9

That would be enough.

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

new const bird[] = "bird/codcodak!!!.wav"

static spawn_music[33]

public 
plugin_precache() {
    
precache_sound(bird)
}

public 
plugin_init() {
    
RegisterHam(Ham_Spawn,"player","onSpawn",1)
    
register_event("HLTV""event_new_round""a""1=0""2=0"
}

public 
onSpawn(id) {
    if (
is_user_alive(id)) {
        if (
spawn_music[id]) {
            
emit_sound(idCHAN_AUTObirdVOL_NORMATTN_NORM0PITCH_NORM)
            
spawn_music[id] = false
        
}
    }


public 
client_putinserver(id)
{
    
spawn_music[id] = true
}

public 
event_new_round() 
{
    new 
iPlayers[32], iNumid
    get_players
(iPlayersiNum)
    for(new 
0iiNumi++)
    {
        
id iPlayers[i]

        
spawn_music[id] = true
    
}

iceeedr is offline
Send a message via Skype™ to iceeedr
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 00:16.


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