CapsAdmin

Untitled

Aug 30th, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. local function escape(s)
  2.     return string.gsub(s, "([^A-Za-z0-9_])", function(c)
  3.         return string.format("%%%02x", string.byte(c))
  4.     end)
  5. end
  6.  
  7. local function geturl(str, to, from)
  8.     from = from or "en"
  9.     assert(str)
  10.     assert(to)
  11.     return ("http://translate.google.com/translate_a/t?client=t&text=%s&sl=%s&tl=%s&ie=UTF-8&oe=UTF-8"):format(escape(str), from, to)
  12. end
  13.  
  14. local function translate(str, to, from, callback)
  15.     http.Get(geturl(str, to, from), "", function(data)
  16.         local res = data:match("%[%[%[\"(.-)\"")
  17.         callback(res)
  18.     end)
  19. end
  20.  
  21. local function check(ply)
  22.     ply = ply or LocalPlayer()
  23.     return ply == caps or ply == shell or ply == funt or ply == newbieking
  24. end
  25.  
  26. if CLIENT then
  27.     if check() then
  28.         hook.Add("OnPlayerChat", 1, function(ply, str)
  29.             if ply == LocalPlayer() then
  30.             return end
  31.                
  32.             translate(str, "en", "ja", function(str) chat.AddText(ply, color_white, ": ", str)  end)
  33.                    
  34.             return true
  35.         end)
  36.     end
  37.  
  38.     usermessage.Hook("tr", function(umr)
  39.         local ply = umr:ReadEntity()
  40.         local out = umr:ReadString()
  41.         local str = umr:ReadString()
  42.         chat.AddText(ply, color_white, ": ", out .. " (" .. str .. ")")
  43.     end)
  44. end
  45.  
  46. if SERVER then
  47.     hook.Add("PlayerSay", 1, function(ply, str)
  48.         if check(ply) and str:sub(1,1) ~= "!" then
  49.             translate(str, "ja", "en", function(out) umsg.Start("tr") umsg.Entity(ply) umsg.String(out) umsg.String(str) umsg.End() end)
  50.             return ""
  51.         end
  52.     end)
  53. end
Advertisement
Add Comment
Please, Sign In to add comment