Ask a simple question, get a simple answer

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!
User avatar
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Ask a simple question, get a simple answer

Post by akroma222 »

Kablammooo!! :twisted: :lol: :D
You could probably spawn an additional particle effect using the "wood_splinter" texture
....this ones from the asset pack: "hit_wood"
SpoilerShow

Code: Select all

defineParticleSystem{
	name = "hit_wood",
	emitters = {
		{
			spawnBurst = true,
			maxParticles = 60,
			boxMin = {-0.5,-0.5,-0.5},
			boxMax = { 0.5, 0.25, 0.5},
			sprayAngle = {0,60},
			velocity = {2,4},
			objectSpace = false,
			texture = "assets/textures/particles/wood_splinter.tga",
			lifetime = {0.7,1},
			color0 = {0.55, 0.45, 0.4},
			opacity = 0.5,
			fadeIn = 0.1,
			fadeOut = 0.3,
			size = {0.1, 0.2},
			gravity = {0,-7,0},
			airResistance = 0.2,
			rotationSpeed = 2,
			blendMode = "Translucent",
			clampToGroundPlane = true,
		},

		{
			spawnBurst = true,
			maxParticles = 40,
			boxMin = {-0.75,-0.5,-0.75},
			boxMax = { 0.75, 0.25, 0.75},
			sprayAngle = {0,100},
			velocity = {0.5,2},
			objectSpace = false,
			texture = "assets/textures/particles/smoke_01.tga",
			lifetime = {0.3,1.5},
			color0 = {0.65, 0.4, 0.3},
			opacity = 0.3,
			fadeIn = 0.1,
			fadeOut = 0.3,
			size = {0.5, 1.5},
			gravity = {0,0,0},
			airResistance = 2,
			rotationSpeed = 1,
			blendMode = "Translucent",
		},
	}
}
PedroMoniz
Posts: 16
Joined: Wed Jan 11, 2017 9:46 pm

Re: Ask a simple question, get a simple answer

Post by PedroMoniz »

Hello,

I have a question regarding traits in usableItems

I have traits working in normal items, but how can I add keywords to usableItems?



Example would be:

cloneObject{
name = "Potion_Energy",
baseObject = "potion_energy",
components = {
{
class = "UsableItem",
uiName = "Energy Potion",
-- traits = { "good" ,"magic" },
onUseItem = function(item, champion)
hooks.script.item_OnUsePotion(item, champion)
end
}
},
}
User avatar
Isaac
Posts: 3179
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

PedroMoniz wrote:Hello,

I have a question regarding traits in objects.

What are these and how can i use them>
Traits are like permanent conditions that are inherent to the character (or item). They can be rule exceptions, for instance the 'aquatic' trait allows a weapon to be used underwater; and allows a monster operate submerged without drowning. Open the traits.lua file in the asset pack to read through the default traits. Characters can pick up to two optional traits during creation, the character classes provide additional [class related] traits; and the designer can invent new traits.

Most traits have one or more hooks that allow changes to be made to the character. If used, each is called every frame, and allows per-frame modification. Traits can be added and removed via script, and the existence of traits can be checked, and I have used traits as special markers for items ~not even needing the hooks.

You can assign (or remove) a trait to an item, monster, or champion by using the methods available to each (listed in the scripting reference). For monsters and items, you also can add traits to the traits table in its definition.

Check here for information on defining new/original traits:
https://github.com/JKos/log2doc/wiki/As ... etraitdesc
______
You've updated/changed your question a bit. What exactly are you planning, or wanting to use the traits to achieve?
Traits are not key-words or tags, per se... To have an effect, they have to exist as pre-defined. You'll get a console error when trying to add an undefined trait to something.
PedroMoniz
Posts: 16
Joined: Wed Jan 11, 2017 9:46 pm

Re: Ask a simple question, get a simple answer

Post by PedroMoniz »

I am just trying to add some identifiers to items.

To allow me to check if cheese is food or check if a potion is good and a mage item without having to go throught many ifs.

edit:
I have found a way to do what I want by just putting my data on my functions directly. Since i have to create my clones, I can just do this. It is ugly, but works.

cloneObject{
name = "Cheese",
baseObject = "cheese",
components = {
{
class = "UsableItem",
onUseItem = function(item, champion)
hooks.script.item_OnEatFood(item, champion, {"poor"})
end
}
},
}
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

You can always use the item trait system.
It basically just a string, but it can be very useful! My enchanting system works with them.
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
Isaac
Posts: 3179
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

PedroMoniz wrote:I am just trying to add some identifiers to items.

To allow me to check if cheese is food or check if a potion is good and a mage item without having to go throught many ifs.
With this defined, you can add the 'food' trait to items, and check if they are food:

Code: Select all

defineTrait{
	name = "food",
	uiName = "Food",
	description = "Item is edible food, and gives nutritional value.",
}

Code: Select all

cheese_1.item:addTrait('food')
print(cheese_1.item:hasTrait('food'))
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

Isaac wrote:
PedroMoniz wrote:I am just trying to add some identifiers to items.

To allow me to check if cheese is food or check if a potion is good and a mage item without having to go throught many ifs.
With this defined, you can add the 'food' trait to items, and check if they are food:

Code: Select all

defineTrait{
	name = "food",
	uiName = "Food",
	description = "Item is edible food, and gives nutritional value.",
}

Code: Select all

cheese_1.item:addTrait('food')
print(cheese_1.item:hasTrait('food'))
You don't define item traits, and AFAIK they don't have functionality on their own (except for built in ones)
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
Isaac
Posts: 3179
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

zimberzimber wrote:You don't define item traits, and AFAIK they don't have functionality on their own (except for built in ones)
All that's intended here is that cheese_1.item:hasTrait('food') returns true. It doesn't do anything besides that.
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

Isaac wrote:All that's intended here is that cheese_1.item:hasTrait('food') returns true. It doesn't do anything besides that.
I'm talking about your

Code: Select all

    defineTrait{
       name = "food",
       uiName = "Food",
       description = "Item is edible food, and gives nutritional value.",
    }
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
Isaac
Posts: 3179
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

zimberzimber wrote:
Isaac wrote:All that's intended here is that cheese_1.item:hasTrait('food') returns true. It doesn't do anything besides that.
I'm talking about your

Code: Select all

    defineTrait{
       name = "food",
       uiName = "Food",
       description = "Item is edible food, and gives nutritional value.",
    }
I know, but I'm not sure of the specific issue. The trait doesn't do anything, but it also doesn't cause a console error, and allows any item with the trait to be marked as food.
(But more to the purpose, it is a template for any kind of custom tag... "good", 'evil', "insect_only", "Jim's__personal_stuff", etc... It's true that one could check instead for Item:getNutritionValue() ~if all that was wanted was to detect food.)
Post Reply