Page 2 of 2

Re: Creating Custom assets (monsters, objects and items)

Posted: Sat May 30, 2020 11:56 pm
by Isaac
ratman wrote: Sat May 30, 2020 11:36 pm For now if I call destroy() on the item when its in an inventory it just crashes and gives an error message that the item doesn't exist.
Items in character inventory do not exist—on the map.
SpoilerShow
To interact with inventory items, you must use the Champion object—specifically the one champion who is holding the item. You can then call either the removeItem() function, or removeItemFromSlot() function for that champion.

https://github.com/JKos/log2doc/wiki/Ob ... s#champion

*The usual way(s) to access a champion object is to assign a local variable [typically called champion] the return value from
party.party:getChampion(number)
or
party.party:getChampionByOrdinal(number)

Where 'number' is the current champion in slot position 1 through 4, or (by ordinal) number is the ordinal number assigned to the champions when the game starts; their first positions. This number never changes.

______________________

Example:

Code: Select all

--in your function
local champion = party.party:getChampion(2) --for the champion in position #2; upper right portrait

Code: Select all

--in your function
local champion = party.party:getChampionByOrdinal(2) --for champion #2; could be in any position, doesn't matter
Item onEquip/Unequip hooks provide the relevant champion object to use with them.
https://github.com/JKos/log2doc/wiki/Co ... -component
*Search this thread for LoG2 answers; it's probably there, and if not, just ask. ;)
http://www.grimrock.net/forum/viewtopic.php?f=22&t=7951

Re: Creating Custom assets (monsters, objects and items)

Posted: Sat Jun 06, 2020 6:01 pm
by ratman
I try this script just to test it, but it gives me an error saying

Code: Select all

bad argument #1 to 'removeItem' (ItemComponent expected, got ???
The script that gives me the error:

Code: Select all

function removeitem()
	party.party:getChampion(1):removeItem(torch)
end
I also tried using the code in an item and got the same error:

Code: Select all

defineObject{
	name = "torch_",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/torch.fbx",
		},
		{
			class = "Item",
			uiName = "Torch",
			gfxIndex = 130,
			impactSound = "impact_blunt",
			weight = 1.2,
		},
		{
			class = "TorchItem",
			fuel = 1100,
		},
		{
			class = "UsableItem",
			sound = "fireburst",
			onUseItem = function(self, champion)
			champion:removeItem(torch)
			champion:insertItem(1, rock)
			end
		},
	},
}
I am probably doing something wrong, I just don't know what. (Yes, the champion is holding a torch when the script is called) :lol:

Re: Creating Custom assets (monsters, objects and items)

Posted: Sat Jun 06, 2020 9:04 pm
by Isaac
The function expects the object's item component; not the object itself. So...

Code: Select all

 --example
local champion = party.party:getChampion(1)
champion:removeItem(champion:getItem(1).go.item)

--removes the left-hand item from the top left champion. 
Listing of Item Slots, by name & number:
https://github.com/JKos/log2doc/wiki/Ob ... s#itemslot

Code: Select all

--alternate example
local champion = party.party:getChampion(1)
champion:removeItem(champion:getItem(ItemSlot.Weapon).go.item)

Re: Creating Custom assets (monsters, objects and items)

Posted: Sun Jun 14, 2020 5:51 pm
by ratman
Okay, I'll try experimenting with some different scripts. In the meantime, I've been trying some more modeling, this time just basic stuff. First of all, I am trying to create an item that is just a small square, with my own textures. I am able to add it to the game, the textures work, but the item is huge. I try to just make it smaller in blender, and export it again, but it's still the exact same size. Also I've just been trying to combine models; making a wizard hold a sword, making a trickster hold a machete. To do this I just import the trickster model, and import the machete model, and move the machete so it's in his hand. Then when I export it gives me an error, but creates the model file, and when I place it on the map (as just an object with no animations) it gives me another error. Could this be because there is two objects in the file? And if so, is there a way to combine them into one object? :?

Re: Creating Custom assets (monsters, objects and items)

Posted: Sun Jun 14, 2020 10:07 pm
by Isaac
You must apply the scale in Blender, before exporting. With the object selected, press <CTRL> + A, to apply the scale; IE, to adjust the model scale to 1,1,1.

Image

______________

Getting monsters to hold a weapon (rudimentarily)... is thankfully very easy—if you know the built in feature for it. ;)

Here is a variation of Trickster with a machete; using stock animation. He tosses bombs at range, but uses the machete when close enough to reach.

Code: Select all

defineObject{
	name = "trickster_armed_machete",
	baseObject = "trickster",
	components = {

		{ --Weapon Model Component!
			class = "Model",
			name = "weapon",
			parentNode = "hand_1_right", --Node in Trickster model, to attach weapon model to.
			model = "assets/models/items/machete.fbx",
			--================================================================================
			offset = vec(.20,.10,-.4),  --location of weapon model relative to hand
			rotation = vec(220,-65, -10), --rotation of weapon model relative to hand
			--================================================================================
			storeSourceData = true, -- must be enabled for mesh particles to work
		},
			{
				class = "MonsterAttack",
				name = "rangedAttack",
				animation = "throwItem",
				attackType = "melee",
				attackPower = 20,
				cooldown = 4,
				sound = "swipe_special",
				onAttack = function(self) 
						if self.go.brain.partyAdjacent then
							return true
						end
						local bomb = spawn('fire_bomb')
						self.go.monster:addItem(bomb.item)
						self.go.monster:throwItem(bomb.name, 2, 15)
						self.go.monster:removeItem(bomb.item)
						playSound('trickster_throw')
						return true
					end
			},

	}

}
Image

You can improve on this by generating your own animations, but you need not import weapon models, and by keeping them separate, and included as model components, they can be automatically made part of the existing game animations.

Re: Creating Custom assets (monsters, objects and items)

Posted: Thu Jul 23, 2020 7:46 pm
by jane477
ratman wrote: Sun Jun 14, 2020 5:51 pm Okay, I'll try experimenting with some different scripts. In the meantime, I've been trying some more modeling, this time just basic stuff. First of all, I am trying to create an item that is just a small square, with my own textures. I am able to add it to the game, the textures work, but the item is huge. I try to just make it smaller in blender, and export it again, but it's still the exact same size. Also I've just been trying to combine models; making a wizard hold a sword, making a trickster hold a machete. To do this I just import the trickster model, and import the machete model, and move the machete so it's in his hand. Then when I export it gives me an error, but creates the model file, and when I place it on the map (as just an object with no animations) it gives me another error. Could this be because there is two objects in the file? And if so, is there a way to combine them into one object? :?
Scaling it is first thing you need to do , and also, if I remember correctly some objects in the game are size restricted so even if you change the model in Blender the game will upscale or downscale according the its settings