change the inventory icon of a torch(problem)

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
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

change the inventory icon of a torch(problem)

Post by FeMaiden »

I dunno. I am trying to make a custom item. I took the everburning torch and changed it's model to look like the orb of radiance. to create an "orb" that burns forever like a torch.

now, I know the graphic has 2 components, the 3d model you see when it's on the ground, and then the 2d icon when you pick it up.

the 3d model on the ground looks right, but when I pick it up, it changes to look like a torch again.

in the past, I just changed the GfxIndex to match the item in the grimrock assets.

but this torch, no matter what I change the GfxIndex to, it still looks like a torch.
is the 2d image hardcoded in, because it's class = TorchItem?

is it because I'm trying to give it a GFXIndex for a class = EquipmentItem?

but I am assuming that to get it to act as an everburning torch, I need this

Code: Select all

{
			class = "TorchItem",
			fuel = math.huge,
		},
if I change it to equipmentItem then it won't act like a torch anymore?

Am I missing something here?
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

Re: change the inventory icon of a torch(problem)

Post by minmay »

IIRC TorchItemComponent makes the item use gfx indices 130 (not lit), 131 (lit, brightest), 132, 133, 134 (lit, dimmest), 135 (burnt out), and 104 (not lit, partly used). You can still use a custom atlas, so you can use custom icons for every step of the process, their indices are just locked at those values.

If you want to implement an effect like the light from Grimrock 1's Orb of Radiance, with the ability to use arbitrary color/range/etc, you might be interested in what I did here for the Illumulet. It detects whether an item is worn, and if it is, disables the party's default light source and replaces it with a better one. When all such items are removed, the party's original light source is enabled again and the new one is disabled. Here is the relevant code:

Code: Select all

-- illumination has to be handled in party hook
defineObject{
	name = "dm_necklace_illumulet",
	baseObject = "base_dm_item",
	components = {
		{
			class = "Model",
			model = "mod_assets/dmcsb_pack/models/items/dm_amulet_illumulet.fbx",
		},
		{
			class = "Item",
			uiName = "Illumulet",
			gfxAtlas = "mod_assets/dmcsb_pack/textures/gui/dm_icoatlas.tga",
			gfxIndex = 24,
			weight = 0.2,
			impactSound = "dm_katana",
			traits = { "necklace", "illumulet" },
			onEquipItem = function(self, champion, slot)
				if slot == ItemSlot.Necklace then
					party.dm_illum:enable()
					party.torch:disable()
				end -- dm_illum's onUpdate takes care of disabling
			end,
		},
		{
			class = "Light",
			brightness = 16,
			color = vec(1,1,1),
			range = 7,
			castShadow = false,
			offset = vec(-0.02926,0.055,-0.09462),
		},
	},
}

Code: Select all

defineObject{
	name = "party",
	baseObject = "party",
	components = {
		{	-- can't really modify torch's color, so duplicate it instead
			-- luckily torch still updates when disabled, unlike regular
			-- LightComponent onUpdate hooks.
			-- Multiple illumulets do not stack (multiple torches, light
			-- spells, etc. don't stack, so this is consistent).
			class = "Light",
			name = "dm_illum",
			brightness = 0,
			range = 11, -- a bit longer than torch (9)
			castShadow = false,
			enabled = false,
			onUpdate = function(self)
				for i=1,4 do
					local necklace = party.party:getChampion(i):getItem(ItemSlot.Necklace)
					if necklace and necklace:hasTrait("illumulet") then
						local col = self.go.torch:getColor()
						local brightness = self.go.torch:getBrightness()
						local illumBrightness = 8*(math.noise(Time.currentTime())+1)
						-- illumulet light is pure white. No stacking.
						col[1] = col[1]*(brightness/8)+1
						col[2] = col[2]*(brightness/8)+1
						col[3] = col[3]*(brightness/8)+1
						self:setColor(col)
						if self.go.torch:getRange() == 9 then -- torch or light spell
							self:setBrightness(math.max(brightness,illumBrightness))
							self:setOffset(self.go.torch:getOffset())
						else -- illumulet only
							self:setBrightness(illumBrightness)
							self:setOffset(vec(math.sin(Time.currentTime())*0.25,1.5,math.cos(Time.currentTime())*0.25-1))
						end
						self.go.torch:disable()
						return
					end
				end
				-- no illumulets worn, switch back to torch
				self.go.torch:enable()
				self:disable()
			end,
		},
	},
}
It's easily adaptable to other items.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

Re: change the inventory icon of a torch(problem)

Post by FeMaiden »

I see...so it's a bit more work than just changing the integer stats.

thanks for the info, I actually understood that...I think.
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

Re: change the inventory icon of a torch(problem)

Post by Isaac »

Doesn't this also mean that by default the orb would be a melee weapon that sets the target on fire?

*That's a cool item minmay. 8-)
User avatar
FeMaiden
Posts: 290
Joined: Wed Jan 16, 2013 8:16 am

Re: change the inventory icon of a torch(problem)

Post by FeMaiden »

Isaac wrote:Doesn't this also mean that by default the orb would be a melee weapon that sets the target on fire?

*That's a cool item minmay. 8-)
yes...I'm actually wondering if this item is a good idea. It might not fit the theme of my mod. I'm not copping out just because the script is complicated lol...
Post Reply