[READ-ONLY] Mirror of https://github.com/thoda-dev/DualUniverse. DualUniverse scripts
0

Configure Feed

Select the types of activity you want to include in your feed.

fuel tanks metatable

Thomas (Jul 23, 2023, 4:23 PM +0200) bb53be65 f0d0e30b

+73
+67
ElementsMetatable/FuelTank.lua
··· 1 + --[[ 2 + Fuel Tanks Metatable By Jericho 3 + Version: 1.0.0 4 + Source available at: 5 + ]] 6 + FuelTank = { 7 + __index = { 8 + name = '', 9 + percentage = 0, 10 + timeLeft = 0, 11 + lastRefresh = 0, 12 + fuelType = 'rocket', 13 + refresh = function(self) 14 + local time = system.getUtcTime() 15 + if lastRefresh ~= time then --refresh only once by seconds 16 + local class = self.getClass():lower() 17 + if class:find('atmo') then 18 + self.fuelType = "atmo" 19 + elseif class:find('space') then 20 + self.fuelType = "space" 21 + end 22 + local jsondata = self.getWidgetData() 23 + local data = json.decode(jsondata) 24 + self.name = data.name 25 + self.percentage = data.percentage 26 + self.timeLeft = tonumber(data.timeLeft) 27 + self.lastRefresh = time 28 + end 29 + end, 30 + getName = function(self) 31 + self:refresh() 32 + return self.name 33 + end, 34 + getPercentFilled = function(self) 35 + self:refresh() 36 + return self.percentage 37 + end, 38 + getSecondsLeft = function(self) 39 + self:refresh() 40 + return self.timeLeft 41 + end, 42 + getFuelType = function(self) 43 + self:refresh() 44 + return self.fuelType 45 + end, 46 + getTimeLeftString = function (self) 47 + local seconds = self:getSecondsLeft() 48 + if seconds == nil or seconds <= 0 then 49 + return "-"; 50 + end 51 + days = string.format("%2.f", math.floor(seconds/(3600*24))); 52 + hours = string.format("%2.f", math.floor(seconds/3600 - (days*24))); 53 + mins = string.format("%2.f", math.floor(seconds/60 - (hours*60) - (days*24*60))); 54 + secs = string.format("%2.f", math.floor(seconds - hours*3600 - (days*24*60*60) - mins *60)); 55 + str = "" 56 + if tonumber(days) > 0 then str = str .. days.."d " end 57 + if tonumber(hours) > 0 then str = str .. hours.."h " end 58 + if tonumber(mins) > 0 then str = str .. mins.."m " end 59 + if tonumber(secs) > 0 then str = str .. secs .."s" end 60 + return str 61 + end, 62 + dump = function(self) 63 + self:refresh() 64 + system.print('{name="' .. self.name .. '",percentage=' .. self.percentage ..',timeLeft=' .. self.timeLeft .. ',fuelType="'.. self.fuelType ..'"}') 65 + end 66 + } 67 + }
+6
ElementsMetatable/FuelTank.min.lua
··· 1 + --[[ 2 + Fuel Tanks Metatable By Jericho 3 + Version: 1.0.0 4 + Unminified Source available at: https://github.com/Jericho1060/DualUniverse/blob/master/ElementMetatable/FuelTank.lua 5 + ]] 6 + FuelTank={__index={name='',percentage=0,timeLeft=0,lastRefresh=0,fuelType='rocket',refresh=function(self)local a=system.getUtcTime()if lastRefresh~=a then local b=self.getClass():lower()if b:find('atmo')then self.fuelType="atmo"elseif b:find('space')then self.fuelType="space"end;local c=self.getWidgetData()local d=json.decode(c)self.name=d.name;self.percentage=d.percentage;self.timeLeft=tonumber(d.timeLeft)self.lastRefresh=a end end,getName=function(self)self:refresh()return self.name end,getPercentFilled=function(self)self:refresh()return self.percentage end,getSecondsLeft=function(self)self:refresh()return self.timeLeft end,getFuelType=function(self)self:refresh()return self.fuelType end,getTimeLeftString=function(self)local e=self:getSecondsLeft()if e==nil or e<=0 then return"-"end;days=string.format("%2.f",math.floor(e/(3600*24)))hours=string.format("%2.f",math.floor(e/3600-days*24))mins=string.format("%2.f",math.floor(e/60-hours*60-days*24*60))secs=string.format("%2.f",math.floor(e-hours*3600-days*24*60*60-mins*60))str=""if tonumber(days)>0 then str=str..days.."d "end;if tonumber(hours)>0 then str=str..hours.."h "end;if tonumber(mins)>0 then str=str..mins.."m "end;if tonumber(secs)>0 then str=str..secs.."s"end;return str end,dump=function(self)self:refresh()system.print('{name="'..self.name..'",percentage='..self.percentage..',timeLeft='..self.timeLeft..',fuelType="'..self.fuelType..'"}')end}}