AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How work this is_user_connected (Need some Help) (https://forums.alliedmods.net/showthread.php?t=155797)

.Dare Devil. 04-26-2011 17:20

How work this is_user_connected (Need some Help)
 
Hi

Is it correct.
I want this, if player connecting on server then this client_cmd "mp3 play"
Not work for him like if client connect then no sounds play only loading sound plugin.

Here is my code.
PHP Code:

 
// Plays a sound on clients
PlaySound_Mp3(const sound[] , id)
{
 if (!
is_user_connected(id))
 
client_cmd(0"mp3 play ^"sound/%s^""sound)
}
PlayMP3Sound(const soundMP3[])
{
 if (!
is_user_connected(0)) 
 
client_cmd(0"mp3 play ^"sound/%s^""soundMP3)


Is this works same like i want ?

SonicSonedit 04-26-2011 17:38

Re: How work this is_user_connected (Need some Help)
 
.Dare Devil.
The "!" means "NOT". if (!is_user_connected(id)) means "if client #id NOT connected". if (!is_user_connected(0)) statement has no meaning, because there is no player #0. Player numbers are from 1 to get_maxplayers(). 0 used as "all players" "server" and "worldspawn" in some functions, but in most cases it means "no value", "not found" or "error".

Quote:

I want this, if player connecting on server then this client_cmd "mp3 play"
Ancient and one of my favourite plugins:
PHP Code:

Play a sound during the connection.
*
Random code part taken from plugin
connectsound by White Panther
*
v1.0
*
*/

#include <amxmodx>

// sounds localized in gcf cache (valve/media)
// you can add more song if you want.
new soundlist[][] = {"Half-Life01","Half-Life02","Half-Life04","Half-Life12","Half-Life13","Half-Life17"}

public 
client_connect(id)
    
client_cmd(id,"mp3 play media/%s",soundlist[random_num(0charsmax(soundlist))])

public 
plugin_init()
    
register_plugin("Loading Sound","1.0","Amxx User"

Just 2 functions, 5 lines and yet so usefull <3

.Dare Devil. 04-26-2011 18:13

Re: How work this is_user_connected (Need some Help)
 
I mean this code is like i want

PHP Code:

 
PlaySound_Mp3
(const sound[] , id)
{
 if (!
is_user_connected(id))
 
client_cmd(0"mp3 play ^"sound/%s^""sound)


When userd connecting or loading ( he are not yet on server. Loading ...:) ) or download models or sounds then playSound_Mp3 Dont work for this client who was loading or download items.

SonicSonedit 04-26-2011 18:22

Re: How work this is_user_connected (Need some Help)
 
PHP Code:

PlaySound_Mp3(const sound[] , id)
{
 if (!
is_user_connected(id))
 
client_cmd(0"mp3 play ^"sound/%s^""sound)


1) coded incorrectly
2) does nothing
3) use code from post #2

.Dare Devil. 04-27-2011 01:39

Re: How work this is_user_connected (Need some Help)
 
You mean this
PHP Code:

 
PlayMP3Sound
(const soundMP3[])
{
 if (!
is_user_connected(0)) 
 
client_cmd(0"mp3 play ^"sound/%s^""soundMP3)


When yes thanks you soo much.
it was very important for me...

ConnorMcLeod 04-27-2011 02:40

Re: How work this is_user_connected (Need some Help)
 
You have to loop all players.

PHP Code:

PlaySound_Mp3(const szSound[] , id)
{
    if( 
id )
    {
        if( 
is_user_connected(id) && !is_user_connecting(id) )
        {
            
client_cmd(id"mp3 play %s"szSound)
        }
    }
    else
    {
        new 
iPlayers[32], iNum
        get_players
(iPlayersiNum"c")
        for(--
iNumiNum>=0iNum--)
        {
            
id iPlayers[iNum]
            if( !
is_user_connecting(id) )
            {
                
client_cmd(id"mp3 play %s"szSound)
            }
        }
    }



.Dare Devil. 04-27-2011 05:08

Re: How work this is_user_connected (Need some Help)
 
Quote:

Originally Posted by ConnorMcLeod (Post 1458702)
You have to loop all players.

PHP Code:

PlaySound_Mp3(const szSound[] , id)
{
    if( 
id )
    {
        if( 
is_user_connected(id) && !is_user_connecting(id) )
        {
            
client_cmd(id"mp3 play %s"szSound)
        }
    }
    else
    {
        new 
iPlayers[32], iNum
        get_players
(iPlayersiNum"c")
        for(--
iNumiNum>=0iNum--)
        {
            
id iPlayers[iNum]
            if( !
is_user_connecting(id) )
            {
                
client_cmd(id"mp3 play %s"szSound)
            }
        }
    }



Thanks.

.Dare Devil. 04-27-2011 09:49

Re: How work this is_user_connected (Need some Help)
 
Now i done.
But is that correct what i done?

Call the play

PHP Code:

 
 
// Play it on clients
 
if (ismp3)
  
PlaySound_Mp3(sound id)
 else
  
PlaySound(sound)
 
 
// Set the task for when the sound is done playing
 
set_task(float(duration), "ambience_sound_effects"TASK_AMBIENCESOUNDS

PHP Code:

 
  
// Play win sound and increase score
  
ArrayGetString(sound_win_humansrandom_num(0ArraySize(sound_win_humans) - 1), soundMP3charsmax(soundMP3))
  
PlayMP3Sound(soundMP3id)
  
g_scorehumans++ 

And Now.

PHP Code:

 
PlaySound_Mp3
(const sound[] , id

    if( 
id 
    { 
        if( 
is_user_connected(id) && !is_user_connecting(id) ) 
        { 
            
client_cmd(id"mp3 play ^"sound/%s^""sound
        } 
    } 
    else 
    { 
        new 
iPlayers[32], iNum 
        get_players
(iPlayersiNum"c"
        for(--
iNumiNum>=0iNum--) 
        { 
            
id iPlayers[iNum
            if( !
is_user_connecting(id) ) 
            { 
                
client_cmd(id"mp3 play ^"sound/%s^""sound 
            } 
        } 
    } 

PlayMP3Sound(const soundMP3[] , id

    if( 
id 
    { 
        if( 
is_user_connected(id) && !is_user_connecting(id) ) 
        { 
            
client_cmd(id"mp3 play ^"sound/%s^""soundMP3
        } 
    } 
    else 
    { 
        new 
iPlayers[32], iNum 
        get_players
(iPlayersiNum"c"
        for(--
iNumiNum>=0iNum--) 
        { 
            
id iPlayers[iNum
            if( !
is_user_connecting(id) ) 
            { 
                
client_cmd(id"mp3 play ^"sound/%s^""soundMP3 )
            } 
        } 
    } 



Exolent[jNr] 04-27-2011 14:53

Re: How work this is_user_connected (Need some Help)
 
Why do you have 2 functions that do the exact same thing?

Use one of those in all places where both are used and then delete the one you didn't use.

.Dare Devil. 04-27-2011 16:01

Re: How work this is_user_connected (Need some Help)
 
Quote:

Originally Posted by Exolent[jNr] (Post 1459056)
Why do you have 2 functions that do the exact same thing?

Use one of those in all places where both are used and then delete the one you didn't use.

Some items not working when i do this way.


All times are GMT -4. The time now is 04:20.

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