Use item to create another item.. need help :P

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
vanblam
Posts: 243
Joined: Sun Nov 09, 2014 12:15 am

Use item to create another item.. need help :P

Post by vanblam »

Ive been trying to create item, that once use it , it will be replaced by another item. This is how I'm trying it but not successfully lol. I am a total scripting newb! so this will probably look very wrong :P

Code: Select all

defineObject{
	name = "glass_ball",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/power_gem.fbx",
		},
		{
			class = "Item",
			uiName = "Tome of Health",
			description = "A thick glass ball, somthing seems to be inside.",
			gfxIndex = 157,
			weight = 2.0,
			traits = { "ball" },
		},
		{
			class = "UsableItem",
			sound = "level_up",
			onUseItem = function(self, champion)
				hudPrint(champion:getName().."found an Iron Key")
				champion:insertItem(7, iron_key)
				return true
			end,
		},
	},
}
Every time I use the item I get.

bad argument #2 to 'insertItem' (ItemComponent expected, got ???)
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Use item to create another item.. need help :P

Post by Drakkan »

You can of course spawn it by some scripting, but maybe easier solution is just to use emptyItem and then regulery define the new spawned item

Code: Select all

		{
          class = "UsableItem",
          emptyItem = "rock", -- this will spawn rock when right-clicked on the item
          sound = "level_up",
		},
Breath from the unpromising waters.
Eye of the Atlantis
User avatar
vanblam
Posts: 243
Joined: Sun Nov 09, 2014 12:15 am

Re: Use item to create another item.. need help :P

Post by vanblam »

Drakkan wrote:You can of course spawn it by some scripting, but maybe easier solution is just to use emptyItem and then regulery define the new spawned item

Code: Select all

		{
          class = "UsableItem",
          emptyItem = "rock", -- this will spawn rock when right-clicked on the item
          sound = "level_up",
		},
Awesome that worked like a charm :D .. thank you.
Also just wondering how could I add a message to that?
User avatar
vanblam
Posts: 243
Joined: Sun Nov 09, 2014 12:15 am

Re: Use item to create another item.. need help :P

Post by vanblam »

Never mind I answered my own question haha.

Code: Select all

defineObject{
	name = "glass_ball",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/power_gem.fbx",
		},
		{
			class = "Item",
			uiName = "Tome of Health",
			description = "A thick glass ball, somthing seems to be inside.",
			gfxIndex = 157,
			weight = 2.0,
			traits = { "ball" },
		},
		{
			class = "UsableItem",
                        emptyItem = "iron_key", -- this will spawn an Iron Key when right-clicked on the item
			onUseItem = function(self, champion)
				hudPrint("You found an Iron Key")
			end,
			sound = "level_up",
		},
	},
}
Post Reply