hi, I would like to make some chatsound only available For the CPs , is it possible or not. And if is it can you tell me how to do it please ?
Thanks,
Benji
You mean like the chat sound from the CP in HL2RP?
Make a check if the job is CP then play the sound file.
I will try to do this will it work ?
[code]
customCheck = function(ply) return CLIENT or not ply:IsCP() end
[/code]
[QUOTE=benji131201;48866014]I will try to do this will it work ?
[code]
customCheck = function(ply) return CLIENT or not ply:IsCP() end
[/code][/QUOTE]
make an actual lua code..
-facepalms- I dont mean customcheck - besides its only for shipments etc - I ment hook into the chat function, and make it play the certain sound if they're cp.
which hook do I need to use ?
You're going to want to use [URL="http://wiki.garrysmod.com/page/GM/PlayerSay"]this[/URL]
[CODE]local Sounds = {
["Hello"] = {"soundfile1", "soundfile2"},
["Bye"] = {"same"}
}
hook.Add("PlayerSay", "ChatSoundsForCP", function(ply, text)
local prefix = string.sub(text, 0, 1)
if prefix == "/" or prefix == "!" or prefix == "@" then return end
if not ply:IsCP() then return end
for k, v in pairs(Sounds) do
local res1, res2 = string.find(string.lower(text), k)
if res1 and (not text[res1 - 1] or text[res1 - 1] == "" or text[res1 - 1] == " ") and (not text[res2 + 1] or text[res2 + 1] == "" or text[res2 + 1] == " ") then
ply:EmitSound(table.Random(v), 80, 100)
break
end
end
end)[/CODE]
Here
[QUOTE=boxvader;48866731]Oh good lord :hairpull:
-code-[/QUOTE]
Friendly, but please dont spoonfeed :c
[editline]9th October 2015[/editline]
[QUOTE=geferon;48866874]-snip-[/QUOTE]
Dont spoonfeed :c - Also ply:isCP() is better than making the teams manually.
[QUOTE=whitestar;48866875]dont spoonfeed :c[/QUOTE]
That's why I didn't try and fix all the code just gave him the hook.
[QUOTE=whitestar;48866875]Dont spoonfeed :c - Also ply:isCP() is better than making the teams manually.[/QUOTE]
Edited now
I tried but it's not working ? here is the entire code that I found somewhere else :
[code]
local Sounds = {
sounds[ "404" ] = { "npc/metropolice/vo/possible404here.wav" },
sounds[ "505" ] = { "npc/metropolice/vo/subjectis505.wav" },
sounds[ "citoyen" ] = { "npc/metropolice/vo/citizen.wav" },
sounds[ "code 100" ] = { "npc/metropolice/vo/code100.wav" },
sounds[ "recherche de suspect" ] = { "npc/metropolice/hiding02.wav" },
sounds[ "bloquer"] = { "npc/metropolice/vo/lock.wav" },
sounds[ "isolez" ] = { "npc/metropolice/vo/isolate.wav" },
sounds[ "appliquer" ] = { "npc/metropolice/takedown.wav" },
sounds[ "zone 404" ] = { "npc/metropolice/vo/404zone.wav" },
sounds[ "visuel" ] = { "npc/metropolice/vo/acquiringonvisual.wav" },
sounds[ "administrer" ] = { "npc/metropolice/vo/administer.wav" },
sounds[ "affirmative" ] = { "npc/metropolice/vo/affirmative.wav" },
sounds[ "Ghost patrouille aerienne 505" ] = { "npc/metropolice/vo/airwatchsubjectis505.wav" },
sounds[ "circulez" ] = { "npc/metropolice/vo/allrightyoucango.wav" },
sounds[ "tous sur le suspect" ] = { "npc/metropolice/vo/allun" },
sounds[ "allez au qg" ] = { "npc/metropolice/vo/allunitsmovein.wav" },
sounds[ "localisez le suspect" ] = { "npc/metropolice/vo/allunitsreportlocationsuspect.wav" },
sounds[ "amputez" ] = { "npc/metropolice/vo/amputate.wav" },
sounds[ "anti citoyen" ] = { "npc/metropolice/vo/anticitizen.wav" },
sounds[ "urgence code 2" ] = { "npc/metropolice/vo/allunitscode2.wav" },
sounds[ "34s dans" ] = { "npc/metropolice/vo/allunitsbol34sat.wav" },
sounds[ "anti citoyen libre" ] = { "npc/metropolice/vo/anyonepickup647e.wav" },
sounds[ "appliquer" ] = { "npc/metropolice/vo/apply.wav" },
sounds[ "pdc" ] = { "npc/metropolice/vo/atcheckpoint.wav" },
sounds[ "insectes" ] = { "npc/metropolice/vo/bugs.wav"},
sounds[ "insectes libre" ] = { "npc/metropolice/vo/bugsontheloose.wav" },
sounds[ "channel" ] = { "npc/metropolice/vo/canal.wav" },
sounds[ "bip" ] = { "npc/metropolice/vo/catchthatbliponstabilization.wav"},
sounds[ "haha" ] = { "npc/metropolice/vo/chuckle.wav" },
sounds[ "session usine" ] = { "npc/metropolice/vo/citizensummoned.wav" },
sounds[ "sujet deceder" ] = { "npc/metropolice/vo/classifyasdbthisblockready.wav" },
sounds[ "zone bloquer" ] = { "npc/metropolice/vo/condemnedzone.wav" },
sounds[ "confirmation dataincarne sur le suspect 10-0" ] = { "npc/metropolice/vo/confirmadw.wav" },
sounds[ "recu" ] = { "npc/metropolice/vo/copy.wav" },
sounds[ "unite defaillante" ] = { "npc/metropolice/vo/cpiscompromised.wav" },
sounds[ "position unite" ] = { "npc/metropolice/vo/cprequestsallunitsreportin.wav" },
sounds[ "intrusion criminelle" ] = { "npc/metropolice/vo/criminaltrespass63.wav" },
sounds[ "nombre de mort" ] = { "npc/metropolice/vo/dbcountis.wav" },
sounds[ "intrusion suspect" ] = { "npc/metropolice/vo/dispreportssuspectincursion.wav" },
sounds[ "documentez" ] = { "npc/metropolice/vo/document.wav" },
sounds[ "pas un geste" ] = { "npc/metropolice/vo/dontmove.wav" },
sounds[ "examine" ] = { "npc/metropolice/vo/examine.wav" },
sounds[ "verdict final" ] = { "npc/metropolice/vo/finalverdictadministered.wav" },
sounds[ "dernier avertisement" ] = { "npc/metropolice/vo/finalwarning.wav" },
sounds[ "premier avertisement" ] = { "npc/metropolice/vo/firstwarningmove.wav" },
sounds[ "necrotique libre" ] = { "npc/metropolice/vo/freenecrotics.wav" },
sounds[ "a terre" ] = { "npc/metropolice/vo/getdown.wav" },
sounds[ "complice ici" ] = { "npc/metropolice/vo/gotoneaccomplicehere.wav" },
sounds[ "hero" ] = { "npc/metropolice/vo/hero.wav" },
sounds[ "stop sa" ] = { "npc/metropolice/vo/holditrightthere.wav" },
sounds[ "injecte" ] = { "npc/metropolice/vo/inject.wav" },
sounds[ "dit circulez" ] = { "npc/metropolice/vo/Isaidmovealong.wav" },
sounds[ "passive" ] = { "npc/metropolice/vo/ispassive.wav" },
sounds[ "refus obtemperer" ] = { "vo/npc/male01/whoops01.wav" },
sounds[ "roi" ] = { "npc/metropolice/vo/king.wav" },
sounds[ "refus test loyauter" ] = { "npc/metropolice/vo/loyaltycheckfailure.wav" },
sounds[ "hostile" ] = { "npc/metropolice/vo/malignant.wav" },
sounds[ "recule maintenant" ] = { "npc/metropolice/vo/movebackrightnow.wav" },
sounds[ "avencez" ] = { "npc/metropolice/vo/moveit.wav" },
sounds[ "necrotique" ] = { "npc/metropolice/vo/necrotics.wav" },
sounds[ "aide pour celui la" ] = { "npc/metropolice/vo/needanyhelpwiththisone.wav" },
sounds[ "code 3 10-20" ] = { "npc/metropolice/vo/officerdowncode3tomy10-20.wav" },
sounds[ "patrouille" ] = { "npc/metropolice/vo/patrol.wav" },
sounds[ "ramasse cette boite" ] = { "npc/metropolice/vo/pickupthecan1.wav" },
sounds[ "jugement civil" ] = { "npc/metropolice/vo/prepareforjudgement.wav" },
sounds[ "rendez vous pdc" ] = { "npc/metropolice/vo/proceedtocheckpoints.wav" },
sounds[ "met sa dans la poubelle" ] = { "npc/metropolice/vo/putitinthetrash1.wav" },
sounds[ "zone interdite" ] = {"npc/metropolice/vo/restrictedblock.wav" },
sounds[ "deuxieme avertisement" ] = { "npc/metropolice/vo/secondwarning.wav" },
sounds[ "merde" ] = { "npc/metropolice/vo/shit.wav" },
sounds[ "test loyauter" ] = { "npc/metropolice/vo/standardloyaltycheck.wav" },
sounds[ "sterelisez" ] = { "npc/metropolice/vo/sterilize.wav" },
sounds[ "confirmation data" ] = { "npc/metropolice/vo/confirmadw.wav" },
sounds[ "union" ] = { "npc/metropolice/vo/union.wav" },
sounds[ "ta renverse ramase" ] = { "npc/metropolice/vo/youknockeditover.wav" },
sounds[ "affirmative" ] = { "npc/combine_soldier/vo/affirmative.wav" },
sounds[ "debut" ] = { "npc/combine_soldier/vo/engaging.wav" },
sounds[ "foncez foncez" ] = { "npc/combine_soldier/vo/gosharpgosharp.wav" },
sounds[ "milice" ] = { "npc/combine_soldier/vo/overwatch.wav" }
}
DarkRP.hookStub{
name = "canChatSound",
description = "Whether a chat sound can be played.",
parameters = {
{
name = "ply",
description = "The player who triggered the chat sound.",
type = "Player"
},
{
name = "chatPhrase",
description = "The chat sound phrase that has been detected.",
type = "string"
},
{
name = "chatText",
description = "The whole chat text the player sent that contains the chat sound phrase.",
type = "string"
}
},
returns = {
{
name = "canChatSound",
description = "False if the chat sound should not be played.",
type = "boolean"
}
}
}
DarkRP.hookStub{
name = "onChatSound",
description = "When a chat sound is played.",
parameters = {
{
name = "ply",
description = "The player who triggered the chat sound.",
type = "Player"
},
{
name = "chatPhrase",
description = "The chat sound phrase that was detected.",
type = "string"
},
{
name = "chatText",
description = "The whole chat text the player sent that contains the chat sound phrase.",
type = "string"
}
},
returns = {
}
}
local function CheckChat(ply, text)
if not GAMEMODE.Config.chatsounds or ply.nextSpeechSound and ply.nextSpeechSound > CurTime() then return end
local prefix = string.sub(text, 0, 1)
if prefix == "/" or prefix == "!" or prefix == "@" then return end -- should cover most chat commands for various mods/addons
for k, v in pairs(sounds) do
local res1, res2 = string.find(string.lower(text), k)
if res1 and (not text[res1 - 1] or text[res1 - 1] == "" or text[res1 - 1] == " ") and (not text[res2 + 1] or text[res2 + 1] == "" or text[res2 + 1] == " ") then
local canChatSound = hook.Call("canChatSound", nil, ply, k, text)
if canChatSound == false then return end
ply:EmitSound(table.Random(v), 80, 100)
ply.nextSpeechSound = CurTime() + GAMEMODE.Config.chatsoundsdelay -- make sure they don't spam HAX HAX HAX, if the server owner so desires
hook.Call("onChatSound", nil, ply, k, text)
break
end
end
end
hook.Add("PostPlayerSay", "ChatSounds", CheckChat)
DarkRP.get
Youre not even checking if the player is a cop.
You also dont need the hook call and neither the hookStub thing, nor the last function.
Also, inside that table at the start you have to remove the sounds text before each [command] and change the table in the checkchat function wich is beeing looped through, so instead of sounds it would be Sounds.
You just completly ignored the code i gave you.
Congratulations
I did with the code you gave me :
[code]
local sounds = {
[ "404" ] = { "npc/metropolice/vo/possible404here.wav" }
[ "505" ] = { "npc/metropolice/vo/subjectis505.wav" }
[ "citoyen" ] = { "npc/metropolice/vo/citizen.wav" }
[ "code 100" ] = { "npc/metropolice/vo/code100.wav" }
[ "recherche de suspect" ] = { "npc/metropolice/hiding02.wav" }
[ "bloquer"] = { "npc/metropolice/vo/lock.wav" }
[ "isolez" ] = { "npc/metropolice/vo/isolate.wav" }
[ "appliquer" ] = { "npc/metropolice/takedown.wav" }
[ "zone 404" ] = { "npc/metropolice/vo/404zone.wav" }
[ "visuel" ] = { "npc/metropolice/vo/acquiringonvisual.wav" }
[ "administrer" ] = { "npc/metropolice/vo/administer.wav" }
[ "affirmative" ] = { "npc/metropolice/vo/affirmative.wav" }
[ "Ghost patrouille aerienne 505" ] = { "npc/metropolice/vo/airwatchsubjectis505.wav" }
[ "circulez" ] = { "npc/metropolice/vo/allrightyoucango.wav" }
[ "tous sur le suspect" ] = { "npc/metropolice/vo/allun" }
[ "allez au qg" ] = { "npc/metropolice/vo/allunitsmovein.wav" }
[ "localisez le suspect" ] = { "npc/metropolice/vo/allunitsreportlocationsuspect.wav" }
[ "amputez" ] = { "npc/metropolice/vo/amputate.wav" }
[ "anti citoyen" ] = { "npc/metropolice/vo/anticitizen.wav" }
[ "urgence code 2" ] = { "npc/metropolice/vo/allunitscode2.wav" }
[ "34s dans" ] = { "npc/metropolice/vo/allunitsbol34sat.wav" }
[ "anti citoyen libre" ] = { "npc/metropolice/vo/anyonepickup647e.wav" }
[ "appliquer" ] = { "npc/metropolice/vo/apply.wav" }
[ "pdc" ] = { "npc/metropolice/vo/atcheckpoint.wav" }
[ "insectes" ] = { "npc/metropolice/vo/bugs.wav"}
[ "insectes libre" ] = { "npc/metropolice/vo/bugsontheloose.wav" }
[ "channel" ] = { "npc/metropolice/vo/canal.wav" }
[ "bip" ] = { "npc/metropolice/vo/catchthatbliponstabilization.wav"}
}
hook.Add("PlayerSay", "ChatSoundsForCP", function(ply, text)
local prefix = string.sub(text, 0, 1)
if prefix == "/" or prefix == "!" or prefix == "@" then return end
if not ply:IsCP() then return end
for k, v in pairs(sounds) do
local res1, res2 = string.find(string.lower(text), k)
if res1 and (not text[res1 - 1] or text[res1 - 1] == "" or text[res1 - 1] == " ") and (not text[res2 + 1] or text[res2 + 1] == "" or text[res2 + 1] == " ") then
ply:EmitSound(table.Random(v), 80, 100)
break
end
end
end)
[/code]
And it's not working
Why do you have a ton of subtables that only have one value???
[QUOTE=MPan1;48872086]Why do you have a ton of subtables that only have one value???[/QUOTE]
For various sounds to be added, but he only adds one.
[editline]10th October 2015[/editline]
[QUOTE=benji131201;48871922]I did with the code you gave me :
[code]
local sounds = {
[ "404" ] = { "npc/metropolice/vo/possible404here.wav" }
[ "505" ] = { "npc/metropolice/vo/subjectis505.wav" }
[ "citoyen" ] = { "npc/metropolice/vo/citizen.wav" }
[ "code 100" ] = { "npc/metropolice/vo/code100.wav" }
[ "recherche de suspect" ] = { "npc/metropolice/hiding02.wav" }
[ "bloquer"] = { "npc/metropolice/vo/lock.wav" }
[ "isolez" ] = { "npc/metropolice/vo/isolate.wav" }
[ "appliquer" ] = { "npc/metropolice/takedown.wav" }
[ "zone 404" ] = { "npc/metropolice/vo/404zone.wav" }
[ "visuel" ] = { "npc/metropolice/vo/acquiringonvisual.wav" }
[ "administrer" ] = { "npc/metropolice/vo/administer.wav" }
[ "affirmative" ] = { "npc/metropolice/vo/affirmative.wav" }
[ "Ghost patrouille aerienne 505" ] = { "npc/metropolice/vo/airwatchsubjectis505.wav" }
[ "circulez" ] = { "npc/metropolice/vo/allrightyoucango.wav" }
[ "tous sur le suspect" ] = { "npc/metropolice/vo/allun" }
[ "allez au qg" ] = { "npc/metropolice/vo/allunitsmovein.wav" }
[ "localisez le suspect" ] = { "npc/metropolice/vo/allunitsreportlocationsuspect.wav" }
[ "amputez" ] = { "npc/metropolice/vo/amputate.wav" }
[ "anti citoyen" ] = { "npc/metropolice/vo/anticitizen.wav" }
[ "urgence code 2" ] = { "npc/metropolice/vo/allunitscode2.wav" }
[ "34s dans" ] = { "npc/metropolice/vo/allunitsbol34sat.wav" }
[ "anti citoyen libre" ] = { "npc/metropolice/vo/anyonepickup647e.wav" }
[ "appliquer" ] = { "npc/metropolice/vo/apply.wav" }
[ "pdc" ] = { "npc/metropolice/vo/atcheckpoint.wav" }
[ "insectes" ] = { "npc/metropolice/vo/bugs.wav"}
[ "insectes libre" ] = { "npc/metropolice/vo/bugsontheloose.wav" }
[ "channel" ] = { "npc/metropolice/vo/canal.wav" }
[ "bip" ] = { "npc/metropolice/vo/catchthatbliponstabilization.wav"}
}
hook.Add("PlayerSay", "ChatSoundsForCP", function(ply, text)
local prefix = string.sub(text, 0, 1)
if prefix == "/" or prefix == "!" or prefix == "@" then return end
if not ply:IsCP() then return end
for k, v in pairs(sounds) do
local res1, res2 = string.find(string.lower(text), k)
if res1 and (not text[res1 - 1] or text[res1 - 1] == "" or text[res1 - 1] == " ") and (not text[res2 + 1] or text[res2 + 1] == "" or text[res2 + 1] == " ") then
ply:EmitSound(table.Random(v), 80, 100)
break
end
end
end)
[/code]
And it's not working[/QUOTE]
Where are you putting that and what gamemode are you on
I'm on darkRP and I put this in gamemode/darkrp/gamemode/modules/chatsounds.lua
[QUOTE=benji131201;48872130]I'm on darkRP and I put this in gamemode/darkrp/gamemode/modules/chatsounds.lua[/QUOTE]
Try putting it in lua/autorun/server.
And do not replace nor change nothing on that module
still not working
Try putting prints in there to check the code
[editline]10th October 2015[/editline]
To check what is failing
sorry I'm a beginner in lua how do you do this ?
After each if or something you want to check for you just got to put print("test1"), etc
nothing appears
[QUOTE=benji131201;48873180]nothing appears[/QUOTE]
If he is running this on a server then nothing is going to appear because you can't see server side output on your console.
benji what host are you using? Do they have a server console?
I'm using MTXServ and yes they have a server console
[QUOTE=benji131201;48873247]I'm using MTXServ and yes they have a server console[/QUOTE]
Check in the servers console then.
The code with prints would just be:
[CODE]
local sounds = {
[ "404" ] = { "npc/metropolice/vo/possible404here.wav" },
[ "505" ] = { "npc/metropolice/vo/subjectis505.wav" },
[ "citoyen" ] = { "npc/metropolice/vo/citizen.wav" },
[ "code 100" ] = { "npc/metropolice/vo/code100.wav" },
[ "recherche de suspect" ] = { "npc/metropolice/hiding02.wav" },
[ "bloquer"] = { "npc/metropolice/vo/lock.wav" },
[ "isolez" ] = { "npc/metropolice/vo/isolate.wav" },
[ "appliquer" ] = { "npc/metropolice/takedown.wav" },
[ "zone 404" ] = { "npc/metropolice/vo/404zone.wav" },
[ "visuel" ] = { "npc/metropolice/vo/acquiringonvisual.wav" },
[ "administrer" ] = { "npc/metropolice/vo/administer.wav" },
[ "affirmative" ] = { "npc/metropolice/vo/affirmative.wav" },
[ "Ghost patrouille aerienne 505" ] = { "npc/metropolice/vo/airwatchsubjectis505.wav" },
[ "circulez" ] = { "npc/metropolice/vo/allrightyoucango.wav" },
[ "tous sur le suspect" ] = { "npc/metropolice/vo/allun" },
[ "allez au qg" ] = { "npc/metropolice/vo/allunitsmovein.wav" },
[ "localisez le suspect" ] = { "npc/metropolice/vo/allunitsreportlocationsuspect.wav" },
[ "amputez" ] = { "npc/metropolice/vo/amputate.wav" },
[ "anti citoyen" ] = { "npc/metropolice/vo/anticitizen.wav" },
[ "urgence code 2" ] = { "npc/metropolice/vo/allunitscode2.wav" },
[ "34s dans" ] = { "npc/metropolice/vo/allunitsbol34sat.wav" },
[ "anti citoyen libre" ] = { "npc/metropolice/vo/anyonepickup647e.wav" },
[ "appliquer" ] = { "npc/metropolice/vo/apply.wav" },
[ "pdc" ] = { "npc/metropolice/vo/atcheckpoint.wav" },
[ "insectes" ] = { "npc/metropolice/vo/bugs.wav"},
[ "insectes libre" ] = { "npc/metropolice/vo/bugsontheloose.wav" },
[ "channel" ] = { "npc/metropolice/vo/canal.wav" },
[ "bip" ] = { "npc/metropolice/vo/catchthatbliponstabilization.wav"}
}
hook.Add("PlayerSay", "ChatSoundsForCP", function(ply, text)
print("Test1")
local prefix = string.sub(text, 0, 1)
if prefix == "/" or prefix == "!" or prefix == "@" then return end
print("Test2")
if not ply:IsCP() then return end
print("Test3")
for k, v in pairs(sounds) do
local res1, res2 = string.find(string.lower(text), k)
if res1 and (not text[res1 - 1] or text[res1 - 1] == "" or text[res1 - 1] == " ") and (not text[res2 + 1] or text[res2 + 1] == "" or text[res2 + 1] == " ") then
print("Test4")
ply:EmitSound(table.Random(v), 80, 100)
break
end
end
end)
[/CODE]
Also, you were missing the commas
[editline]10th October 2015[/editline]
It will work now.
It just was the commas.
In a table, all the values, have to have a comma after them before the next value.
Next time be aware of the commas
The test 1 and Test 2 are working but not the Test 3 and Test 4 and I have this error :
[code]
Local file is overriding addon's file! gamemodes/darkrp/gamemode/modules/chatsounds.lua (DarkRP)
10/11/2015 10:40:19: Lua Error
[ERROR] gamemodes/darkrp/gamemode/modules/chatsounds.lua:37: attempt to call method 'IsCP' (a nil value)
1. v - gamemodes/darkrp/gamemode/modules/chatsounds.lua:37
2. unknown - gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua:138
[ERROR] gamemodes/darkrp/gamemode/modules/chatsounds.lua:37: attempt to call method 'IsCP' (a nil value)
1. v - gamemodes/darkrp/gamemode/modules/chatsounds.lua:37
2. unknown - gamemodes/darkrp/gamemode/modules/chat/sv_chat.lua:138
[/code]
Sorry, you need to Log In to post a reply to this thread.