Hi facepunch.
So I added a script that allows the use of spoken emotes. Just for fun.
However, as always - the players have figured out how to abuse it and generally spam the sounds. I was wondering how I would go about making a limit?
Here's the original code:
[LUA]hook.Add("PlayerSay", "Emotes1", function(ply, say, team)
if (emotes[say]) and ply:Alive() and ply:Team() != TEAM_SPECTATOR then
local snds = emotes[say]
if (type(snds) == "table") and ply:Alive() then
ply:EmitSound(table.Random(snds), 100, 100)
else
ply:EmitSound(snds, 100, 100)
end
return message;
end
end)[/LUA]
I tried using Set/GetNWBool like so:
[LUA]hook.Add("PlayerSay", "Emotes2", function(ply, say, team)
ply:SetNWBool( "canchat", true )
if (emotes[say]) and ply:Alive() and ply:Team() != TEAM_SPECTATOR and ply:GetNWBool( "canchat", true ) then
local snds = emotes[say]
if (type(snds) == "table") and ply:Alive() then
ply:EmitSound(table.Random(snds), 100, 100)
else
ply:EmitSound(snds, 100, 100)
end
ply:SetNWBool( "canchat", false )
timer.Simple( 5, function()
ply:SetNWBool( "canchat", true )
end)
return ""
end
end)[/LUA]
then I tried using os.time():
[LUA]local function CanChat( time )
if time+5<time then return false end
return true
end
hook.Add("PlayerSay", "Emotes2", function(ply, say, team)
if (emotes[say]) and ply:Alive() and ply:Team() != TEAM_SPECTATOR and CanChat(os.time()) then
local snds = emotes[say]
if (type(snds) == "table") and ply:Alive() then
ply:EmitSound(table.Random(snds), 100, 100)
else
ply:EmitSound(snds, 100, 100)
end
return ""
end
end)[/LUA]
Now I'm stuck.
I've googled it too, and all that came up was some way to stop a steamid from using the chat sounds.
Any help or ideas would be greatly appreciated, thanks.
[lua]
if ((ply.nextEmote or 0) < CurTime()) then
ply.nextEmote = CurTime() + 5
ply:EmitSound(huehue)
end
[/lua]
Thanks a ton Chessnut!
Sorry, you need to Log In to post a reply to this thread.