A few questions about Editor

Talk about anything Legend of Grimrock 1 related here.
Post Reply
Aranok
Posts: 2
Joined: Thu Feb 27, 2020 5:12 pm

A few questions about Editor

Post by Aranok » Thu Feb 27, 2020 9:11 pm

I need some help with the editor. To ask a few things IF they can be done, and subsequently HOW to script them.

1: Is it possible to get a demon statue mouth slot to only activate when a specific green gem is inserted, rather than just any green gem?

2: Is it possible to have gems spawned in a demon statue eye slot only be removable after a certain trigger, rather than at any given time?

3: Can I change the name of an object in the editor, so that in the game it displays a different name?

4: Can I program a door to be opened once certain monsters have been killed?

If anyone can advise me on this, it would be greatly appreciated and help me with the creation of a level.

Zo Kath Ra
Posts: 827
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: A few questions about Editor

Post by Zo Kath Ra » Thu Feb 27, 2020 10:02 pm

Aranok wrote:
Thu Feb 27, 2020 9:11 pm
I need some help with the editor. To ask a few things IF they can be done, and subsequently HOW to script them.

1: Is it possible to get a demon statue mouth slot to only activate when a specific green gem is inserted, rather than just any green gem?

2: Is it possible to have gems spawned in a demon statue eye slot only be removable after a certain trigger, rather than at any given time?

3: Can I change the name of an object in the editor, so that in the game it displays a different name?

4: Can I program a door to be opened once certain monsters have been killed?

If anyone can advise me on this, it would be greatly appreciated and help me with the creation of a level.
1:
- Place a daemon_head or daemon_head_eye_sockets
- Place a mouth_socket at the same location
- Place a script_entity anywhere in the level; you can place the script entity in another level, but placing it in the same level makes things less confusing; you can use an existing script entity, as long as the function name is unique within the script entity
- Put this code in the script entity:

Code: Select all

function onInsertItem(self)
	for i in self:containedItems() do
		if (i.id == "green_gem_1") then
			-- This action is executed when you insert "green_gem_1" into the mouth_socket
			dungeon_door_iron_1:open()
		end
	end
end
- In the mouth_socket, add a connector; Event = activate, Target = the script_entity, Action = onInsertItem

2:
- Place a daemon_head_eye_sockets
- Place an eye_socket_left or eye_socket_right at the same location
- Place a script_entity anywhere in the level; you can place the script entity in another level, but placing it in the same level makes things less confusing; you can use an existing script entity, as long as the function name is unique within the script entity
- Put this code in the script entity:

Code: Select all

function onRemoveItem(self)
	local mouseItem = getMouseItem()
	
	-- This condition determines whether you can take the gem out of the eye socket
	if (counter_1:getValue() > 0) then
		-- Put the gem back in the eye socket
		self:addItem(mouseItem)
		
		-- Remove the gem from the mouse cursor, so it doesn't exist twice in the game
		setMouseItem(nil)
		
		-- Display a helpful warning message
		hudPrint("You can't take the gem because counter_1's value is > 0")
	end
end
- In the eye_socket_*, add a connector; Event = deactivate, Target = the script_entity, Action = onRemoveItem

3:
As far as I know, you can't change an object's name with a script.
You need to use cloneObject{…} to define a new type of object with a different name:
http://www.grimrock.net/modding_log1/as ... reference/ -> Dungeon Objects -> cloneObject{…}
(AFAIK you must do this in one of the mod's LUA files that are loaded in init.lua, such as items.lua)
For example, put this code in your mod's items.lua:

Code: Select all

cloneObject{
	name = "sword_of_slaying",
	baseObject = "long_sword",
	uiName = "Sword of Slaying",
	attackPower = 99,
	coolDownTime = 1.0,	
}
4:
todo

I'm sure someone else will come along and post better solutions.
These solutions will probably involve:
http://www.grimrock.net/modding_log1/ -> Custom Assets

Aranok
Posts: 2
Joined: Thu Feb 27, 2020 5:12 pm

Re: A few questions about Editor

Post by Aranok » Thu Feb 27, 2020 11:39 pm

Thank you very much. This should atleast get me started.

User avatar
Isaac
Posts: 2936
Joined: Fri Mar 02, 2012 10:02 pm

Re: A few questions about Editor

Post by Isaac » Fri Feb 28, 2020 4:57 am

For #4

Quick method:
SpoilerShow
Nevermind the quick method. ;)
________________________________________________
Alternate method:

Code: Select all

cloneObject{
	--use or replace 'snail' with whatever monster name is preferred.
	name = "gate_monster_snail",
	baseObject = "snail", 
	onDie = function()  
				if findEntity("monster_count") and monster_count:getValue() > 1 then
					monster_count:decrement(1) 
					return
				end
				if 	findEntity("monster_gate") then monster_gate:open() end
			end 
}
Place this script in scripts/monster.lua
Save the file, and reload the project.
Place one or more gate_monsters, and one door with the ID of 'monster_gate'.
Place a counter on the map, and assign it the id 'monster_count'; set its value to the number of gate_monsters.

If you would like there to be different kinds of gate monsters, then you must duplicate the above script for each monster, and update the name, and baseObject string values with the new monster name.
Last edited by Isaac on Fri Feb 28, 2020 5:39 am, edited 2 times in total.

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

Re: A few questions about Editor

Post by minmay » Fri Feb 28, 2020 5:35 am

Isaac wrote:
Fri Feb 28, 2020 4:57 am
For #4

Quick method:

Code: Select all

cloneObject{
	--use or replace 'snail' with whatever monster name is preferred.
	name = "gate_monster_snail",
	baseObject = "snail", 
	onDie = function(self)  
				local gate_monsters = 0
				for monster in allEntities(self.level) do
					if monster.name == self.name then gate_monsters = gate_monsters + 1 end
				end
				if gate_monsters < 2 then monster_gate:open() end
			end 
}
Rename the door to monster_gate.
Do not use this method. The allEntities() function doesn't work if the player has made a map note on the level. See viewtopic.php?f=14&t=5672.

The alternate method you gave is fine, though. Note that the decrement() method doesn't actually use any arguments, it always decrements by 1.
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: 2936
Joined: Fri Mar 02, 2012 10:02 pm

Re: A few questions about Editor

Post by Isaac » Fri Feb 28, 2020 5:38 am

Good call, I had actually forgotten about the debacle it caused in the ORRR2. The quick method was my second choice; a revision of the first.
Thanks for pointing it out.

Post Reply