Cider RP - Local Voice not working?

Hello, Me and my friend is working on a Cider RP, and we just fixed some minor bugs, then we ran into another, our Local voice did not work.
We hope some of you can help us with this huge bug?

Some of the code
[lua]
– sh_configuration.lua file!
cider.configuration[“Local Voice”] = true; – Players can only hear a player’s voice if they are near them.
cider.configuration[“Talk Radius”] = 256; – The radius of each player that other players have to be in to hear them talk (units).

– init.lua Line: 33
if (cider.configuration[“Local Voice”]) then
game.ConsoleCommand("sv_voiceenable 1
");
game.ConsoleCommand("sv_alltalk 1
");
game.ConsoleCommand("sv_voicecodec voice_speex
");
game.ConsoleCommand("sv_voicequality 5
");
end;

– cl_init.lua Line: 616
function GM:Think()
if ( cider.configuration[“Local Voice”] ) then
for k, v in pairs( player.GetAll() ) do
if ( hook.Call(“PlayerCanVoice”, GAMEMODE, v) ) then
if ( v:IsMuted() ) then v:SetMuted(); end;
else
if ( v:IsMuted() ) then v:SetMuted(); end;
end;
end;
end;

-- Call the base class function.
return self.BaseClass:Think();

end;
[/lua]

Could not find anymore, but if you do know a little thing about this please respond!! We are really lost in this section of lua!

Thanks.

**[Gamemode.PlayerCanHearPlayersVoice

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Gamemode.PlayerCanHearPlayersVoice)**

Could you be more descriptive? What i found was this
[lua]
function GM:PlayerCanHearPlayersVoice()
return true, true
end
[/lua]
How to intergrate that in to my coding?

Check their distance using ents.FindInSphere and return based off of if they’re close enough or not.

Example from base gamemode:
[lua]
–[[---------------------------------------------------------
Name: gamemode:PlayerCanHearPlayersVoice()
Can this player see the other player’s voice?
---------------------------------------------------------]]–
function GM:PlayerCanHearPlayersVoice( pListener, pTalker )

-- This is the default action.
-- Note - sv_alltalk 1 makes this hook irrelivant (everyone hears everyone)

return pListener:Team() == pTalker:Team()

end
[/lua]

If you can’t integrate that, you need more practise with basic stuff.

[lua]
local maxVoiceRange = 320;

function GM:PlayerCanHearPlayerVoice(listener, speaker)
local listenerPos = listener:GetPos();
local position = speaker:GetPos();
local distance = listenerPos:Distance(position);

 return distance <= maxVoiceRange;

end;
[/lua]

Ok I’ve tried some of your opinions, but i just can’t simply get it to work… I don’t know if Cider Roleplay just blocked it or whatever…
I’ve tried these in cl_init.lua and I’ve also tried them in init.lua
[lua]
function GM:PlayerCanHearPlayersVoice(list,speak)
if (list:GetShootPos():Distance(speak:GetShootPos()) < 320) then
return true;
end;
return false;
end;
[/lua]
I’ve also tried yours’, but nothing seems to work… I’ve tried remove all things in the lua files that might could have something to do with the Speech… I don’t know if i should do that… I have been fighting with this for some hours today…

Make sure sv_alltalk is 0.

I’ve check that.
If some could help me over teamviewer or skype, it would be more helpful :-I

  • I Don’t know if i need a hook? If so what should it be named…? :-S

EDIT:
This is all my coding i got now!

In cl_init.lua
[lua]
– Called to check if a player can use voice.
function GM:PlayerCanVoice(player)
if ( player:Alive()
and player:GetPos():Distance( LocalPlayer():GetPos() ) <= cider.configuration[“Talk Radius”]
and !player:GetNetworkedBool(“cider_Arrested”)
and !player:GetNetworkedBool(“cider_KnockedOut”) ) then
return true;
else
cider.player.notify(player, “GM:PCHPV failed!”, 1)
return false;
end;
end;

function GM:PlayerCanHearPlayersVoice(listener, speaker)
local listenerPos = listener:GetPos();
local position = speaker:GetPos();
local distance = listenerPos:Distance(position);

if (distance &lt;= cider.configuration["Talk Radius"] and speaker:Alive()) then
return true;
else
	if (!player:Alive() or player.cider._Arrested or player._KnockedOut) then
	cider.player.notify(speaker, "You cannot do that in this state!", 1);
	return false;
	end;
end;

end;

– Called every frame.
function GM:Think()
if ( cider.configuration[“Local Voice”] ) then
for k, v in pairs( player.GetAll() ) do
if ( hook.Call(“PlayerCanVoice”, GAMEMODE, v) ) then
return true;
else
return true;
end;
end;
end;

-- Call the base class function.
return self.BaseClass:Think();

end;
[/lua]

This is my coding in generic/sv_init.lua (This is where all the hook’s are)
[lua]
function PLUGIN.PlayerCanVoice(player)
if ( player:Alive()
and player:GetPos():Distance( LocalPlayer():GetPos() ) <= cider.configuration[“Talk Radius”]
and !player:GetNetworkedBool(“cider_Arrested”)
and !player:GetNetworkedBool(“cider_KnockedOut”) ) then
return true;
else
return false;
end;
end;

– ADD HOOK!
cider.hook.add(“PlayerCanVoice”, PLUGIN.PlayerCanVoice);
[/lua]
**
PS: I does not work still… HELP!
Note: This is all of the coding of Voice/Speech code.**

I read somewhere else that the second true if a fade. So if you do return true, true then it will fade as you get further away. I’ve never used it though.

Which true statement do you mean?

The second true in this bit of code.