mirror of
https://github.com/Earu/EasyChat.git
synced 2025-03-04 03:13:20 -05:00
hacks were necessary but this works
This commit is contained in:
parent
c2b2af928b
commit
c8d91723ac
@ -146,7 +146,12 @@ local function say_override(ply, msg, is_team, is_local)
|
||||
if #msg == 0 then return end
|
||||
|
||||
if SERVER then
|
||||
RunConsoleCommand(is_team and "sayteam" or "say", msg)
|
||||
if not IsValid(ply) then
|
||||
RunConsoleCommand(is_team and "sayteam" or "say", msg)
|
||||
return
|
||||
end
|
||||
|
||||
EasyChat.ReceiveGlobalMessage(ply, msg, is_team or false, is_local or false)
|
||||
end
|
||||
|
||||
if CLIENT then
|
||||
@ -228,10 +233,8 @@ if SERVER then
|
||||
end
|
||||
|
||||
function EasyChat.SendGlobalMessage(ply, str, is_team, is_local)
|
||||
_G.EC_PLAYER_SAY_CALL = true
|
||||
local msg = safe_hook_run("PlayerSay", ply, str, is_team, is_local)
|
||||
_G.EC_PLAYER_SAY_CALL = false
|
||||
|
||||
-- we run our own hook because we use the original PlayerSay to detect native source calls
|
||||
local msg = safe_hook_run("ECPlayerSay", ply, str, is_team, is_local)
|
||||
if type(msg) ~= "string" then return end
|
||||
|
||||
msg = EasyChat.ExtendedStringTrim(msg)
|
||||
|
@ -1,21 +1,35 @@
|
||||
local TAG = "EasyChatEngineChatHack"
|
||||
|
||||
if SERVER then
|
||||
local existing_callbacks = hook.GetTable().PlayerSay or {}
|
||||
for identifier, callback in pairs(existing_callbacks) do
|
||||
hook.Remove("PlayerSay", identifier)
|
||||
hook.Add("ECPlayerSay", identifier, callback)
|
||||
end
|
||||
|
||||
hook.NativeAdd = hook.NativeAdd or hook.Add
|
||||
function hook.Add(event_name, identifier, callback)
|
||||
if event_name == "PlayerSay" then
|
||||
event_name = "ECPlayerSay"
|
||||
end
|
||||
|
||||
hook.NativeAdd(event_name, identifier, callback)
|
||||
end
|
||||
|
||||
-- handle messages that are run by the engine (usually the say or sayteam commands)
|
||||
hook.Add("PlayerSay", TAG, function(ply, msg, is_team, is_local)
|
||||
if _G.EC_PLAYER_SAY_CALL then return end
|
||||
hook.NativeAdd("PlayerSay", TAG, function(ply, msg, is_team, is_local)
|
||||
if not IsValid(ply) then return end -- for console just let source handle it I guess
|
||||
|
||||
EasyChat.ReceiveGlobalMessage(ply, msg, is_team, is_local or false)
|
||||
return "" -- we handled it dont network it back the source way
|
||||
end)
|
||||
|
||||
local PLY = FindMetaTable("Player")
|
||||
PLY.old_Say = PLY.old_Say or PLY.Say
|
||||
|
||||
function PLY:Say(msg, is_team, is_local)
|
||||
EasyChat.ReceiveGlobalMessage(self, msg, is_team, is_local)
|
||||
end
|
||||
-- make the default behavior follow the gamemode PlayerSay one
|
||||
hook.Add("PostGamemodeLoaded", TAG, function()
|
||||
function GAMEMODE:ECPlayerSay(ply, msg, is_team, is_local)
|
||||
return self:PlayerSay(ply, msg, is_team, is_local)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- this is inspired off
|
||||
|
Loading…
Reference in New Issue
Block a user