Player Connect sounds help.

Hey guys once again I’m in need of help. I have a script that shows when a player connects to my server + plays a sound, I’ve edited it to make it play a sound depending on their rank ( Admin or not ) but I’ve got it so it checks local players so if your an admin on the server you’ll always hear the admin connecting sound where as the none admins will hear the member connecting sound.

What I am asking here is there a way to check if the player connecting to the server is admin or not a play the sound depending on his rank and not everyones on the server?

This is the code:

// Connect
function player_connect( data )
local ply = LocalPlayer()
local name1 = data:ReadString()
local nickteamcolour1 = team.GetColor(data:ReadShort())
	chat.AddText( Color( 15, 15, 15 ), "[Server] ", nickteamcolour1, name1, Color( 255, 255, 255 ), " has joined the server." )
if ply:IsAdmin() then
	surface.PlaySound( "ag/WelcomeAdmin.mp3" )
elseif ply:IsUserGroup( "user" ) or ply:IsUserGroup( "respected" ) then
	surface.PlaySound( "ag/MemberJoined.mp3" )
usermessage.Hook("player_connect", player_connect)

// Disconnect
function player_disconnect( data )
local name2 = data:ReadString()
local nickteamcolour2 = team.GetColor(data:ReadShort())
	chat.AddText( Color( 15, 15, 15 ), "[Server] ", nickteamcolour2, name2, Color( 255, 255, 255 ), " has left the server." )
	surface.PlaySound( "garrysmod/save_load2.wav" )
usermessage.Hook("player_disconnect", player_disconnect)


send the players entity in the usermessage, then you dont need to send the nick and team as a bonus :slight_smile:

That is true thank you for that :smiley: but I’m just also trying to figure out why its not playing the same sound for everyone based of the guys rank that is joining :o

What? I just gave you the solution, replace ply = with the player entity that you send in usermessage, LocalPlayer() is the player that hears the sound

Oh you did haha sorry, I’m in a derp mood today, no sleep plays havoc with your mind. Thanks again much appreciated :slight_smile:

[editline]8th February 2013[/editline]

I think I fail at this I tired a few different things but Its still not working for me, Reckon you’d be able to whip up that line of code for me please?

Don’t even use usermessages… use the new net library…

This is not all my code, I only added in the part where it plays depending on what rank you are, but it plays the admin song to all admins on server even if the person connecting is a user and all users only hear the member connecting song even if the user is an admin connecting.

I’d code it for you real quick if you’d add me on steam, mainly to have someone to test it with and so you can give me direction in waht you want exactly. My steam is in my profile