Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactored chat function calls, to get rid of duplicate code.

  • Loading branch information...
commit 499d9dedd18bea2f1eb168bafa89314e0a5412d4 1 parent 5c69323
@daranable authored
Showing with 32 additions and 38 deletions.
  1. +32 −38 lua/starfall/libs_sv/chat.lua
View
70 lua/starfall/libs_sv/chat.lua
@@ -12,44 +12,38 @@ local callbacks = {}
---------------------------------------------------------------------
hook.Add( "PlayerSay", "starfall_chat_receive", function( ply, msg, toall )
- local hidden
- local steamid = ply:SteamID()
- local wrapped_player = SF.Entities.Wrap(ply)
-
- for instance, tbl in pairs(callbacks) do
- for _, func in pairs(tbl.global) do
- local success, hide = pcall(
- instance.runFunction,
- instance,
- func,
- msg,
- wrapped_player
- )
-
- if success and hide and ply == instance.player then
- hidden = true
- end
- end
- for _, func in pairs(tbl[steamid]) do
- local success, hide = pcall(
- instance.runFunction,
- instance,
- func,
- msg,
- wrapped_player
- )
-
- if success and hide and ply == instance.player then
- hidden = true
- end
- end
- end
-
- if hidden then
- return ""
- else
- return msg
- end
+ local hidden
+ local steamid = ply:SteamID()
+ local wrapped_player = SF.Entities.Wrap(ply)
+
+ local function call_handler (instance, handler)
+ local success, hide = pcall(
+ instance.runFunction,
+ instance,
+ handler,
+ msg,
+ wrapped_player
+ )
+
+ if success and hide and ply == instance.player then
+ hidden = true
+ end
+ end
+
+ for instance, tbl in pairs(callbacks) do
+ for _, func in pairs(tbl.global) do
+ call_handler( instance, handler )
+ end
+ for _, func in pairs(tbl[steamid]) do
+ call_handler( instance, handler )
+ end
+ end
+
+ if hidden then
+ return ""
+ else
+ return msg
+ end
end)
SF.Libraries.AddHook( "deinitialize", function( instance )
Please sign in to comment.
Something went wrong with that request. Please try again.