Advertisement
Guest User

Untitled

a guest
Jun 11th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.67 KB | None | 0 0
  1. PLUGIN.Title = "Looter checker"
  2. PLUGIN.Description = "Plugin that will help you detect who looted where you are standing at."
  3. PLUGIN.Author = "Reneb"
  4. PLUGIN.Version = "1.5.1"
  5.  
  6. local DateTime
  7. local GetPlayersLooting, SetPlayersLooting = typesystem.GetField( Rust.Inventory, "_netListeners", bf.private_instance )
  8. function PLUGIN:Init()
  9. self.oxminPlugin = cs.findplugin("oxmin")
  10. self.ucontrolPlugin = cs.findplugin("ucontrol")
  11. self.FlagsPlugin = cs.findplugin("flags")
  12. if (self.oxminPlugin) then
  13. self.DepPlugin = self.oxminPlugin
  14. elseif (self.ucontrolPlugin) then
  15. if(self.FlagsPlugin) then
  16. self.DepPlugin = self.oxminPlugin
  17. end
  18. end
  19. if(not self.DepPlugin) then
  20. error("Nor Oxmin nor uControl were found, please download at least one to make this plugin work")
  21. return
  22. end
  23. self:AddChatCommand("looter",self.cmdLooter)
  24. self.Looter = {}
  25. DateTime = System.DateTime.Now:ToString("dd-MM")
  26. self.DataFile = util.GetDatafile("looter - " .. DateTime )
  27. local txt = self.DataFile:GetText()
  28. if (txt ~= "") then
  29. self.Looter = json.decode( txt )
  30. else
  31. self.Looter = {}
  32. end
  33. self.Timer = timer.Once( 600, function() self:Saver() end )
  34. self.LastLooters = {}
  35. end
  36. function PLUGIN:Saver()
  37. self:Save()
  38. if(DateTime ~= System.DateTime.Now:ToString("dd-MM")) then
  39. DateTime = System.DateTime.Now:ToString("dd-MM")
  40. self.DataFile = util.GetDatafile("looter - " .. DateTime )
  41. local txt = self.DataFile:GetText()
  42. if (txt ~= "") then
  43. self.Looter = json.decode( txt )
  44. else
  45. self.Looter = {}
  46. end
  47. end
  48. if(self.Timer) then self.Timer:Destroy() end
  49. self.Timer = timer.Once( 600, function() self:Saver() end )
  50. end
  51. function PLUGIN:Unload()
  52. self:Save()
  53. if (self.Timer) then
  54. self.Timer:Destroy()
  55. end
  56. end
  57. function PLUGIN:OnItemRemoved(inventory, slot, item)
  58. local iid2 = inventory.name
  59. if (iid2 == "WoodBoxLarge(Clone)" or iid2 == "WoodBox(Clone)" or iid2 == "SmallStash(Clone)") then
  60. local hashset = GetPlayersLooting( inventory )
  61. local it = hashset:GetEnumerator()
  62. local netuser = false
  63. while (it:MoveNext()) do
  64. local networkplayer = it.Current
  65. netuser = networkplayer:GetLocalData()
  66. end
  67. if(netuser and netuser.playerClient) then
  68. self:RegisterLoot(netuser)
  69. end
  70. end
  71. end
  72. function PLUGIN:RegisterLoot(netuser)
  73. local loc = netuser.playerClient.lastKnownPosition
  74. local x = tostring(math.floor(loc.x))
  75. local z = tostring(math.floor(loc.z))
  76. local userid = tostring(rust.GetUserID(netuser))
  77. if(not self.Looter[x]) then self.Looter[x] = {} end
  78. if(not self.Looter[x][z]) then self.Looter[x][z] = {} end
  79. if(not self.Looter[x][z][userid]) then self.Looter[x][z][userid] = tostring(util.GetTime()) end
  80. end
  81. function inRadius(pos,invpos,rad)
  82. if(pos.x < invpos.x + rad and pos.x > invpos.x - rad and pos.z < invpos.z + rad and pos.z > invpos.z - rad) then
  83. return true
  84. end
  85. return false
  86. end
  87. function PLUGIN:isAdmin(netuser)
  88. if(netuser:CanAdmin()) then return true end
  89. if(self.oxminPlugin and self.oxminPlugin:HasFlag( netuser, 3 )) then return true end
  90. if(self.ucontrolPlugin and self.FlagsPlugin and self.FlagsPlugin:HasFlag(tostring( rust.GetLongUserID(netuser) ), "cancheck" )) then return true end
  91. return false
  92. end
  93. function PLUGIN:cmdLooter(netuser,cmd,args)
  94. if(not self:isAdmin(netuser)) then
  95. rust.Notice( netuser, "You are not allowed to use this command")
  96. return
  97. end
  98. local radius
  99. if(not(args[1])) then
  100. radius = 1
  101. else
  102. radius = tonumber(args[1])
  103. end
  104. if(radius >= 50) then
  105. rust.SendChatToUser( netuser, "SERVER CONSOLE", "Mother of gods!!! Don't use radiuses SO big, it will make your server lag!!")
  106. end
  107. if(not(args[2])) then
  108. self.Looterc = self.Looter
  109. else
  110. local day = false
  111. if(string.sub(args[2],3,3) ~= "-") then
  112. rust.SendChatToUser( netuser, "SERVER CONSOLE", "Invalid argument, format: /looter RADIUS DD-MM")
  113. return
  114. end
  115. if(tonumber(string.sub(args[2],1,2)) <= 31 and tonumber(string.sub(args[2],1,2)) >= 1) then
  116. day = tonumber(string.sub(args[2],1,2))
  117. end
  118. local month = false
  119. if(tonumber(string.sub(args[2],4,5)) <= 12 and tonumber(string.sub(args[2],4,5)) >= 1) then
  120. month = tonumber(string.sub(args[2],4,5))
  121. end
  122. if(not day) then
  123. rust.SendChatToUser( netuser, "SERVER CONSOLE", "Invalid argument, format: /looter RADIUS DD-MM")
  124. return
  125. end
  126. if(not month) then
  127. rust.SendChatToUser( netuser, "SERVER CONSOLE", "Invalid argument, format: /looter RADIUS DD-MM")
  128. return
  129. end
  130. self.CheckFile = util.GetDatafile("looter - " .. string.sub(args[2],1,2) .. "-" .. string.sub(args[2],4,5) )
  131. local txt = self.CheckFile:GetText()
  132. if (txt ~= "") then
  133. self.Looterc = json.decode( txt )
  134. else
  135. self.Looterc = {}
  136. end
  137. end
  138. local loc = netuser.playerClient.lastKnownPosition
  139. local xrad = 0
  140. local zrad = 0
  141. local yrad = 0
  142. local tbl = {}
  143. local currenttime = util.GetTime()
  144. for i=-radius, radius*2 do
  145. xrad = tostring(math.floor(loc.x + i))
  146. if(self.Looterc[xrad]) then
  147. for o=-radius,radius*2 do
  148. zrad = tostring(math.floor(loc.z + o))
  149. if(self.Looterc[xrad][zrad]) then
  150. for k,v in pairs(self.Looterc[xrad][zrad]) do
  151. if(not tbl[k]) then
  152. local userdata = self.DepPlugin:GetUserDataFromID( k )
  153. if(userdata) and (userdata.Name) and (userdata.Name ~= nil) then
  154. tbl[k] = userdata.Name
  155. else
  156. tbl[k] = "Unknown"
  157. end
  158. end
  159. rust.SendChatToUser( netuser, "SERVER CONSOLE", "x:".. xrad .. " z:" .. zrad .. " Looter name: '" .. tbl[k] .."' Time: " .. (currenttime - tonumber(v)) .. "s ago" )
  160. end
  161. end
  162. end
  163. end
  164. end
  165. end
  166. function PLUGIN:Save()
  167. self.DataFile:SetText( json.encode( self.Looter ) )
  168. self.DataFile:Save()
  169. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement