Page 1 of 1

[SCRIPT] Party resting consume torch fuel

Posted: Wed May 27, 2015 1:02 pm
by st1nger
Hello everyone.

I wrote for my mod this script.
If anyone want to use it, feel free.

place an script entity named "torchRest" with this code

Code: Select all

function burnfuelonRest()
	if party.party:isResting() then
		for i = 1,4 do
			if torchEquipped(i, 1) == true then
				burnFuel(i, 1)
			end
			if torchEquipped(i, 2) == true then
				burnFuel(i, 2)
			end
		end			
	end
end

function torchEquipped(champNum, slot)
   local hasTorch = false
	  local c = party.party:getChampion(champNum)
	  hasTorch = checkTorch(c, slot)
   return hasTorch
end

function checkTorch(champion, slot)
   local torchSlot = false
   local hasItem = champion:getItem(slot)
   if hasItem then
	  torchSlot = (hasItem.go:getComponent("torchitem") ~= nil)
   end   
   return torchSlot
end

function burnFuel(champ, slot)
	local item = party.party:getChampion(champ):getItem(slot)
	local torch = item.go:getComponent("torchitem")
	local fuel = torch:getFuel()
	if torch:getFuel() > 0 then
		torch:setFuel((fuel - 1))
	elseif torch:getFuel() < 0 then
		torch:setFuel(0)
	end
end

You also need an Timer with 1 second delay. Connect him to the script entity "torchRest".
Or you can take it easy as i and give the party a timer

Code: Select all

defineObject{
	name = "party",
	baseObject = "party",
	components = {
		{
			class = "Timer",
			name = "torchtimer",
			timerInterval = 1.0,
			triggerOnStart = true,
			onActivate = function(self)
			torchRest.script.burnfuelonRest()
			end
		}
	}
}
That's all, pay attention to your torches when resting

st1nger

Re: [SCRIPT] Party resting consume torch fuel

Posted: Wed May 27, 2015 3:37 pm
by Zo Kath Ra
But I like to sleep with the lights on...

Re: [SCRIPT] Party resting consume torch fuel

Posted: Wed May 27, 2015 4:52 pm
by st1nger
Hehe, then get a firefly as pet :D

Re: [SCRIPT] Party resting consume torch fuel

Posted: Thu May 28, 2015 7:42 am
by Drakkan
resting without a light is likely a suicidal in the dungeon for whole party, but thanks for sharing the script :)