How do I make a door open, by putting items on alcoves.

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
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Re: How do I make a door open, by putting items on alcoves.

Post by Mysterious »

Just asking has anyone figured how to do this ? Thxs :)
Gladus
Posts: 9
Joined: Wed Sep 17, 2014 12:45 pm

Re: How do I make a door open, by putting items on alcoves.

Post by Gladus »

Leki wrote:Here is what you looking for. Add both functions in script entity and link Alcove to second one.

General function (check if surface contains item)

Code: Select all

function surfaceContains(surface, item)
	for _,i in surface:contents() do
		if i.go.name == item then return true end
	end
end
Riddle example (link alcove/alcoves to this and define conditions). Under if you can add as many alcoves you wish:

Code: Select all

function openRiddleDoor()
	if surfaceContains(myFirstAlcove.surface, "rock") and
		surfaceContains(mySecondAlcove.surface, "dagger") then
			myRiddleDoor.door:open()
	else
			myRiddleDoor.door:close()
	end
end
[/color]
i am making similar puzzle and i tryed the code you made but it didnt work.
Here is what i wrote: https://www.dropbox.com/s/3yw3vb129ks0q ... 9.jpg?dl=0

i wasnt sure if "" were needed so i tryed whit and whit out them and both failed.
User avatar
Skuggasveinn
Posts: 562
Joined: Wed Sep 26, 2012 5:28 pm

Re: How do I make a door open, by putting items on alcoves.

Post by Skuggasveinn »

you need to also have the surfaceContains function in your script, that's the function you are calling.
Link to all my LoG 2 assets on Nexus.
Link to all my LoG 1 assets on Nexus.
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

Re: How do I make a door open, by putting items on alcoves.

Post by Mysterious »

Well the code that leki wrote works for me, how to destroy the items is on the menu. Like I said b4 if the items are Id correct I can destroy them as I have put in the code, What I need to know is how do you destroy the item(s) without the item Id. It does not mater which rock or dagger goes on the Altar, once the items are placed onto the Altar the are destroyed yeah. This is how I did it LOG 1:

Code: Select all

function checkItems(alcove)

local ent,c
local list = {"rock", "rock"}

table.sort(list)
local inv = table.concat(list,",")
local alcoved = {}
for ent in alcove:containedItems() do
local count = ent:getStackSize()
if count == 0 then count = 1 end
for c = 1, count do
table.insert(alcoved,ent.name)
end
	end
table.sort(alcoved)
local alc = table.concat(alcoved,",")
if inv == alc then

-- My functions here --

dungeon_door_wooden_1:open()

for ent in altar_1:containedItems() do
if ent~=nil then ent:destroy() end
       end

return true
	end
return false
	end
PS: I did not write this code I just used it, I am not that good at coding.
Splint
Posts: 1
Joined: Sat Oct 25, 2014 10:13 pm

Re: How do I make a door open, by putting items on alcoves.

Post by Splint »

Mysterious wrote:Well the code that leki wrote works for me, how to destroy the items is on the menu. Like I said b4 if the items are Id correct I can destroy them as I have put in the code, What I need to know is how do you destroy the item(s) without the item Id. It does not mater which rock or dagger goes on the Altar, once the items are placed onto the Altar the are destroyed yeah. This is how I did it LOG 1:

PS: I did not write this code I just used it, I am not that good at coding.
This code seemed to work for me,


Delete all items from surface:

Code: Select all

function removeItemsFromSurface(surface)
	for _,i in surface:contents() do		
		i.go:destroy()
	end 
end	

Specific Items:

Code: Select all

function removeItemsFromSurface(surface)
	for _,i in surface:contents() do     
		if i.go.name == "rock" then 
			i.go:destroy()
		end
	end 
end 
User avatar
AdrTru
Posts: 223
Joined: Sat Jan 19, 2013 10:10 pm
Location: Trutnov, Czech Republic

Re: How do I make a door open, by putting items on alcoves.

Post by AdrTru »

Hi,
I made script named "help1" with helpfull scripts

Code: Select all

-- return surface of object defined:   
--   a/ by id in text; 
--   b/ object; 
--   c/ object from connector

function getSurface(alcove)
  if type(alcove) == "string" then alcove = findEntity(alcove) end
  if alcove == nil then return nil end
  return alcove.surface or alcove.go.surface
end


--  return count of Items in alcove object

function getItemCount(alcove)
  local surf = getSurface(alcove)
  if surf == nil then return 0 end
  local count = 0
  for _,i in surf:contents() do
    count = count +1
  end
  return count
end


-- return booalen info Is item(name) in alcove?

function surfaceContains(alcove, item)
  local surf = getSurface(alcove)
  if surf == nil then return false end
  for _,i in surf:contents() do
    if i.go.name == item then return true end
  end
  return false
end


-- return count of item(name) in alcove

function surfaceNameCount(alcove, item) 
  local surf = getSurface(alcove)
  if surf == nil then return 0 end
  local count = 0
  for _,i in surf:contents() do
    if i.go.name == item then count = count+1 end
  end
  return count
end


-- destroy all items in alcove

function destroyItems(alcove)
  local surf = getSurface(alcove)
  if surf == nil then return false end
  local it = {}
  for _,i in surf:contents() do
    table.insert(it,i.go.id)
  end
  for i = 1,#it do
    findEntity(it[i]):destroy()
  end
end
When want to use this functions in own scripts its nessesery to make connection on he top of script, like this Mysterious scripts:

Code: Select all



help = help1.script


function checkDag1(self)
  local alcove = findEntity("altar_2")
  if (alcove ~= nil) and (help.getItemCount(alcove)>0) then
    local item 
    for _,item in alcove.surface:contents() do
      if item.go.name == "rock" then

        --- Destroy Items here ---
        alcove:destroy() -- This will Destroy the Altar --
        item.go:destroy() -- Destroy the Key --

        -- HudPrints Here --
        hudPrint("Yes the Yuanti Dagger is mine.")
        party.party:shakeCamera(1,1)

        dungeon_door_wooden_1.door:open()
	  else
        hudPrint("I DONT WANT THAT!")
      end
    end
  end
end

---------------------------

function checkItems(alcove)
  surf = help.getSurface(alcove)
  if surf == nil then return false end
  local ent,c
  local list = {"rock", "rock"}

  table.sort(list)
  local inv = table.concat(list,",")
  local alcoved = {}
  for _,ent in surf:contents() do
    local count = ent:getStackSize()
    if count == 0 then count = 1 end
    for c = 1, count do
      table.insert(alcoved,ent.go.name)
    end
  end
  table.sort(alcoved)
  local alc = table.concat(alcoved,",")
  if inv == alc then

    -- My functions here --
    dungeon_door_wooden_1.door:open()
    help.destroyItems(alcove)

    return true
  end
  return false
end
My LOG2 projects: virtual money, Forge recipes, liquid potions and
MultiAlcoveManager, Toolbox, Graphic text,
Post Reply