Advertisement
sciaschi

darkrp

Dec 23rd, 2011
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.27 KB | None | 0 0
  1. local ChatCommands = {}
  2. function AddChatCommand(cmd, callback, prefixconst)
  3. for k,v in pairs(ChatCommands) do
  4. if cmd == v.cmd then return end
  5. end
  6. table.insert(ChatCommands, { cmd = cmd, callback = callback, prefixconst = prefixconst })
  7. end
  8.  
  9. local function PlayerChat(ply, text)
  10. DB.Log(ply:SteamName().." ("..ply:SteamID().."): "..text )
  11. local callback = ""
  12. local DoSayFunc
  13. for k, v in pairs(ChatCommands) do
  14. if string.lower(v.cmd) == string.Explode(" ", string.lower(text))[1] then
  15. callback, DoSayFunc = v.callback(ply, string.sub(text, string.len(v.cmd) + 2, string.len(text)))
  16. if callback == "" then
  17. return "", "" , DoSayFunc
  18. end
  19. text = string.sub(text, string.len(v.cmd) + 2, string.len(text)).. " "
  20. end
  21. end
  22. if callback ~= "" then callback = (callback or "").." " end
  23. return text, callback, DoSayFunc
  24. end
  25.  
  26. local function ActualDoSay(ply, text, callback)
  27. callback = callback or ""
  28. if text == "" then return "" end
  29. local col = team.GetColor(ply:Team())
  30. local col2 = Color(255,255,255,255)
  31. if not ply:Alive() then
  32. col2 = Color(255,200,200,255)
  33. col = col2
  34. end
  35.  
  36. if GetConVarNumber("alltalk") == 1 then
  37. for k,v in pairs(player.GetAll()) do
  38. TalkToPerson(v, col, callback..ply:Name(), col2, text, ply)
  39. end
  40. else
  41. TalkToRange(ply, callback..ply:Name(), text, 250)
  42. end
  43. return ""
  44. end
  45.  
  46. local otherhooks = {}
  47. function GM:PlayerSay(ply, text, teamonly, dead)
  48. local text2 = (teamonly and "" or "/g ") .. text
  49. local callback
  50.  
  51. for k,v in SortedPairs(otherhooks, false) do
  52. if type(v) == "function" then
  53. text2 = v(ply, text, teamonly, dead) or text2
  54. end
  55. end
  56.  
  57. text2, callback, DoSayFunc = PlayerChat(ply, text2)
  58. if tostring(text2) == " " then text2, callback = callback, text2 end
  59.  
  60. if isDedicatedServer() then
  61. ServerLog("\""..ply:Nick().."<"..ply:UserID()..">" .."<"..ply:SteamID()..">".."<"..team.GetName( ply:Team() )..">\" say \""..text.. "\"\n")
  62. end
  63.  
  64. if DoSayFunc then DoSayFunc(text2) return "" end
  65. text2 = ActualDoSay(ply, text2, callback)
  66. return ""
  67. end
  68.  
  69. hook.Add("InitPostEntity", "hatCommands", function()
  70. if not hook.GetTable().PlayerSay then return end
  71. for k,v in pairs(hook.GetTable().PlayerSay) do
  72. otherhooks[k] = v
  73. hook.Remove("PlayerSay", k)
  74. end
  75. for a,b in pairs(otherhooks) do
  76. if type(b) ~= "function" then
  77. otherhooks[a] = nil
  78. end
  79. end
  80. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement