TorchItem Component issues?

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
MadCatter
Posts: 34
Joined: Mon Nov 03, 2014 5:02 am
Location: Southampton, UK

TorchItem Component issues?

Post by MadCatter »

I've been trying to create a lantern item (definition below), but when I pick up the item it results in this error:

What am I doing wrong? I have tried defining fuel amounts as well but to no avail. Is it an issue with my syntax?

Previously I used baseObject = "torch_everburning" but that resulted in item atlas glitches when it automatially increments the index on equip.

Image

Item Definition:
SpoilerShow

Code: Select all

defineObject{
   name = "hand_lantern",
   baseObject = "base_item",
      components = {
      {
         class = "Model",
         model = "mod_assets/models/sx_lantern.fbx",
      },
	  {
         class ="Item",
         uiName = "Lantern",
		 gfxAtlas = "mod_assets/textures/items_atlas.dds",
         gfxIndex = 0,
		 GfxIndexPowerAttack = 1,
         secondaryAction = "Fire_Blast",
		 impactSound = "impact_blade",
         weight = 3,
         traits = { "item" },
         description = "An old oil lantern.",
      },
{
		 class ="TorchItem",
		 onEquipItem =
			function()
				self.go.torch:setType("spot")
self.go.torch:enable()
			end,
	  },
	  {
         class = "MeleeAttack",
         attackPower = 5,
         attackSound = "impact_blade",
         cooldown = 3.0,
         baseDamageStat = "strength",
         damageType = "physical",
      },
	  {
        class = "CastSpell",         
        name = "Fire_Blast",
		uiName = "Fire Blast",
		spell = "fireburst",
		repeatCount = 0,
		cooldown = 6,
        energyCost = 30,
	  },
   },
   editorIcon = 24,
}
Thanks to anyone who can help.
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: TorchItem Component issues?

Post by NutJob »

add "fuel = 1100," to torchitem class, perhaps, then try again.

May need to update that amount every so often so it doesn't burn out.

Edit: or maybe "fuel = inf" for infinity? I just looked that one up in John's Primitive asset definitions.
Last edited by NutJob on Fri Nov 21, 2014 7:29 pm, edited 1 time in total.
Batty
Posts: 509
Joined: Sun Apr 15, 2012 7:04 pm

Re: TorchItem Component issues?

Post by Batty »

I get the same error if I have this line:

Code: Select all

party.party:getChampion(1):insertItem(2, spawn("torch").item)
even though I 'cleaned' the party's inventory out first. Strange thing is if I press play after the error, the editor starts and champion(1) has a torch in hand (but it crashes if exported).

I have no problem inserting any other items into the party's inventory, only the torch, so maybe this is related to MadCatter's error.
User avatar
MadCatter
Posts: 34
Joined: Mon Nov 03, 2014 5:02 am
Location: Southampton, UK

Re: TorchItem Component issues?

Post by MadCatter »

NutJob wrote:add "fuel = 1100," to torchitem class, perhaps, then try again.

May need to update that amount every so often so it doesn't burn out.

Edit: or maybe "fuel = inf" for infinity? I just looked that one up in John's Primitive asset definitions.
Can't believe it was that simple, thanks. :D

"inf" didn't seem to work, so I substituted it for "math.huge" which seems to be standard in lua.

However, now I have another problem. Adding a torch component to an item makes the item atlas index increment by one when it is equipped, and has a vertical offset of the image. I'm assuming this is due to some code that comes bundled with the class, but is there any way to disable that?
You can see in the image below, both icons are shifted down a small amount.
SpoilerShow
Image
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: TorchItem Component issues?

Post by NutJob »

Perhaps something to do with being a weapon and weapons get shoved down so they take up the entire slot? GUI isn't something I've even looked into yet with the editor. =)

AKA I have no idea.
User avatar
MadCatter
Posts: 34
Joined: Mon Nov 03, 2014 5:02 am
Location: Southampton, UK

Re: TorchItem Component issues?

Post by MadCatter »

Could be. I'll just have a fiddle with the item atlas and see if I can adjust it there so it ends up in the right place.
GUI meddling can wait until some other time :D
Thanks.
Periodiko
Posts: 19
Joined: Fri Oct 19, 2012 2:45 am

Re: TorchItem Component issues?

Post by Periodiko »

How is this going? I created a torch item with a similar approach - it's a magic staff that's supposed to radiate torchlight - but in-game the item weirdly replaces the base graphics with a normal torch. I'm not really sure how to proceed.
User avatar
MadCatter
Posts: 34
Joined: Mon Nov 03, 2014 5:02 am
Location: Southampton, UK

Re: TorchItem Component issues?

Post by MadCatter »

I think you want to use the following functions in your item definition. The gfxIndexInHand is the one that is changing the texture when you equip it.

Code: Select all

gfxIndex(number)          Set index of icon in texture atlas
gfxIndexInHand(number)          Set index of in-hand icon
gfxIndexPowerAttack(number)          Set index of charging power attack icon
Strangely though, there doesn't seem to be anything in the definition of the torch item which is odd. I assume it's handled inside the torchItemComponent which seems to automatically increment the gfx index by 1 when you equip the item, and puts it out in water (may be an issue if you want to use your staff underwater).
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: TorchItem Component issues?

Post by minmay »

It doesn't just increment it by 1, it changes it depending on the fuel level. The "torch" item uses indices 130 (not lit), 131 (lit, brightest), 132, 133, 134, 135 (burnt out), and 104 (used).
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.
Post Reply