Log in

View Full Version : Berserker/Mastermind etc Potion Drinker. With small HUD.



kamilqq
03-18-2016, 09:51 PM
Hello i'd like to share with my code, its poorly written as most of my scripts.
I wrote it because my friends asked me for.
It need some more features but i dont feel like doin' this.
Here is a screenshot of hud. ( poor as fuck :D ).
13389
And here is the code.

--[[
#Config:
['ID'] = id of potion to use over time.
['Lasts'] = time in seconds -> how much your potion lasts.
['Backpack'] = backpack contains your potions.
]]--
local extraPotion = {['ID'] = Item.GetID('berserk potion'), ['Lasts'] = 10 * 60, ['Backpack'] = 'golden backpack'}

--[[
____ ___ _ _ _____ _____ ____ ___ _____ ____ _____ _ _____ __
| _ \ / _ \| \ | |_ _| | ____| _ \_ _|_ _| | __ )| ____| | / _ \ \ / /
| | | | | | | \| | | | | _| | | | | | | | | _ \| _| | | | | | \ \ /\ / /
| |_| | |_| | |\ | | | | |___| |_| | | | | | |_) | |___| |__| |_| |\ V V /
|____/ \___/|_| \_| |_| |_____|____/___| |_| |____/|_____|_____\___/ \_/\_/
]]--
local lastsMinutes = extraPotion['Lasts'] / 60 >= 1 and math.floor(extraPotion['Lasts'] / 60) or 0
local lastsSeconds = lastsMinutes >= 1 and extraPotion['Lasts'] - (lastsMinutes * 60) or extraPotion['Lasts']
local extraPotionTimer = 0
local bp = Container.New(extraPotion['Backpack'])
local minutes, seconds = 0, 0
local function drinkExtraPotion()
if os.difftime(os.time(), extraPotionTimer) >= extraPotion['Lasts'] then
local tmpExtraPotion = bp:CountItemsOfID(extraPotion['ID'])
for slot, item in bp:iItems() do
if item.id == extraPotion['ID'] then
bp:UseItem(slot)
wait(Self.Ping() + 15)
if bp:CountItemsOfID(extraPotion['ID']) <= tmpExtraPotion - 1 then
extraPotionTimer = os.time()
else
return drinkExtraPotion()
end
end
end
end
end

local HUD = {
extraPotionInfo = HUD.New(10, 365, Item.GetName(extraPotion['ID']), 255, 255, 255),
extraPotionTime = HUD.New(140, 365, "00:00:00", 0, 255, 0),

extraPotionExpiredInfo = HUD.New(10, 380, "Potion expires at : ", 255, 255, 255),
extraPotionExpiredTime = HUD.New(140, 380, string.format("%02.f", lastsMinutes) .. " : " .. string.format("%02.f", lastsSeconds), 255, 0, 0)
}

Module.New('extraPotionDrinker', function(this)
drinkExtraPotion()
minutes = os.difftime(os.time(), extraPotionTimer) % 60 == 0 and os.difftime(os.time(), extraPotionTimer) / 60 or minutes
seconds = os.difftime(os.time(), extraPotionTimer) >= 60 and os.difftime(os.time(), extraPotionTimer) - minutes * 60 or os.difftime(os.time(), extraPotionTimer)
HUD.extraPotionTime:SetText(string.format("%02.f", minutes) .. " : " .. string.format("%02.f", seconds))
end)



Maybe some1 will use it. :P