Page 1 of 2
Script options to check if party has various items or not
Posted: Fri Feb 08, 2013 9:55 pm
by Conchron
I can't write a working script even if my life depend on it and I have to read through the forum looking for the bits I need. However, I can't find this.
I need to check the party for specific items, golden_crown, golden_dragon and golden_orb and open door1 if the party has all of them and door2 if they don't.
Can anyone help with this script?
Does it help if I tell you that I think you all are fantastic and you make amazing stuff?

I've been lurking around here for months and I still find things that make me go "wow!"

every day.
Re: Can anyone help me with a scrip?
Posted: Fri Feb 08, 2013 10:03 pm
by Filipsan
Conchron wrote:
I need to check the party for specific items, golden_crown, golden_dragon and golden_orb and open door1 if the party has all of them and door2 if they don't.
Can anyone help with this script?
Hi there
Try this:
viewtopic.php?f=14&t=4903&p=52094&hilit ... eck#p52094
or maybe
viewtopic.php?f=14&t=3099&p=31872&hilit ... eck#p31872
Re: Can anyone help me with a scrip?
Posted: Fri Feb 08, 2013 10:07 pm
by Conchron
Thank you Filipsan, but, I've seen those and I can't put them together so that they do what I need them to do.

Re: Can anyone help me with a scrip?
Posted: Sat Feb 09, 2013 4:22 am
by crisman
You can try this, but I warn you, this kind of scripts needs grimq
viewtopic.php?f=14&t=4256&hilit=grimq
because the script I'm going to write will not work if the items are inside sacks, boxes, mortars, ecc...
A script with grimq will provide that kind of stuff, but unfortunately I'm not good using it

Anyway, here's the script, I've tested it and it's working
Code: Select all
function checkItems()
local treasure1 = false
local treasure2 = false
local treasure3 = false
local treasures = {
"golden_crown", "golden_dragon", "golden_orb"}
local checks = {
treasure1, treasure2, treasure3}
for i = 1, 4 do
for j = 1, 31 do
local item = party:getChampion(i):getItem(j)
for k, v in ipairs(treasures) do
if item then
if item.name == v then
checks[k] = true
end
end
end
end
end
for i, v in ipairs(checks) do
if not v then
door2:open()
return
end
end
door1:open()
end
EDIT:
Okay, I've managed to create a code that seek for items even inside sacks, boxes, etc... and seems working good.
Here's the new code.
Code: Select all
function checkItems()
local treasure1 = false
local treasure2 = false
local treasure3 = false
local treasures = {
"golden_crown", "golden_dragon", "golden_orb"}
local checks = {
treasure1, treasure2, treasure3}
for i = 1, 4 do
for j = 1, 31 do
local item = party:getChampion(i):getItem(j)
for k, v in ipairs(treasures) do
if item then
if item.name == "sack" or item.name == "mortar" or item.name == "wooden_box" then
for x in item:containedItems() do
if x then
if x.name == "mortar" then
for y in x:containedItems() do
if y then
if y.name == v then
checks[k] = true
end
end
end
end
end
if x.name == v then
checks[k] = true
end
end
end
if item.name == v then
checks[k] = true
end
end
end
end
end
for i, v in ipairs(checks) do
if not v then
door2:open()
return
end
end
door1:open()
end
Let me know if you have problems

Re: Can anyone help me with a scrip?
Posted: Sat Feb 09, 2013 5:07 am
by Komag
my head just pirouetted across the office!
Re: Can anyone help me with a scrip?
Posted: Sat Feb 09, 2013 12:32 pm
by Conchron
Thank you crisman! That works perfectly.

Re: Can anyone help me with a scrip? (Solved)
Posted: Sat Feb 09, 2013 1:11 pm
by Komag
minor correction to crisman's very good code:
Code: Select all
function checkItems()
local treasure1 = false
local treasure2 = false
local treasure3 = false
local treasures = {
"golden_crown", "golden_dragon", "golden_orb"}
local checks = {
treasure1, treasure2, treasure3}
for i = 1, 4 do
for j = 1, 31 do
local item = party:getChampion(i):getItem(j)
for k, v in ipairs(treasures) do
if item then
if item.name == "sack" or item.name == "mortar" or item.name == "wooden_box" then
for x in item:containedItems() do
if x then
if x.name == "mortar" then
for y in x:containedItems() do
if y then
if y.name == v then
checks[k] = true
end
end
end
end
if x.name == v then
checks[k] = true
end
end
end
end
if item.name == v then
checks[k] = true
end
end
end
end
end
for i, v in ipairs(checks) do
if not v then
door2:open()
return
end
end
door1:open()
end
I just moved an "end" from right before the "if x.name" section to right after it (and adjusted the spacing accordingly), so the "if x" (existence) check above that is still in place for the x.name check
Re: Can anyone help me with a scrip? (Solved)
Posted: Sat Feb 09, 2013 1:35 pm
by Komag
And here's my (squished!) version for a single item:
Code: Select all
function checkGoldOrb()
local goldOrb = false
local n = "golden_orb"
for i = 1, 4 do
for j = 1, 31 do
local item = party:getChampion(i):getItem(j)
if item then
if item.name == "sack" or
item.name == "mortar" or
item.name == "wooden_box" then
for x in item:containedItems() do
if x then
if x.name == "mortar" then
for y in x:containedItems() do
if y then if y.name == n then goldOrb = true end end
end end
if x.name == n then goldOrb = true end
end end end
if item.name == n then goldOrb = true end
end end end
if goldOrb then door1:open() else door2:open() end
end
Re: Script options to check if party has various items or no
Posted: Sat Feb 09, 2013 5:20 pm
by crisman
Thanks Komag, didn't notice that

Its' funny that 5 minutes before writing the code I didn't remember that item:contaniedItems() was added to the editor
Surely for an item is way much more simple, like you did!
Re: Script options to check if party has various items or no
Posted: Mon Mar 11, 2013 4:10 pm
by PoonMoon
Hi everyone,
Just an additional question - is it possible to check for the 'hand' i.e. if you take something from a champs inventory or equipped hands, the cursor (in game) changes to that object. This script does not detect / check that 'hand' - which is scuppering my plans....
Great forum btw - excellent resource, thanks to all for contributing.