Advertisement
it300

Log

Oct 26th, 2016
435
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.29 KB | None | 0 0
  1.  
  2. -- Custom Logging
  3. -- SAPP Compatability: 9.8+
  4. -- Script by: Skylace aka Devieth
  5. -- Discord: https://discord.gg/Mxmuxgm
  6.  
  7. api_version = "1.10.0.0"
  8.  
  9. function OnScriptLoad()
  10.     register_callback(cb['EVENT_JOIN'], "OnEventJoin")
  11.     register_callback(cb['EVENT_LEAVE'], "OnEventLeave")
  12.     register_callback(cb['EVENT_CHAT'], "OnEventChat")
  13.     register_callback(cb['EVENT_COMMAND'], "OnCommand")
  14. end
  15.  
  16. function OnScriptUnload() end
  17.  
  18. function OnEventJoin(PlayerIndex)
  19.     ChatCommand(PlayerIndex, nil, "Join", 1)
  20. end
  21.  
  22. function OnEventLeave(PlayerIndex)
  23.     ChatCommand(PlayerIndex, nil, "Join", 0)
  24. end
  25.  
  26. function OnEventChat(PlayerIndex, Message)
  27.     ChatCommand(PlayerIndex, Message, "Chat")
  28. end
  29.  
  30. function OnCommand(PlayerIndex, Command, Enviroment, Password)
  31.     ChatCommand(PlayerIndex, Command, "Cmd")
  32. end
  33.  
  34. function ChatCommand(PlayerIndex, Message, Enviroment, Extra)
  35.     log_message = nil
  36.     if tonumber(PlayerIndex) ~= 0 then
  37.         if player_present(PlayerIndex) then
  38.             local name = get_var(PlayerIndex, "$name")
  39.             local hash = get_var(PlayerIndex, "$hash")
  40.             local ip = get_var(PlayerIndex, "$ip")
  41.             if Enviroment == "Chat" then
  42.                 log_message = string.format("%s: %s", name, Message)
  43.             elseif Enviroment == "Cmd"  then
  44.                 log_message = string.format("Admin: %s\tName: %s\tCommand: %s\tIP: %s\tHash: %s", isadmin(PlayerIndex), name, Message, ip, hash)
  45.             elseif Enviroment == "Join" then
  46.                 if Extra == 1 then
  47.                     log_message = string.format("%s joined the server.\tIP: %s\tHash: %s", name, ip, hash)
  48.                 else
  49.                     log_message = string.format("%s left the server.", name)
  50.                 end
  51.             end
  52.         end
  53.     end
  54.     if log_message ~= nil then
  55.         Writelog(Enviroment.."Log.txt",log_message)
  56.     end
  57. end
  58.  
  59. function Writelog(filename, value)
  60.     local path = read_string(0x5B9610) .. "\\logs\\"
  61.     if not folder(path) then os.execute("mkdir "..path) end
  62.     local file = io.open(path .. (os.date("%Y-%m-%d_")) .. filename, "a")
  63.     if file then
  64.         local line = string.format("%s\t%s\n", os.date("%H:%M:%S"), tostring(value))
  65.         file:write(line)
  66.         file:close()
  67.     end
  68. end
  69.  
  70. function isadmin(PlayerIndex)
  71.     local lvl = get_var(PlayerIndex, "$lvl")
  72.     if lvl ~= "-1" then
  73.         return true
  74.     end
  75.     return false
  76. end
  77.  
  78. function folder(path)
  79.     local f  = os.execute("cd " .. path)
  80.     if f ~= 1 then
  81.         return true
  82.     else
  83.         return false
  84.     end
  85. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement