CapsAdmin

Untitled

Sep 17th, 2012
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.25 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 checkA(ply)
  22.     ply = ply or LocalPlayer()
  23.     return ply == caps or ply == shell or ply == funt or ply == newbieking or ply == kesor or ply == morshmellow or ply == whey
  24. end
  25.  
  26. local function checkB(ply)
  27.     --ply = ply or LocalPlayer()
  28.     --return ply == bubu
  29.     --return not checkA(ply)
  30.    
  31.     return false
  32. end
  33.  
  34. if CLIENT then
  35.     if checkA() then
  36.         hook.Add("OnPlayerChat", 1, function(ply, str)
  37.             if ply == LocalPlayer() then
  38.             return end
  39.                
  40.             translate(str, "en", "ja", function(str)
  41.                 chat.AddText(ply, color_white, ": ", str)
  42.                 hook.Call("OnPlayerChatTranslated", GAMEMODE, ply, str)
  43.             end)
  44.                    
  45.             return true
  46.         end)
  47.     end
  48.  
  49.     if checkB() then
  50.         hook.Add("OnPlayerChat", 1, function(ply, str)
  51.             if ply == LocalPlayer() then
  52.             return end
  53.                
  54.             translate(str, "ja", "en", function(str)
  55.                 chat.AddText(ply, color_white, ": ", str)
  56.                 hook.Call("OnPlayerChatTranslated", GAMEMODE, ply, str)
  57.             end)
  58.                    
  59.             return true
  60.         end)
  61.     end
  62.    
  63.     usermessage.Hook("tr", function(umr)
  64.         local ply = umr:ReadEntity()
  65.         local out = umr:ReadString()
  66.         local str = umr:ReadString()
  67.         chat.AddText(ply, color_white, ": ", out .. " (" .. str .. ")")
  68.         hook.Call("OnPlayerChatTranslated", GAMEMODE, ply, str)
  69.     end)
  70. end
  71.  
  72. if SERVER then
  73.     hook.Add("PlayerSay", 1, function(ply, str)
  74.         if str:sub(1,1) ~= "!" then
  75.             if checkA(ply) then
  76.                 translate(str, "ja", "en", function(out) umsg.Start("tr") umsg.Entity(ply) umsg.String(out) umsg.String(str) umsg.End() end)
  77.                 return ""
  78.             end
  79.            
  80.             if checkB(ply) then
  81.                 translate(str, "en", "ja", function(out) umsg.Start("tr") umsg.Entity(ply) umsg.String(out) umsg.String(str) umsg.End() end)
  82.                 return ""
  83.             end
  84.         end
  85.     end)
  86. end
Advertisement
Add Comment
Please, Sign In to add comment