Open door by placing gem on plate or on point of map

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!
Post Reply
Dinasty
Posts: 10
Joined: Tue Oct 02, 2012 6:59 pm

Open door by placing gem on plate or on point of map

Post by Dinasty »

Hi,

can someone give me the lua script to open a door by placing a gem on a specific tile of the map? (without using alcove or altar)

Code: Select all

function itemCheck()
  for item in map:entitiesAt(15, 14) do
    if item.id == "red_gem_1" then
      dungeon_secret_door_1.door:open()
    end
  end
end
I tryed this but doens't work :(
User avatar
Duncan1246
Posts: 404
Joined: Mon Jan 19, 2015 7:42 pm

Re: Open door by placing gem on plate or on point of map

Post by Duncan1246 »

Dinasty wrote:Hi,

can someone give me the lua script to open a door by placing a gem on a specific tile of the map? (without using alcove or altar)

Code: Select all

function itemCheck()
  for item in map:entitiesAt(15, 14) do
    if item.id == "red_gem_1" then
      dungeon_secret_door_1.door:open()
    end
  end
end
I tryed this but doens't work :(
Hi, Dinasty,
Try party.map:entitiesAt(15,14) , it should work
Duncan
The Blue Monastery (LOG1)
download at:http://www.nexusmods.com/grimrock/mods/399/?

Finisterrae(LOG2)
download at:http://www.nexusmods.com/legendofgrimrock2/mods/61/?
minmay
Posts: 2788
Joined: Mon Sep 23, 2013 2:24 am

Re: Open door by placing gem on plate or on point of map

Post by minmay »

surely you want self.go.map or dungeon_secret_door_1.map, not party.map
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
Duncan1246
Posts: 404
Joined: Mon Jan 19, 2015 7:42 pm

Re: Open door by placing gem on plate or on point of map

Post by Duncan1246 »

minmay wrote:surely you want self.go.map or dungeon_secret_door_1.map, not party.map
Hi Minmay,
What difference does it make?
The Blue Monastery (LOG1)
download at:http://www.nexusmods.com/grimrock/mods/399/?

Finisterrae(LOG2)
download at:http://www.nexusmods.com/legendofgrimrock2/mods/61/?
Dinasty
Posts: 10
Joined: Tue Oct 02, 2012 6:59 pm

Re: Open door by placing gem on plate or on point of map

Post by Dinasty »

self.go.map
dungeon_secret_door_1.map
party.map

all of theese works, thank you :D
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Open door by placing gem on plate or on point of map

Post by AndakRainor »

With dungeon_secret_door_1.map you will be sure to test the map in which the door is included. party.map will give you any map where the party currently is, self.go.map any map where the item is, or worst, a nil value if it is not on any map (inventory, container...).
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: Open door by placing gem on plate or on point of map

Post by Isaac »

Dinasty wrote:self.go.map
dungeon_secret_door_1.map
party.map

all of theese works, thank you :D
Duncan1246 wrote:What difference does it make?
It is that party.map is always the current level; [where the party object is]; self.go.map (and dungeon_secret_door_1.map) might not be [it's whatever level the object is on]. So if a script runs while the player is on a different floor than expected (or assumed), then that script can potentially use the wrong map.

If Dinasty's script used party.map, and the party were to drop the item through a pit onto the tile below, then it would fail to detect, because that script would then check for the object on the party's level ( one or more floors above ~in the tile where the pit is). If the party isn't on that level, or leaves the level before the test is performed, then it will not check the correct tile. If the check is on a slow timer, the player might be able to use a pit, teleporter, or a stairway before the itemCheck() test.

**Also: If dungeon_secret_door_1 (or any other object used for its map location) is destroyed, that reference in the script becomes nil; that's something to bear in mind when using it.
The party.map, and self.go.map references never become nil for an active script.
User avatar
Duncan1246
Posts: 404
Joined: Mon Jan 19, 2015 7:42 pm

Re: Open door by placing gem on plate or on point of map

Post by Duncan1246 »

Thanks Andak Raynor and Isaac. This confirms to me that the difference is useful only in limit situations as that quoted by Isaac.
The Blue Monastery (LOG1)
download at:http://www.nexusmods.com/grimrock/mods/399/?

Finisterrae(LOG2)
download at:http://www.nexusmods.com/legendofgrimrock2/mods/61/?
User avatar
Isaac
Posts: 3188
Joined: Fri Mar 02, 2012 10:02 pm

Re: Open door by placing gem on plate or on point of map

Post by Isaac »

Using party.map is generally safe for instant [or trivial] access to the current map when called. The problems can come when one assumes the party's position is on the expected map when the script is run. So if your script relies on timers and/or floor_triggers that aren't activated only by the party, then a more reliable map reference should be used, unless you have a specific reason that the script should always use the party's map location for its actions.

Also... in the case of script_entities: Some use their object's position on the map as a basis for variable coordinates. In this case using self.go will the change if the script if object is moved, (or copied & pasted somewhere else).
Post Reply