AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [BUG] - Welcome Sound (https://forums.alliedmods.net/showthread.php?t=335483)

Yusochan 12-08-2021 16:10

[BUG] - Welcome Sound
 
Hello !

When i join the server the sound doesn't play..

Code:

#include <amxmodx>

new const szPLUGIN[] = "Welcome kho", szVERSION[] = "2.0", szAUTHOR[] = "YusoChan-";

new const szWelcome[] = "sound/misc/welcome.wav";

public plugin_init() {
       
        register_plugin(szPLUGIN, szVERSION, szAUTHOR);
}

public client_connect(id) {
        set_task(3.0, "Welcome", id);
}

public plugin_precache()
{
        precache_sound(szWelcome);
}

public Welcome(id)
{
        if(is_user_connected(id)) {
                client_cmd(id, "spk welcome.wav", szWelcome);
        }
}


SHIFT0 12-08-2021 16:45

Re: [BUG] - Welcome Sound
 
Quote:

Originally Posted by Yusochan (Post 2765353)
Hello !

When i join the server the sound doesn't play..

Code:

#include <amxmodx>

new const szPLUGIN[] = "Welcome kho", szVERSION[] = "2.0", szAUTHOR[] = "YusoChan-";

new const szWelcome[] = "sound/misc/welcome.wav";

public plugin_init() {
       
        register_plugin(szPLUGIN, szVERSION, szAUTHOR);
}

public client_connect(id) {
        set_task(3.0, "Welcome", id);
}

public plugin_precache()
{
        precache_sound(szWelcome);
}

public Welcome(id)
{
        if(is_user_connected(id)) {
                client_cmd(id, "spk welcome.wav", szWelcome);
        }
}



PHP Code:

#include <amxmodx>

// change this number to the amount of sounds u have
#define Maxsounds 2

// add here your sounds, sounds must be somewhere in <ModDir>/sound
// format must be like: {"misc/sound1","ambience/sound2"}
new soundlist[Maxsounds][] = {"misc/welcome""misc/prepare"}

new 
plugin_author[] = "White Panther"
new plugin_version[] = "1.2.3"

public plugin_init( )
{
    
register_plugin("Connect Sound"plugin_versionplugin_author)
    
register_cvar("connectsound_version"plugin_versionFCVAR_SERVER)
}

public 
plugin_precache( )
{
    new 
temp[128], soundfile[128]
    for ( new 
0Maxsoundsa++ )
    {
        
format(temp127"sound/%s.wav"soundlist[a])
        if ( 
file_exists(temp) )
        {
            
format(soundfile127"%s.wav"soundlist[a])
            
precache_sound(soundfile)
        }
    }
}

public 
client_putinserverid )
{
    
set_task(1.0"consound"100 id)
}

public 
consoundtimerid_id )
{
    new 
id timerid_id 100
    
new Usertime
    Usertime 
get_user_time(id0)
    if ( 
Usertime <= )
    {
        
set_task(1.0"consound"timerid_id)
    }else
    {
        new 
random(Maxsounds)
        
client_cmd(id"spk ^"%s^""soundlist[i])
    }
    
    return 
PLUGIN_CONTINUE



Yusochan 12-08-2021 17:56

Re: [BUG] - Welcome Sound
 
Mate :/ are u okay ?

OciXCrom 12-09-2021 15:56

Re: [BUG] - Welcome Sound
 
1. client_connect() is called while the client is still connecting. Playing the sound 3 seconds after this doesn't guarantee that he is in the server and can hear the sound. It's best to use client_putinserver() for this which is called when the client enters the game.

2. You defined your path as "sound/misc/welcome.wav" but you're playing "welcome.wav" which defaults to the "sound" folder. You're not using the "szWelcome" variable there.

Shadows Adi 12-09-2021 16:48

Re: [BUG] - Welcome Sound
 
Replace
Code:

is_user_connected()
with
Code:

is_user_connecting()
http://www.amxmodx.org/api/amxmodx/is_user_connecting
http://www.amxmodx.org/api/amxmodx/is_user_connected

And what said OciXCrom at 2nd point.

OciXCrom 12-10-2021 02:24

Re: [BUG] - Welcome Sound
 
If he does that then it won't work if the player has connected which is very likely to happen when changing the forward.


All times are GMT -4. The time now is 11:36.

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