I tried to make a script the main idea of it to disable voice or mute everybody on the server for 60 sec for newly arriving players.
And i made this:
[CODE]
function Mute( ply )
for _,ply in ipairs(player:GetAll()) do
ply:SetMuted(true);
end
end
hook.Add( "PlayerInitialSpawn", "PlayerInitialSpawn", Mute)
timer.Create( "UnMuteTimer", 60, 1, function( ply )
for _,ply in ipairs(player:GetAll()) do
ply:SetMuted(false);
end
end)
[/CODE]
No errors in server or client console.
I see many errors with your code:
1. timer.Create will only be created once since it's outside of any function/hook, anyone that joins would make everyone mute forever
2. you use ply as the argument in PlayerInitialSpawn, but then you use it again in your for loop.
3. ply:SetMuted is a clientside function
[lua]--server
local function Mute( ply )
umsg.Start("muteall")
end
hook.Add( "PlayerInitialSpawn", "PlayerInitialSpawnMute", Mute)[/lua]
[lua]
--client
usermessage.Hook("muteall", function()
for _,v in pairs(player.GetAll()) do
v:SetMuted(true)
end
if timer.IsTimer("unmute") then
timer.Remove("unmute")
end
timer.Create("unmute", 60, 1, function()
for _,v in pairs(player.GetAll()) do
v:SetMuted(false)
end
end)
end)[/lua]
Hmm...when im spawn on server it place error to server console
[QUOTE]Error - Starting message without ending the old one![/QUOTE]
Thanks for help, but it is really doen't work too
The same error
[QUOTE]Error - Starting message without ending the old one![/QUOTE]
Usermessages won't send unless you end them.
[lua]
AddCSLuaFile("autorun/NAMEOFSCRIPT.lua")
if SERVER then
local function Mute( ply )
umsg.Start("muteall")
umsg.End()
end
hook.Add( "PlayerInitialSpawn", "PlayerInitialSpawnMute", Mute)
else -- Client
usermessage.Hook("muteall", function()
for _,v in pairs(player.GetAll()) do
v:SetMuted(true)
end
if timer.IsTimer("unmute") then
timer.Remove("unmute")
end
timer.Create("unmute", 60, 1, function()
for _,v in pairs(player.GetAll()) do
v:SetMuted(false)
end
end)
end)
end
[/lua]
Place it in your servers lua/autorun folder and change "AddCSLuaFile("autorun/NAMEOFSCRIPT.lua")" and it should work
[editline]15th June 2012[/editline]
If it doesn't work, feel free to add me on steam, I'll try to help.
Probably this doesn't work too, when i spawn i head player voices.
Maybe it will work i such another way?
Anybody help
You probably shouldn't be using PlayerInitialSpawn. From the wiki "Called when you start 'sending client info' rather then when you actually spawn." So there is a good chance that running SetMuted won't do anything at that time.
I'd try it in PlayerAuthed or some other hook that is called later.
Sorry, you need to Log In to post a reply to this thread.