Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PLUGIN.Title = "Looter checker"
- PLUGIN.Description = "Plugin that will help you detect who looted where you are standing at."
- PLUGIN.Author = "Reneb"
- PLUGIN.Version = "1.5.1"
- local DateTime
- local GetPlayersLooting, SetPlayersLooting = typesystem.GetField( Rust.Inventory, "_netListeners", bf.private_instance )
- function PLUGIN:Init()
- self.oxminPlugin = cs.findplugin("oxmin")
- self.ucontrolPlugin = cs.findplugin("ucontrol")
- self.FlagsPlugin = cs.findplugin("flags")
- if (self.oxminPlugin) then
- self.DepPlugin = self.oxminPlugin
- elseif (self.ucontrolPlugin) then
- if(self.FlagsPlugin) then
- self.DepPlugin = self.oxminPlugin
- end
- end
- if(not self.DepPlugin) then
- error("Nor Oxmin nor uControl were found, please download at least one to make this plugin work")
- return
- end
- self:AddChatCommand("looter",self.cmdLooter)
- self.Looter = {}
- DateTime = System.DateTime.Now:ToString("dd-MM")
- self.DataFile = util.GetDatafile("looter - " .. DateTime )
- local txt = self.DataFile:GetText()
- if (txt ~= "") then
- self.Looter = json.decode( txt )
- else
- self.Looter = {}
- end
- self.Timer = timer.Once( 600, function() self:Saver() end )
- self.LastLooters = {}
- end
- function PLUGIN:Saver()
- self:Save()
- if(DateTime ~= System.DateTime.Now:ToString("dd-MM")) then
- DateTime = System.DateTime.Now:ToString("dd-MM")
- self.DataFile = util.GetDatafile("looter - " .. DateTime )
- local txt = self.DataFile:GetText()
- if (txt ~= "") then
- self.Looter = json.decode( txt )
- else
- self.Looter = {}
- end
- end
- if(self.Timer) then self.Timer:Destroy() end
- self.Timer = timer.Once( 600, function() self:Saver() end )
- end
- function PLUGIN:Unload()
- self:Save()
- if (self.Timer) then
- self.Timer:Destroy()
- end
- end
- function PLUGIN:OnItemRemoved(inventory, slot, item)
- local iid2 = inventory.name
- if (iid2 == "WoodBoxLarge(Clone)" or iid2 == "WoodBox(Clone)" or iid2 == "SmallStash(Clone)") then
- local hashset = GetPlayersLooting( inventory )
- local it = hashset:GetEnumerator()
- local netuser = false
- while (it:MoveNext()) do
- local networkplayer = it.Current
- netuser = networkplayer:GetLocalData()
- end
- if(netuser and netuser.playerClient) then
- self:RegisterLoot(netuser)
- end
- end
- end
- function PLUGIN:RegisterLoot(netuser)
- local loc = netuser.playerClient.lastKnownPosition
- local x = tostring(math.floor(loc.x))
- local z = tostring(math.floor(loc.z))
- local userid = tostring(rust.GetUserID(netuser))
- if(not self.Looter[x]) then self.Looter[x] = {} end
- if(not self.Looter[x][z]) then self.Looter[x][z] = {} end
- if(not self.Looter[x][z][userid]) then self.Looter[x][z][userid] = tostring(util.GetTime()) end
- end
- function inRadius(pos,invpos,rad)
- 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
- return true
- end
- return false
- end
- function PLUGIN:isAdmin(netuser)
- if(netuser:CanAdmin()) then return true end
- if(self.oxminPlugin and self.oxminPlugin:HasFlag( netuser, 3 )) then return true end
- if(self.ucontrolPlugin and self.FlagsPlugin and self.FlagsPlugin:HasFlag(tostring( rust.GetLongUserID(netuser) ), "cancheck" )) then return true end
- return false
- end
- function PLUGIN:cmdLooter(netuser,cmd,args)
- if(not self:isAdmin(netuser)) then
- rust.Notice( netuser, "You are not allowed to use this command")
- return
- end
- local radius
- if(not(args[1])) then
- radius = 1
- else
- radius = tonumber(args[1])
- end
- if(radius >= 50) then
- rust.SendChatToUser( netuser, "SERVER CONSOLE", "Mother of gods!!! Don't use radiuses SO big, it will make your server lag!!")
- end
- if(not(args[2])) then
- self.Looterc = self.Looter
- else
- local day = false
- if(string.sub(args[2],3,3) ~= "-") then
- rust.SendChatToUser( netuser, "SERVER CONSOLE", "Invalid argument, format: /looter RADIUS DD-MM")
- return
- end
- if(tonumber(string.sub(args[2],1,2)) <= 31 and tonumber(string.sub(args[2],1,2)) >= 1) then
- day = tonumber(string.sub(args[2],1,2))
- end
- local month = false
- if(tonumber(string.sub(args[2],4,5)) <= 12 and tonumber(string.sub(args[2],4,5)) >= 1) then
- month = tonumber(string.sub(args[2],4,5))
- end
- if(not day) then
- rust.SendChatToUser( netuser, "SERVER CONSOLE", "Invalid argument, format: /looter RADIUS DD-MM")
- return
- end
- if(not month) then
- rust.SendChatToUser( netuser, "SERVER CONSOLE", "Invalid argument, format: /looter RADIUS DD-MM")
- return
- end
- self.CheckFile = util.GetDatafile("looter - " .. string.sub(args[2],1,2) .. "-" .. string.sub(args[2],4,5) )
- local txt = self.CheckFile:GetText()
- if (txt ~= "") then
- self.Looterc = json.decode( txt )
- else
- self.Looterc = {}
- end
- end
- local loc = netuser.playerClient.lastKnownPosition
- local xrad = 0
- local zrad = 0
- local yrad = 0
- local tbl = {}
- local currenttime = util.GetTime()
- for i=-radius, radius*2 do
- xrad = tostring(math.floor(loc.x + i))
- if(self.Looterc[xrad]) then
- for o=-radius,radius*2 do
- zrad = tostring(math.floor(loc.z + o))
- if(self.Looterc[xrad][zrad]) then
- for k,v in pairs(self.Looterc[xrad][zrad]) do
- if(not tbl[k]) then
- local userdata = self.DepPlugin:GetUserDataFromID( k )
- if(userdata) and (userdata.Name) and (userdata.Name ~= nil) then
- tbl[k] = userdata.Name
- else
- tbl[k] = "Unknown"
- end
- end
- rust.SendChatToUser( netuser, "SERVER CONSOLE", "x:".. xrad .. " z:" .. zrad .. " Looter name: '" .. tbl[k] .."' Time: " .. (currenttime - tonumber(v)) .. "s ago" )
- end
- end
- end
- end
- end
- end
- function PLUGIN:Save()
- self.DataFile:SetText( json.encode( self.Looter ) )
- self.DataFile:Save()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement