SoundDuration() & limiting the player from spamming ply.EmitSound()
1 replies, posted
I created a Derma Menu, now it works. The sounds are send via Net.SendToServer() commands, they play for everyone.
Though it doesn't limit the player on how many times he can press the button in order to play the sound, meaning it could cause spam.
I want to limit that the player who started the sound has to wait until the initial taunt he played will end before playing another one.
The Client Side Menu code:
[code]if ( CLIENT ) then
local FKeyMenus = {
KEY_F4 = phm_1;
KEY_C = phm_1;
};
hook.Add( "PlayerBindPress", "PlayerBindPressFKeyMenus", function( _p, _bind, _pressed )
local _key = "KEY_" .. string.upper( input.LookupBinding( _bind ) );
local _func = FKeyMenus[ _key ];
if ( _func) then
_func( LocalPlayer() );
else
end
end);
//Menu
function phm_1(_p)
print("Received hook.call( taunt_p1 ) from player, opening menu page 1")//Debug Line for hook.Call
local p1_base = vgui.Create( "DFrame") //Menu Frame
p1_base:SetSize(176, 571)
p1_base:SetPos(1728, 208)
p1_base:SetTitle("Taunts - Page 1")
p1_base:SetVisible( true )
p1_base:SetDeleteOnClose(false)
p1_base:ShowCloseButton(false)
p1_base:SetDraggable(false)
p1_base:SetKeyBoardInputEnabled(false)
p1_base:SetMouseInputEnabled(true)
p1_base:MakePopup(false)
local b1 = vgui.Create("DButton", p1_base) //Button1
b1:SetSize(150, 33)
b1:SetPos(12,35)
b1:SetText("Boom Headshot!")
b1.DoClick = function ()
net.Start("send_p1_B1")
net.WriteString("taunts/props/1.wav")//Boom Headshot
net.SendToServer()
end
end
end[/code]
the Server Side code:[code]
if ( SERVER ) then
TAUNT_DELAY = 3
//Menu Page 1
//Button1
util.AddNetworkString("send_p1_B1")
net.Receive( "send_p1_B1", function( ply )
if SoundDuration(net.ReadString()) + TAUNT_DELAY <= CurTime() then
for _,ply in pairs(player.GetAll()) do
ply:EmitSound(net.ReadString())
print("Should Play sound")//Debug Print
end
else
print("Wait until the taunt is finished.")
end
end )
end[/code]
Now this code doesn't play the sound when the button is pressed nor it give any errors. Only thing that happens when I press the button is that this appears twice in console: [code]print("Should Play sound")//Debug Print[/code]
Any tips or ideas as to why it doesn't work?
Just so you guys don't waste your time replying: I posted an answer to his problem here: [url]http://facepunch.com/showthread.php?t=1411111&p=46206968&viewfull=1#post46206968[/url]
Sorry, you need to Log In to post a reply to this thread.