When a certain player by their steamid joins the game, they get a sound playing like 'An admin has join the game.'
Use PlayerInitialSpawn or PlayerAuthed and use if ply:IsAdmin() then ply:EmitSound("somesound.mp3",500,100) end shouldn't be hard to figure out [url]http://wiki.garrysmod.com/?title=Gamemode.PlayerInitialSpawn[/url]
[url]http://wiki.garrysmod.com/?title=Gamemode.PlayerAuthed[/url]
I have no idea how to code lua, thats why I am requesting..
Err. this might work.
[code]
function GM:PlayerInitialSpawn(ply)
for k,v in pairs(player.GetAll()) do
if ply:IsAdmin then
v:EmitSound("anysound.mp3",500,100) and v:PrintMessage(HUD_PRINTCENTER,"An admin has arrived!")
end
end
end
[/code]
and for the unique steam id it to do that, this maybe?
[code]
function GM:PlayerInitialSpawn(ply)
for k,v in pairs(player.GetAll()) do
if (ply:SteamID() =="STEAM:0:0:123456789") then
v:EmitSound("anysound.mp3",500,100) and v:PrintMessage(HUD_PRINTCENTER,"An admin has arrived!")
end
end
end
[/code]
I wrote them both quickly, and they might not work. Would a higher experienced person please kindly tell me if I coded one/both/ or none right?
You don't need and in there and change ply:EmitSound to v:EmitSound so everyone would hear it you only need if ply:IsAdmin() or (ply:SteamID() == "STEAM:0:0:123456789")
would this go into autorun?
[editline]24th October 2010[/editline]
[lua\autorun\client\serveradmin.lua:1] unexpected symbol near '{'
Doesn't anyone in this thread know how to code?
Slash it goes in the serverside folder but it wouldn't work anyway.
Use this
[lua]
JoiningSounds = {}
JoiningSounds[1] = "adminsound.mp3"
JoiningSounds[2] = "NormalSound.mp3"
hook.Add("PlayerInitialSpawn", "SoundSpawn", function(ply)
if ply:IsAdmin() then
ply:EmitSound(JoiningSounds[1], 500, 200)
else
ply:EmitSound(JoiningSounds[2], 500, 200)
end
end)
[/lua]
Replace admin sound and normal sound with the sounds that you want to be played.
[QUOTE=sintwins;25614133]ShitPost.[/QUOTE]
Idiot, that would only play for the person that joined not for everyone, you need to learn more about coding.
[QUOTE=Cubar;25617308]Idiot, that would only play for the person that joined not for everyone, you need to learn more about coding.[/QUOTE]
His thing would emit a sound from the player, anyone would hear it if they were close enough.
[QUOTE=MegaJohnny;25617446]His thing would emit a sound from the player, anyone would hear it if they were close enough.[/QUOTE]
Yeh but it's better to play it on all of the players.
[QUOTE=Cubar;25617673]Yeh but it's better to play it on all of the players.[/QUOTE]
Although I don't like Cubar, I do agree with him, it would be better for every player to hear it not just close players
[lua]
local JoiningSounds = {'adminsound.mp3', 'normalsound.mp3'}
hook.Add('PlayerInitialSpawn', 'SoundSpawn' function(ply)
timer.Simple(.5, function()
if(ValidEntity(ply)) then
if(ply:IsAdmin()) then
BroadcastLua('surface.PlaySound("'..JoiningSounds[1]..'")')
else
BroadcastLua('surface.PlaySound("'..JoiningSounds[2]..'")')
end
end
end)
end)
[/lua]
:eng101:
Don't use BroadcastLua.
Put this in lua/autorun/admin_spawn.lua (or whatever you want to name the lua file as)
[lua]AddCSLuaFile( "admin_spawn.lua" ) //change this to whatever file name you named the lua file
if SERVER then
hook.Add( "PlayerInitialSpawn", "SoundSpawn", function( ply )
timer.Simple( .5, function() //player isn't completely there yet
if !IsValid( ply ) then return end
umsg.Start( "SoundSpawn" )
umsg.Bool( ply:IsAdmin() ) //could check for admin clientside, but that would require sending the player ent instead of a simple bool
umsg.End()
end )
end )
else //client
usermessage.Hook( "SoundSpawn", function( um )
//only the client really needs to know about this table
//hell we don't even need this table, it's just for simplification
local JoiningSounds = {
["Admin"] = Sound( "adminsound.mp3" ),
["Player"] = Sound( "normalsound.mp3" )
}
local admin = um:ReadBool() or false
if admin then
surface.PlaySound( JoiningSounds.Admin )
else
surface.PlaySound( JoiningSounds.Player )
end
end )
end[/lua]
Broadcast lua is fine as long as it's not getting called too often. As is Player:SendLua
Sorry, you need to Log In to post a reply to this thread.