For some reason two PlayerSay hooks are conflicting. It isn’t function GM:PlayerSay() thy use hook.Add, so it’s not that. My first function is for RangedChat, the second function is for ChatCommands. If I remove the RangedChat the ChatCommands works perfectly, just how it is suppose to. So I take away the first PlayerSay, and the other one works. Even if I change the order where the code is, which doesn’t matter really, but it still makes the ChatCommands not work. So I know it has to do something with the hook, not the function, but I can’t seem to find it out. If anyone knows why it’s doing this please help me, or maybe it’s just something fucked up with Garry’s Mod 13 and I should just wait?
can’t do anything without the relevant code
function PlayerChatCommands( ply, text )
local TableCommand = ChatCommands[string.lower( string.Explode( " ", text ) [1] )]
if TableCommand then
callback, DoSayFunc = TableCommand.callback( ply, string.sub(text, string.len( TableCommand.command ) + 2, string.len( text )))
return ""
elseif string.sub( text, 1, 1 ) == "/" and !TableCommand then
NotifyPerson( ply, Color(255, 0, 0), "Invalid command!" )
return ""
end
end
hook.Add( "PlayerSay", "PlayerChatCommands", PlayerChatCommands )
function RangedChat( ply, str )
if string == " " then return "" end
if !ply:Alive() then
NotifyPerson( ply, Color(255,0,0), "You can not talk when you're dead!" )
return ""
end
for k, v in pairs( player.GetAll() ) do
if ply:GetPos():Distance(v:GetPos()) < 500 then
NotifyPerson( ply, Color(230,220,130), ply:Name().." says \""..str.."\"" )
end
end
return ""
end
hook.Add( "PlayerSay", "RangedChat", RangedChat )
it will run them in order of when they are actually hooked.
ie if RangedChat is created first, it will be called first, thus making your other hook redundant unless it does something different like logging the chat.
i would advise merging the two hooks into 1.
You can have two hooks and have it works just fine. The problem is you’re returning an empty string in the RangedChat hook, which prevents any other hooks from being called after it.
But like G4MB!T said, you can merge them into one hook to solve all the problems.
Ah thanks guys, wouldn’t of guessed it was that. Replaced it with return false and it works all good now.
[editline]30th October 2012[/editline]
No, I lied.
use return “”
I just did this:
function RangedChat( ply, str )
if str == " " then return "" end
if string.sub( str, 1, 1 ) != "/" then
if ply:Alive() then
for k, v in pairs( player.GetAll() ) do
if ply:GetPos():Distance(v:GetPos()) < 500 then
NotifyPerson( ply, Color(230,220,130), ply:Name().." says \""..str.."\"" )
end
end
else
NotifyPerson( ply, Color(255,0,0), "You can not talk when you're dead!" )
end
return ""
end
end
hook.Add( "PlayerSay", "RangedChat", RangedChat )
[lua]
function RangedChat( ply, str )
if str == " " then return “” end
if string.sub( str, 1, 1 ) != "/" then
if ply:Alive() then
for k, v in pairs( player.GetAll() ) do
if ply:GetPos():Distance(v:GetPos()) < 500 then
NotifyPerson( ply, Color(230,220,130), ply:Name().." says \""..str.."\"" )
end
end
else
NotifyPerson( ply, Color(255,0,0), "You can not talk when you're dead!" )
end
end
return ""
end
hook.Add( “PlayerSay”, “RangedChat”, RangedChat )
[/lua]
That didn’t work, the one I did though.
Returning “” prevents the chat from being said, and stops other hooks from running
Returning nothing lets the other hooks take action.