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
Khollik
Posts: 171
Joined: Tue Aug 29, 2017 6:44 pm
Location: France

Re: Ask a simple question, get a simple answer

Post by Khollik »

An alternate solution would be to position the two objects at the same location and enable/disable models when needed, for instance:

Code: Select all

function switchcandle()
candle1.model:enable()
candle2.model:disable()
candle1.light:enable()
candle2.light:disable()
end

function switchback()
candle1.model:disable()
candle2.model:enable()
etc.
end
It's maybe not very elegant but it helped me sometimes not messing around with setWorldPosition

K.
Pompidom
Posts: 497
Joined: Sun May 06, 2018 9:42 pm

Re: Ask a simple question, get a simple answer

Post by Pompidom »

That's it. It's perfect!
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 »

If those candles can be picked up, you might want to ensure that their item information matches their appearance when they are inspected in inventory.
User avatar
Huff
Posts: 18
Joined: Fri Jun 22, 2012 9:47 pm

Re: Ask a simple question, get a simple answer

Post by Huff »

I'm attempting to replicate the attack functionality for hitting monsters in the onHitMonster hook for weapons. My goal is to be able to use custom damage formulas that change protection to a percentage based 0 to 100% instead of flat addition and subtraction.

Here's what I've got so far:

Code: Select all

function hitMonster(self, attack, monster, tside, damage, champion)
	local damageType = attack:getDamageType()
	if damageType == "physical" or not damageType then
		local dmg = damage
		local pierce = attack:getPierce()
		local protection = monster:getProtection()
		if pierce then
			protection = protection - pierce
		end
		if protection > 0 and protection < 100 then
			dmg = math.max(1, math.floor(dmg * (1 - (protection * .01))))
		elseif protection >= 100 then
			dmg = 1
		else -- protection <= 0
			-- do nothing
		end
		local dmgText = ""..dmg
		monster:setHealth(monster:getHealth() - dmg)
		monster:showDamageText(dmgText, "FFFFFF")
		playSoundAt(monster:getHitSound(), monster.go.level, monster.go.x, monster.go.y)
		if monster:getHealth() <= 0 then
			monster:die()
		else
			if monster:getHitEffect() then
				local particle = spawn("particle_system", monster.go.level, monster.go.x, monster.go.y, monster.go.facing, monster.go.elevation)
				particle.particle:setParticleSystem(monster:getHitEffect())
				particle:setWorldPositionY(monster:getCapsuleHeight())
			end
			if not monster:getCurrentAction() and not monster:isPerformingAction("damaged") then
				if tside == 0 then
					if champion == party.party:getChampion(1) or champion == party.party:getChampion(3) then
						monster.go.animation:play("getHitFrontRight")
					else
						monster.go.animation:play("getHitFrontLeft")
					end
				elseif tside == 1 then
					monster.go.animation:play("getHitRight")
				elseif tside == 2 then
					monster.go.animation:play("getHitBack")
				elseif tside == 3 then
					monster.go.animation:play("getHitLeft")
				end
			end
		end
	end
end
Everything here works except for the monster's interrupted state. Currently, this just plays the animation of getting hit, but doesn't actually put them in the "damaged" action state which stops them from attacking, moving, etc.

One thing I have tried is disabling the monster's brain class temporarily with use of delayedCall, but it has mixed results since the number of frames on getHit animations varies. I think it may also break scripted monsters too.

I'm wondering if there's some built-in function I'm not seeing like monster:performAction("damagedFrontRight").
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 »

Huff wrote: Sun Sep 09, 2018 5:31 pm I'm attempting to replicate the attack functionality for hitting monsters in the onHitMonster hook for weapons. My goal is to be able to use custom damage formulas that change protection to a percentage based 0 to 100% instead of flat addition and subtraction.

Everything here works except for the monster's interrupted state. Currently, this just plays the animation of getting hit, but doesn't actually put them in the "damaged" action state which stops them from attacking, moving, etc.

One thing I have tried is disabling the monster's brain class temporarily with use of delayedCall, but it has mixed results since the number of frames on getHit animations varies. I think it may also break scripted monsters too.

I'm wondering if there's some built-in function I'm not seeing like monster:performAction("damagedFrontRight").
Hey Huff!
in order to get knockbacks happening cleanly (even while the monster is doing something at the time) .... minmay posted this:
SpoilerShow

Code: Select all

onHitMonster = function(self, monster)
	
	if monster:isAlive() and not monster:isFalling() and monster:getCurrentAction() ~= "knockback" then
		
		monster.go:setPosition(monster.go.x,monster.go.y,monster.go.facing,monster.go.elevation,monster.go.level)
		
		monster:knockback(party.facing)
	
	end

