Page 1 of 1

A few questions about Editor

Posted: Thu Feb 27, 2020 9:11 pm
by Aranok
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.

Re: A few questions about Editor

Posted: Thu Feb 27, 2020 10:02 pm
by Zo Kath Ra
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

Re: A few questions about Editor

Posted: Thu Feb 27, 2020 11:39 pm
by Aranok
Thank you very much. This should atleast get me started.

Re: A few questions about Editor

Posted: Fri Feb 28, 2020 4:57 am
by Isaac
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.

Re: A few questions about Editor

Posted: Fri Feb 28, 2020 5:35 am
by minmay
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.

Re: A few questions about Editor

Posted: Fri Feb 28, 2020 5:38 am
by Isaac
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.