General > Developers Corner
Admin sounds, tools and other code chat.
jay209015:
I was wondering if someone could make a script that would play a sound when an admin joins the server.
I already have to sound I want to use, but I don't have any knowledge of lua. So if anyone could make a
small script it would be greatly appreciated.
MrPresident:
Here you go..! =)
--- Code: ---if SERVER then
function AdminJoins(ply)
if ply:IsAdmin() then
for i, v in ipairs(player.GetAll()) do
v:SendLua("surface.PlaySound(\"npc/turret_floor/active.wav\")")
end
end
end
hook.Add( "PlayerInitialSpawn", "adminjoins", AdminJoins );
end
--- End code ---
Simply replace npc/turret_floor/active.wav with whatever the path of your sound file is.
Save it to adminjoin.lua and put it in your lua/autorun folder on your server.
If the sound is custom, make sure you distribute it to your clients, you can do that with ULX in the server.ini file.
jay209015:
Wow, thx for the quick response. I made my own script, can you tell me if it's ok. If not could you tell me what's wrong with it and why, so I can learn lua.
--- Code: ---function AdminJoin( ply)
if ( !ply:IsAdmin() ) then return end
ply:ConCommand("ulx playsound fivefinger.mp3")
end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", AdminJoin );
--- End code ---
**EDIT**
BTW fivefinger.mp3 is a song lol
What does the i, v meain in your scrip?
MrPresident:
The only thing wrong with it is your tabbing is a bit off.. the end at the bottom should be over to line up with function, not with if. You have your end at the end of the if line already, but it would still run.
Assuming there isn't a problem with having the player run that command, it would work fine.
jay209015:
I understand most of your script, but could you explain
--- Code: ---for i, v in ipairs
--- End code ---
plz?
BTW, I applied for forum membership, and as a member of your community :D
Navigation
[0] Message Index
[#] Next page
Go to full version