• Problem with admin detector script?
    5 replies, posted
Ok so yesterday I made an admin detector script that is supposed to alert you when an admin/superadmin/owner joins the server, via a sound alert and a text alert, and then also lists the admins that are currently on the server. The script consists of two functions. The second function (ListAdmins) of the script simply outputs, in text, the current admins on the server and also what their rank is. This one works fine, I bind the concommand to a key and does what's specified; but the first function (AdminAlert) doesn't do anything when an admin joins. It doesn't give me any errors in console, says it's working fine. I'm kind of new to lua here so I'm not sure if I left something out in the function or put the wrong thing in somewhere. But yeah, can anyone here find the problem I'm having trouble with in the script? Thanks [code] function AdminAlert() local ply = LocalPlayer() for k, v in pairs( player.GetAll() ) do if v:IsAdmin() or v:IsSuperAdmin() or v:IsUserGroup( "Admin" ) or v:IsUserGroup( "Super Admin" ) or v:IsUserGroup( "Owner" ) then ply:PrintMessage( HUD_PRINTTALK, "Admin Alert!" ) ply:PrintMessage( HUD_PRINTTALK, "Admins: "..v:Nick().."." ) surface.PlaySound( "ambient/robot_admin.mp3" ) end end end hook.Add( "PlayerInitialSpawn", "AdminAlert", AdminAlert ) function ListAdmins() local ply = LocalPlayer() for k, v in pairs( player.GetAll() ) do if v:IsAdmin() or v:IsUserGroup( "Admin" ) then ply:PrintMessage( HUD_PRINTTALK, "Admins: "..v:Nick().."." ) elseif v:IsSuperAdmin() or v:IsUserGroup( "Super Admin" ) then ply:PrintMessage( HUD_PRINTTALK, "Super Admins: "..v:Nick().."." ) elseif v:IsUserGroup( "Owner" ) then ply:PrintMessage( HUD_PRINTTALK, "Owner: "..v:Nick().."." ) elseif v:IsAdmin() == "" and v:IsSuperAdmin() == "" and v:IsUserGroup( "Admin" ) == "" and v:IsUserGroup( "Super Admin" ) == "" and v:IsUserGroup( "Owner" ) == "" then ply:PrintMessage( HUD_PRINTTALK, "There are no admins on this server!" ) end end end concommand.Add( "muffin_sayalladmins", ListAdmins ) [/code]
Hi, [I]'PlayerInitialSpawn'[/I] is a special kind of function and because of it, you don't need to use a [I]'for loop'[/I], you just need to list it as an argument. When playing the sound, we are going to broadcast the lua playsound to ALL players so they know as well as create a fancy chat message! Try dropping this in your lua/autorun folder. [lua] if ( SERVER ) then hook.Add( "PlayerInitialSpawn", "AlertPlayers", function( ply ) -- GET THE FUNCTION AND PLAYER VARIABLE BroadcastLua( 'surface.PlaySound( "PATHTOSOUND" )' ) -- Broadcasts the Sound to ALL players umsg.Start( "GOPLAY" ) -- START IT umsg.String( "An Admin, "..ply:Nick()..", has Joined the Server!" ) -- THIS IS OUR MESSAGE umsg.End() -- SEND THAT SHIT end ) end if ( CLIENT ) then usermessage.Hook( "GOPLAY", function( data ) -- Gets the UMSG and it's data chat.AddText( Color( 255, 255, 255 ), data:ReadString() ) -- Prints the String in White text end ) end [/lua]
[QUOTE=MrGregsWorld;40860749]Hi, [I]'PlayerInitialSpawn'[/I] is a special kind of function and because of it, you don't need to use a [I]'for loop'[/I], you just need to list it as an argument. When playing the sound, we are going to broadcast the lua playsound to ALL players so they know as well as create a fancy chat message! Try dropping this in your lua/autorun folder. [lua] if ( SERVER ) then hook.Add( "PlayerInitialSpawn", "AlertPlayers", function( ply ) -- GET THE FUNCTION AND PLAYER VARIABLE BroadcastLua( 'surface.PlaySound( "PATHTOSOUND" )' ) -- Broadcasts the Sound to ALL players umsg.Start( "GOPLAY" ) -- START IT umsg.String( "An Admin, "..ply:Nick()..", has Joined the Server!" ) -- THIS IS OUR MESSAGE umsg.End() -- SEND THAT SHIT end ) end if ( CLIENT ) then usermessage.Hook( "GOPLAY", function( data ) -- Gets the UMSG and it's data chat.AddText( Color( 255, 255, 255 ), data:ReadString() ) -- Prints the String in White text end ) end [/lua][/QUOTE] Please stop using usermessages.
[QUOTE=MrGregsWorld;40860749]Hi, [I]'PlayerInitialSpawn'[/I] is a special kind of function and because of it, you don't need to use a [I]'for loop'[/I], you just need to list it as an argument. When playing the sound, we are going to broadcast the lua playsound to ALL players so they know as well as create a fancy chat message! Try dropping this in your lua/autorun folder. [lua] if ( SERVER ) then hook.Add( "PlayerInitialSpawn", "AlertPlayers", function( ply ) -- GET THE FUNCTION AND PLAYER VARIABLE BroadcastLua( 'surface.PlaySound( "PATHTOSOUND" )' ) -- Broadcasts the Sound to ALL players umsg.Start( "GOPLAY" ) -- START IT umsg.String( "An Admin, "..ply:Nick()..", has Joined the Server!" ) -- THIS IS OUR MESSAGE umsg.End() -- SEND THAT SHIT end ) end if ( CLIENT ) then usermessage.Hook( "GOPLAY", function( data ) -- Gets the UMSG and it's data chat.AddText( Color( 255, 255, 255 ), data:ReadString() ) -- Prints the String in White text end ) end [/lua][/QUOTE] oh crap i forgot to say it's a clientside-only script. So do I just do if( CLIENT ) hook.Add yada yada..?
[QUOTE=tpops123;40860985]oh crap i forgot to say it's a clientside-only script. So do I just do if( CLIENT ) hook.Add yada yada..?[/QUOTE] If you researched before asking this question you would realise that the "PlayerInitialSpawn" hook is serverside only.
[QUOTE=brandonj4;40860991]If you researched before asking this question you would realise that the "PlayerInitialSpawn" hook is serverside only.[/QUOTE] I never knew that O.o, idk I thought it was both client and server for some reason :/ thx
Sorry, you need to Log In to post a reply to this thread.