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
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

minmay wrote:Pretty sure by "monster group" they meant a MonsterGroupComponent, not several different manually placed monsters.
That's a good point. I almost never use monster groups, so that never occurred to me.

It's kind of tricky to do... unless there is some undocumented feature for it; (which I don't know, but that you might ;) ).

Here is one method; based on the earlier script: (It works with single and grouped monsters; or both at once.)
Image

Code: Select all

--Script_entity

--List the monsters in the set here
groups = {}
set = {	
		"zarchton_1",
		"zarchton_2",	
		"ratling_group1",
		"ratling_group2",
		"medusa_group1",
		"medusa_group2",
		"zarchton_3",
		"zarchton_4",	
	}
	

for k,entry in pairs(set) do
	if entry:match("group%d+") then
		local monstergroup = findEntity(entry)
		if monstergroup and monstergroup.monstergroup then 
			groups[#groups+1] = {["entry"] = k, ["id"] = monstergroup.id, ["mType"] = (monstergroup.monstergroup:getMonsterType()),
								 ["count"] = monstergroup.monstergroup:getCount(), ["map"] = monstergroup.level,
								 ["x"] = monstergroup.x, ["y"] = monstergroup.y, ["f"] = monstergroup.facing, ["e"] = monstergroup.elevation}						
		end
	end	
end

for x = #set, 1, -1 do
	if set[x]:match("group%d+") then
		table.remove(set, x)
	end
end	



--Adds onDie hooks
function _addHooks()	
	for x = 1, #set do
		local monster = findEntity(set[x])
		if monster and monster.monster then
		   monster.monster:addConnector("onDie", self.go.id, "deadCheck")
		end
	end
end	


--Gets called by each monster as they die
function deadCheck(caller)
	--No entries, means they are all dead
	if #set < 1 then
		dungeon_door_wooden_1.door:open()  --========<< Triggered command/ opened door
		set = {}
		groups = {}
		return
	end
	
	--removes the dying monster from the set
	for k,v in pairs(set) do
		if v == caller.go.id then
			table.remove(set, k)
			break
		end
	end	
end


function _isInGroup(object)
	local answer = false
	for k, grp in pairs(groups) do				
			if	object.level == grp.map and
				object.x == grp.x and 
				object.y == grp.y and
				object.elevation == grp.e then
				answer = true
				break
			end
	end
	return answer
end


delayedCall(self.go.id, .1, "searchGroupMembers")

--Second Pass function:-----[called by delayedCall]------------
	
function searchGroupMembers()
	for _,each in pairs(groups) do
		for object in Dungeon.getMap(each['map']):allEntities() do
			if object.monster then
				if _isInGroup(object) then			
					set[#set+1] = object.id
					_addHooks()
				end 
			end
		end
	end
end


This method requires defining a uniquely named monster for each group. Also... whatever you put in the list (set=) must actually exist on the map when the game starts.

Code: Select all

--monsters.lua

-Groups MUST have "group" followed by a number in their name
--As in the examples group1, group2, group3

defineObject{
	name = "medusa_group1",
	baseObject = "medusa",
	components = {
	},
}

defineObject{
	name = "medusa_group2",
	baseObject = "medusa",
	components = {
	},
}

defineObject{
	name = "ratling_group1",
	baseObject = "ratling1",
	components = {
	},
}

defineObject{
	name = "ratling_group2",
	baseObject = "ratling1",
	components = {
	},
}


Demo Editor Project: https://www.dropbox.com/s/jlo17fxwmula5 ... d.zip?dl=0
Torquemada
Posts: 25
Joined: Fri Apr 05, 2013 10:52 pm

Re: Ask a simple question, get a simple answer

Post by Torquemada »

How do you unlit a torch in a torchholder, I remember I did this is log 1 with the following script

function killTorch()
scripted_torch_2:destroy()
spawn("torch_holder",l,x,y,f):addItem(spawn("torch"):setFuel(0))
end")

This does not work in log 2
User avatar
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

Torquemada wrote:How do you unlit a torch in a torchholder, I remember I did this is log 1 with the following script

function killTorch()
scripted_torch_2:destroy()
spawn("torch_holder",l,x,y,f):addItem(spawn("torch"):setFuel(0))
end")

This does not work in log 2

Code: Select all

torch_holder_1.light:disable()
torch_holder_1.particle:disable()
torch_holder_1.sound:disable()
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Code: Select all

function killTorch()
  scripted_torch_2:destroy()
  local torch = spawn("torch")
  torch.torchitem:setFuel(0)
  spawn("torch_holder",l,x,y,f,elevation).socket:addItem(torch.item)
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
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

What happens if you have a custom torch item, and you use 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 »

Can a conditions description be modified to display data similar to how Rage does it?
My asset pack [v1.10]
Features a bit of everything! :D
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

Isaac wrote:What happens if you have a custom torch item, and you use that?
You replace spawn("torch") with spawn([name of your custom torch item]).

Torquemada wanted a torch holder that contains a burnt-out torch with no fuel. The code you gave does prevent the torch holder from emitting light until the next time a torch is added to it, but the torch will still have full fuel.
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
Isaac
Posts: 3172
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

minmay wrote:Torquemada wanted a torch holder that contains a burnt-out torch with no fuel. The code you gave does prevent the torch holder from emitting light until the next time a torch is added to it, but the torch will still have full fuel.
I missed the part about the fuel.

Do you know anything about zimber's question? I assume it's about the change in status the text when the mouse hovers over the big portrait in the inventory menu. When rage is in effect, it lists the strength bonus instead of the usual health message.
minmay
Posts: 2768
Joined: Mon Sep 23, 2013 2:24 am

Re: Ask a simple question, get a simple answer

Post by minmay »

zimberzimber wrote:Can a conditions description be modified to display data similar to how Rage does it?
No.
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.
bongobeat
Posts: 1076
Joined: Thu May 16, 2013 5:58 pm
Location: France

Re: Ask a simple question, get a simple answer

Post by bongobeat »

Hello there,

my question may be stupid but : what is the difference between the resistance of a monster, "absorb" or "immune"?
My asset pack: viewtopic.php?f=22&t=9320

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