end,
... with the explanation:
Setting a monster's position is the easiest way to interrupt monster actions.
Perhaps this can help??

Also, not sure if you know... afaik, when a monster is hit and damaged, a component called 'damaged' is created and attached to the monster game object. This component has a field called 'animation' and it is = to the current (or last) animation used when the monster was hit / needed to perform the 'damaged' action. Unsure if this component is destroyed and recreated when the monster is hit again or whether the animation field is just updated.

Also, how do you plan on handling Firearm weapons - as they do not have an onHitMonster() hook.... ?? :?
(I ask because thats what I am stuck on, working on the same thing....)

Akroma ;)
User avatar
Huff
Posts: 18
Joined: Fri Jun 22, 2012 9:47 pm

Re: Ask a simple question, get a simple answer

Post by Huff »

Setting the monster's position is a great way to interrupt them, but the "damaged" action state is different as it locks the monster in place for the duration of their getHit animation. I think there may be a way to pull it off using a custom MonsterAction component.

Firearm attacks actually do have an onHitMonster hook inherited from the MeleeAttack component by the way!
minmay
Posts: 2780
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Said "damaged" component is just a plain MonsterActionComponent without any special frills. This would be the code for recreating that behaviour:

Code: Select all

function monsterDamageAnimation(monster, anim)
	if monster:getCurrentAction() == nil then
	if not monster.go.damaged then
		monster.go:createComponent("MonsterAction","damaged")
	end
	monster.go.damaged:setAnimation(anim)
	monster:performAction("damaged")
end
Call this every time a monster gets hit for more than 0 damage by something with the DamageFlags.Impact flag. The monster parameter should be the MonsterComponent and the anim parameter should be the name of the animation to play ("getHitBack", "getHitFrontLeft", "getHitFrontRight", "getHitLeft", or "getHitRight").
If you wish to interrupt the current action, then you could use that setPosition hack I described first, but keep in mind that this would be undesirable for a lot of actions (such as moving).
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
akroma222
Posts: 1029
Joined: Thu Oct 04, 2012 10:08 am

Re: Ask a simple question, get a simple answer

Post by akroma222 »

Huff wrote: Thu Sep 13, 2018 1:56 am Firearm attacks actually do have an onHitMonster hook inherited from the MeleeAttack component by the way!
Ahhh this is good news indeed!
I sorted a work around but it was messy (and unnecessary lol)
minmay wrote: Thu Sep 13, 2018 6:08 am Said "damaged" component is just a plain MonsterActionComponent without any special frills. This would be the code for recreating that behaviour:
SpoilerShow

Code: Select all

function monsterDamageAnimation(monster, anim)
	if monster:getCurrentAction() == nil then
	if not monster.go.damaged then
		monster.go:createComponent("MonsterAction","damaged")
	end
	monster.go.damaged:setAnimation(anim)
	monster:performAction("damaged")
end
Call this every time a monster gets hit for more than 0 damage by something with the DamageFlags.Impact flag. The monster parameter should be the MonsterComponent and the anim parameter should be the name of the animation to play ("getHitBack", "getHitFrontLeft", "getHitFrontRight", "getHitLeft", or "getHitRight").
If you wish to interrupt the current action, then you could use that setPosition hack I described first, but keep in mind that this would be undesirable for a lot of actions (such as moving).
This is also all very good news! :lol: :D
Thanks for clearing that up minmay, that really is golden ;)
tantalan
Posts: 112
Joined: Mon Mar 12, 2012 5:49 pm

Re: Ask a simple question, get a simple answer

Post by tantalan »

Hi, I haven't played Grimrock for a while - I completed both games and I am really sad, that there is not going to be a Grimrock 3. Why? Because the second part was better than first, that is really uncommon in video, games industry so third part would be the best I guess.

My question.
Have someone played all (most of) of these mods and by players created dungeons and could you recommend me "Grimrock like" game - I mean custom dungeon mod that would the most remind Grimrock like adventure (riddles, balance of items etc. I dont mean exactly the same dungeon as Grimrock). I have played several dungeons and they are pretty not well balanced - I receive superior armor in the beginning etc. Please recommend me - relatively long, but well balanced dungeon, but if possible not very hard in the beginning, so i can go through easily.

Ragards Tantalan - Czech republic, Prague :-)
kelly1111
Posts: 349
Joined: Sun Jan 20, 2013 6:28 pm

Re: Ask a simple question, get a simple answer

Post by kelly1111 »

my personal favorites:

labyrinth of lies
tomb of zarthos
the mine of malan vael
Post Reply