• Chat sounds delay
    4 replies, posted
Hello, I have a "Chat sounds" script on my GMOD server (I didn't make it myself). It is working fine but I would like to add a delay/cooldown between these sounds to avoid spammers. With a line to the player trying to spam "You have to wait X more seconds to play the sound..." would be nice. Can someone help me ? Here is the current script: USay = {} USay.WordList = { ["ayaya"] = "chatsounds/ayaya.ogg"; ["uhh"] = "chatsounds/uhh.ogg"; ["ffs"] = "chatsounds/ffs.ogg"; ["wtf"] = "chatsounds/wtf.ogg"; ["yolo"] = "chatsounds/yolo.ogg"; ["yo"] = "chatsounds/yo.ogg"; } function USay.ChatFunction( ply, text )     if ply:IsValid() then         for k,v in pairs(USay.WordList) do             if string.match(" "..text.." ", "%A"..k.."%A" ) then                 ply:EmitSound(USay.WordList[k],80,100,0.75, CHAN_WEAPON)                 print(text,k)                 return text             end         end     end end hook.Add("PlayerSay", "USay.ChatFunction_Hook", USay.ChatFunction) Thanks !
I m not actually sure, but you can try make simple delay with CurTime(). Something like this: local delay = 1 local nextOccurance = 0 USay = {} USay.WordList = { ["ayaya"] = "chatsounds/ayaya.ogg"; ["uhh"] = "chatsounds/uhh.ogg"; ["ffs"] = "chatsounds/ffs.ogg"; ["wtf"] = "chatsounds/wtf.ogg"; ["yolo"] = "chatsounds/yolo.ogg"; ["yo"] = "chatsounds/yo.ogg"; } function USay.ChatFunction( ply, text )if ply:IsValid() then for k,v in pairs(USay.WordList) do if string.match(" "..text.." ", "%A"..k.."%A" ) then local timeLeft = nextOccurance - CurTime() if timeLeft < 0 then ply:EmitSound(USay.WordList[k],80,100,0.75, CHAN_WEAPON) nextOccurance = CurTime() + delay end print(text,k) return text end end end end hook.Add("PlayerSay", "USay.ChatFunction_Hook", USay.ChatFunction) Got from here.
Thank you. I'm afraid to say that i'm not good for scripting... Can anyone else help me maybe ?
Any other suggestions ?
USay = {} USay.WordList = { ["ayaya"] = "chatsounds/ayaya.ogg", ["uhh"] = "chatsounds/uhh.ogg", ["ffs"] = "chatsounds/ffs.ogg", ["wtf"] = "chatsounds/wtf.ogg", ["yolo"] = "chatsounds/yolo.ogg", ["yo"] = "chatsounds/yo.ogg", } function USay.ChatFunction( ply, text ) if ply:IsValid() then for k,v in pairs(USay.WordList) do if string.match(" "..text.." ", "%A"..k.."%A") and (ply.Cooldown and ply.Cooldown < CurTime()) then ply:EmitSound(USay.WordList[k],80,100,0.75, CHAN_WEAPON) ply.Cooldown = CurTime() + 5; return text end end end end hook.Add("PlayerSay", "USay.ChatFunction_Hook", USay.ChatFunction) should work
Sorry, you need to Log In to post a reply to this thread.