Created
July 25, 2021 13:33
-
-
Save Earu/2aaeadc79bb91ced40076bbc68be48c0 to your computer and use it in GitHub Desktop.
POC for detecting native PlayerSay calls and fowarding them to EasyChat's own networking (only works in sandbox derived gamemodes).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--[[ | |
--------------------------------------------------------------------- | |
THIS ONLY WORKS IN SANDBOX, DARKRP DOES WEIRD STUFF WITH ITS | |
GAMEMODE PLAYERSAY HOOK SO IT WONT WORK (SAME WITH MURDER) | |
--------------------------------------------------------------------- | |
--]] | |
hook.Add("PostGamemodeLoaded", TAG, function() | |
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, ...) | |
if event_name == "PlayerSay" then | |
event_name = "ECPlayerSay" | |
end | |
hook.NativeAdd(event_name, ...) | |
end | |
hook.NativeCall = hook.NativeCall or hook.Call | |
function hook.Call(event_name, ...) | |
if event_name == "PlayerSay" then | |
event_name = "ECPlayerSay" | |
end | |
return hook.NativeCall(event_name, ...) | |
end | |
-- handle messages that are run by the engine (usually the say or say_team commands) | |
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) | |
-- make the default behavior follow the gamemode PlayerSay one | |
function GAMEMODE:ECPlayerSay(ply, msg, is_team, is_local) | |
return self:PlayerSay(ply, msg, is_team, is_local) | |
end | |
end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment