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!
AdrianKnight
Posts: 21
Joined: Wed Aug 30, 2017 9:21 pm

Re: Ask a simple question, get a simple answer

Post by AdrianKnight » Thu Dec 08, 2022 3:56 pm

I would like to forbid resting if there are monsters in the 80 tiles surrounding the party (considering a 9x9 square with the party at the center of it).

Code: Select all


defineObject{
name = "party",

baseObject = "party",
components = {
{
			class = "Party",

			onRest = function(self)

			-- if there are monsters in the 80 tiles surrounding the party then

				for i = 1 , 4 do
 				local name = party.party:getChampion(i):getName()
				 if party.party:getChampion(i):isAlive() == true then
				   playSound("polymorph_bear")
				   hudPrint(name .. " says: 'We can't rest here. There are monsters in the surroundings.'")
				   break
				 end
				end

				return false

			-- end

			end,
},
},
}

How could I check if there are monsters in the 80 tiles surrounding the party ?

Thank you for your help.

minmay
Posts: 2747
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay » Thu Dec 08, 2022 8:28 pm

For such a large number of tiles, allEntities() will usually be faster than entitiesAt():

Code: Select all

onRest = function(self)
	local go = self.go
	local px = go.x
	local py = go.y
	local abs = math.abs
	local max = math.max
	for e in go.map:allEntities() do
		if e.monster and e.monster:isAlive() and max(abs(e.x-px), abs(e.y-py)) <= 4 then
			for i = 1 , 4 do
				if self:getChampion(i):isAlive() then
					playSound("polymorph_bear")
					local name = self:getChampion(i):getName()
					hudPrint(name .. " says: 'We can't rest here. There are monsters in the surroundings.'")
					return false
				end
			end
		end
	end
end
untested so i probably made a typo somewhere

Warning: If your dungeon has a DiggingToolComponent (like a shovel) or RopeToolComponent (like a rope) anywhere in it, and you ever return false from the onRest hook, you must also write code to prevent the DiggingToolComponent or RopeToolComponent from being used when the onRest hook will return false. Otherwise, you will break people's saved games. See mod_assets/core/scripts/reduced_standard_assets/items/misc.lua in ORRR3's source code.

Also, you asked for (and I provided) a Chebyshev distance test, but Grimrock uses Taxicab geometry for party and monster movement, not Chebyshev. So it would make more sense to use a Taxicab distance check: abs(e.x-px)+abs(e.y-py) <= [distance] instead of max(abs(e.x-px), abs(e.y-py)) <= [distance]. Consider this.
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.

AdrianKnight
Posts: 21
Joined: Wed Aug 30, 2017 9:21 pm

Re: Ask a simple question, get a simple answer

Post by AdrianKnight » Fri Dec 09, 2022 5:21 pm

Thank you.

I have another question to ask.
I noticed that the poison_cloud_medium spawned by the poison_bolt_greater_blast does not grant experience to the party when it kills a monster, even when the poison_bolt_greater is cast by a champion.

Code: Select all


defineObject{
	name = "poison_bolt_greater",
	baseObject = "poison_bolt",
	components = {
		{
			class = "Projectile",
			spawnOffsetY = 1.35,
			velocity = 10,
			radius = 0.1,
			hitEffect = "poison_bolt_greater_blast",
		},
	},
}

defineObject{
	name = "poison_bolt_greater_blast",
	baseObject = "poison_bolt_blast",
	components = {
		{
			class = "TileDamager",
			attackPower = 35,
			damageType = "poison",
			sound = "poison_bolt_hit",
			screenEffect = "poison_bolt_screen",
			onInit = function(self)
				local cloudspell = self.go:spawn("poison_cloud_medium").cloudspell
				local ord = self:getCastByChampion()
				if cloudspell and ord then
					cloudspell:setCastByChampion(ord)
				end
			end,
			onHitMonster = function(self, monster)
				monster:setCondition("poisoned", 25)

				-- mark condition so that exp is awarded if monster is killed by the condition
				local poisonedCondition = monster.go.poisoned
				local ord = self:getCastByChampion()
				if poisonedCondition and ord then
					poisonedCondition:setCausedByChampion(ord)
				end
			end,
		},
	},
}

Why ?

bongobeat
Posts: 983
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: Ask a simple question, get a simple answer

Post by bongobeat » Sun Dec 25, 2022 6:14 pm

Hey there and merry Christmas


I think I've already asked about that, but did someone manage to change the color of the name of items?

Like having the epic items name in yellow, and other specific item's name in another color.
My asset pack: viewtopic.php?f=22&t=9320

Log1 mod : Toorum Manor: viewtopic.php?f=14&t=5505

Kirill
Posts: 125
Joined: Mon Dec 21, 2020 5:36 pm

Re: Ask a simple question, get a simple answer

Post by Kirill » Thu Dec 29, 2022 10:16 am

bongobeat wrote:
Sun Dec 25, 2022 6:14 pm
Hey there and merry Christmas


I think I've already asked about that, but did someone manage to change the color of the name of items?

Like having the epic items name in yellow, and other specific item's name in another color.

New mod by Adragedron "Final Adventure" have this. Epic items have name in gold.


p.s. When you plan to release your LoG2 mod? Do you need testers?

Post Reply