Page 1 of 1

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

Posted: Mon Sep 21, 2015 3:11 am
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 ???)

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

Posted: Mon Sep 21, 2015 3:38 pm
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",
		},

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

Posted: Mon Sep 21, 2015 6:48 pm
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?

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

Posted: Mon Sep 21, 2015 6:58 pm
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",
		},
	},
}