How do I make a door open, by putting items on alcoves.
- Mysterious
- Posts: 226
- Joined: Wed Nov 06, 2013 8:31 am
Re: How do I make a door open, by putting items on alcoves.
Just asking has anyone figured how to do this ? Thxs
Re: How do I make a door open, by putting items on alcoves.
i am making similar puzzle and i tryed the code you made but it didnt work.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)Riddle example (link alcove/alcoves to this and define conditions). Under if you can add as many alcoves you wish:Code: Select all
function surfaceContains(surface, item) for _,i in surface:contents() do if i.go.name == item then return true end end end
[/color]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
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.
- Skuggasveinn
- Posts: 562
- Joined: Wed Sep 26, 2012 5:28 pm
Re: How do I make a door open, by putting items on alcoves.
you need to also have the surfaceContains function in your script, that's the function you are calling.
- Mysterious
- Posts: 226
- Joined: Wed Nov 06, 2013 8:31 am
Re: How do I make a door open, by putting items on alcoves.
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.
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
Re: How do I make a door open, by putting items on alcoves.
This code seemed to work for me,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.
Delete all items from surface:
Code: Select all
function removeItemsFromSurface(surface)
for _,i in surface:contents() do
i.go:destroy()
end
end
Code: Select all
function removeItemsFromSurface(surface)
for _,i in surface:contents() do
if i.go.name == "rock" then
i.go:destroy()
end
end
end
Re: How do I make a door open, by putting items on alcoves.
Hi,
I made script named "help1" with helpfull scripts
When want to use this functions in own scripts its nessesery to make connection on he top of script, like this Mysterious scripts:
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
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,
MultiAlcoveManager, Toolbox, Graphic text,