[SCRIPT] Party resting consume torch fuel

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
Post Reply
User avatar
st1nger
Posts: 19
Joined: Wed May 29, 2013 8:44 pm
Location: Germany

[SCRIPT] Party resting consume torch fuel

Post 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
User avatar
Zo Kath Ra
Posts: 944
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: [SCRIPT] Party resting consume torch fuel

Post by Zo Kath Ra »

But I like to sleep with the lights on...
User avatar
st1nger
Posts: 19
Joined: Wed May 29, 2013 8:44 pm
Location: Germany

Re: [SCRIPT] Party resting consume torch fuel

Post by st1nger »

Hehe, then get a firefly as pet :D
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: [SCRIPT] Party resting consume torch fuel

Post by Drakkan »

resting without a light is likely a suicidal in the dungeon for whole party, but thanks for sharing the script :)
Breath from the unpromising waters.
Eye of the Atlantis
Post Reply