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!
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Ah. Yes, I'm afraid you will have to do something like that. Adding animation events to the beginning of your first model's animations and using the first AnimationComponent's onAnimationEvent hook is probably easier than using onBeginAction, since then you will easily catch when the monster falls through a pit/flinches/gets knocked back/etc. For example:

Code: Select all

do
local listOfAnimations = { -- the same animation table as your first AnimationComponent
	turnRightNormal = "assets/animations/monsters/fjeld_warg/fjeld_warg_turn_right.fbx",
	fall = "assets/animations/monsters/fjeld_warg/fjeld_warg_get_hit_front_left.fbx",
	attack = "assets/animations/monsters/fjeld_warg/fjeld_warg_attack.fbx",
	getHitFrontLeft = "assets/animations/monsters/fjeld_warg/fjeld_warg_get_hit_front_left.fbx",
	turnLeftNormal = "assets/animations/monsters/fjeld_warg/fjeld_warg_turn_left.fbx",
	getHitFrontRight = "assets/animations/monsters/fjeld_warg/fjeld_warg_get_hit_front_right.fbx",
	turnRight = "assets/animations/monsters/fjeld_warg/fjeld_warg_turn_right.fbx",
	getHitBack = "assets/animations/monsters/fjeld_warg/fjeld_warg_get_hit_back.fbx",
	moveForward = "assets/animations/monsters/fjeld_warg/fjeld_warg_walk.fbx",
	turnLeft = "assets/animations/monsters/fjeld_warg/fjeld_warg_turn_left.fbx",
	idle = "assets/animations/monsters/fjeld_warg/fjeld_warg_idle.fbx",
	getHitLeft = "assets/animations/monsters/fjeld_warg/fjeld_warg_get_hit_left.fbx",
	getHitRight = "assets/animations/monsters/fjeld_warg/fjeld_warg_get_hit_right.fbx"
}
for name,filename in pairs(listOfAnimations) do
defineAnimationEvent{
	animation = filename,
	event = "anim2play_"..name,
	normalizedTime = 0,
}
end
end
Then in your first AnimationComponent:

Code: Select all

onAnimationEvent = function(self,event)
  if event:find("anim2play_") then
    otherAnimationComponent:play(event:sub(11))
  end
end,
Now otherAnimationComponent will play its own animation of the same name every time the first AnimationComponent does. Obviously, you can get rid of the dumb string parsing part, this is just for illustrative purposes.
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.
User avatar
Leki
Posts: 550
Joined: Wed Sep 12, 2012 3:49 pm

Re: Ask a simple question, get a simple answer

Post by Leki »

minmay wrote:Ah. Yes, I'm afraid you will have to do something like that. Adding animation events to the beginning of your first model's animations and using the first AnimationComponent's onAnimationEvent hook is probably easier than using onBeginAction, since then you will easily catch when the monster falls through a pit/flinches/gets knocked back/etc. For example:

Code: Select all

do
local listOfAnimations = { -- the same animation table as your first AnimationComponent
	turnRightNormal = "assets/animations/monsters/fjeld_warg/fjeld_warg_turn_right.fbx",
	fall = "assets/animations/monsters/fjeld_warg/fjeld_warg_get_hit_front_left.fbx",
	attack = "assets/animations/monsters/fjeld_warg/fjeld_warg_attack.fbx",
	getHitFrontLeft = "assets/animations/monsters/fjeld_warg/fjeld_warg_get_hit_front_left.fbx",
	turnLeftNormal = "assets/animations/monsters/fjeld_warg/fjeld_warg_turn_left.fbx",
	getHitFrontRight = "assets/animations/monsters/fjeld_warg/fjeld_warg_get_hit_front_right.fbx",
	turnRight = "assets/animations/monsters/fjeld_warg/fjeld_warg_turn_right.fbx",
	getHitBack = "assets/animations/monsters/fjeld_warg/fjeld_warg_get_hit_back.fbx",
	moveForward = "assets/animations/monsters/fjeld_warg/fjeld_warg_walk.fbx",
	turnLeft = "assets/animations/monsters/fjeld_warg/fjeld_warg_turn_left.fbx",
	idle = "assets/animations/monsters/fjeld_warg/fjeld_warg_idle.fbx",
	getHitLeft = "assets/animations/monsters/fjeld_warg/fjeld_warg_get_hit_left.fbx",
	getHitRight = "assets/animations/monsters/fjeld_warg/fjeld_warg_get_hit_right.fbx"
}
for name,filename in pairs(listOfAnimations) do
defineAnimationEvent{
	animation = filename,
	event = "anim2play_"..name,
	normalizedTime = 0,
}
end
end
Then in your first AnimationComponent:

Code: Select all

onAnimationEvent = function(self,event)
  if event:find("anim2play_") then
    otherAnimationComponent:play(event:sub(11))
  end
end,
Now otherAnimationComponent will play its own animation of the same name every time the first AnimationComponent does. Obviously, you can get rid of the dumb string parsing part, this is just for illustrative purposes.
Yes, animation events on 1st frame is the best way, I agree - I used onBegin just as a simple example here in questions.
What I dont understand is this part:

Code: Select all

otherAnimationComponent:play(event:sub(11))
it's the same problem as I have with

Code: Select all

self.go.animation("weapons"):play("moveForward")
I mean - what is the propper syntax to call that component?[/color]
I'm the Gate I'm the Key.
Dawn of Lore
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Sorry, that shorthand was confusing. If your other animation component is named "goat", it would be:

Code: Select all

onAnimationEvent = function(self,event)
  if event:find("anim2play_") then
    self.go.goat:play(event:sub(11))
  end
end,
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.
User avatar
Leki
Posts: 550
Joined: Wed Sep 12, 2012 3:49 pm

Re: Ask a simple question, get a simple answer

Post by Leki »

minmay wrote:Sorry, that shorthand was confusing. If your other animation component is named "goat", it would be:

Code: Select all

onAnimationEvent = function(self,event)
  if event:find("anim2play_") then
    self.go.goat:play(event:sub(11))
  end
end,
Cool, so the answer is: propper syntax is just: self.go.component_name:play(). Thanks for help m8.
I'm the Gate I'm the Key.
Dawn of Lore
User avatar
petri
Posts: 1917
Joined: Thu Mar 01, 2012 4:58 pm
Location: Finland

Re: Ask a simple question, get a simple answer

Post by petri »

@Leki: a simple way to attach a weapon like a sword to a monster's hand is to use the parentNode property. This way you don't need to animate the weapon at all.
User avatar
Leki
Posts: 550
Joined: Wed Sep 12, 2012 3:49 pm

Re: Ask a simple question, get a simple answer

Post by Leki »

petri wrote:@Leki: a simple way to attach a weapon like a sword to a monster's hand is to use the parentNode property. This way you don't need to animate the weapon at all.

Yes, sword is fine, axe and morning star as well, but I have armoured body parts, bow etc and they have more komplex skin and parent node cannot manage it - I need "full animation" for them. The point is that I have geared monster and onActivate script will turn on random weapons and gear parts around the main body (and activate brain for a selected weapon) - so with one "smart" object I have nice visual variability of one monster type.
I'm the Gate I'm the Key.
Dawn of Lore
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

petri wrote:@Leki: a simple way to attach a weapon like a sword to a monster's hand is to use the parentNode property. This way you don't need to animate the weapon at all.
Oh wow, I never realized ModelComponent supported that! I have a lot of things to redesign now...
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.
User avatar
The cube
Posts: 94
Joined: Tue Apr 23, 2013 6:09 pm
Location: Barren Desert

Re: Ask a simple question, get a simple answer

Post by The cube »

Is it possible to check what tile (forest_trees/forest_wall/...) is in a certain tile?

for example, is it possible to check if there is a forest_ground tile with elevation equal to our monster's elevation in front of the monster?

or is there a way to circument this withought adding a shitton of blockers or other objects to use as walls.
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

It is possible to check the decorations present, and make an assumption... It is also possible check what the automap tile is. Provided you don't alter it in your mod, it's a reasonably reliable way to check for certain aspects using the Map component.

Ground can be distinguished from water, and a few other types.
The automap tile number can be 0 (ground), 1 (grassy_ground), 2 (water), 3 (wall), 4 (rocky_wall), 5 (trees) or 6 (chasm).

A combination check of the automap tile, and the decorations present could give a good guess as to the tile used. Elevation check is another feature of the Map component.
User avatar
Eleven Warrior
Posts: 745
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Ask a simple question, get a simple answer

Post by Eleven Warrior »

Hi guys. I am trying to get this script to work. What happens is when the counter gets to 9 nothing will happen. It comes up with a error with the rat_shank. The player can pull the level 9 times to get a rat_shank, but after that they get nothing. I go this script from LOG 1. Any help would be appreciated thxs :)

Oh a lever is connected to the function (feedTheParty) I can name the rat_shank to rat_shank_1 but when you pull the lever the second time it says duplicate item etc...

Code: Select all

fed_counter = 0

function feedTheParty()
if fed_counter > 9 then
	hudPrint("Nothing happens.")
else
	fed_counter = fed_counter + 1
		spawn("rat_shank",5,26,18,2,0)
			pickup_food_alcove.surface:addItem(rat_shank.item)
				playSound("level_up")
end
	end
Post Reply