Checking contents of champions' inventory
Posted: Mon Nov 03, 2014 1:58 am
Hello
I'm trying to make a script that checks if the champions have a particular item in inventory. There is a script for this in the "Useful scripts repository" thread for Grimrock 1, but it doesn't work in Grim 2 as is. Here's what I have so far:
First, I have the two functions from the post above.
To fix an error, I modified party:getChampion(i) to party.party:getChampion(i)
Then I want to check if the party is holding the skeleton figurine and if so set a variable to false, so I have:
This all runs now without any error, but the function never returns true. I used some print statements, and found that itemObj.name is always "nil"
My guess is that champion.getItem() doesn't work in Grim 2 but I don't know how to fix it.
I'm trying to make a script that checks if the champions have a particular item in inventory. There is a script for this in the "Useful scripts repository" thread for Grimrock 1, but it doesn't work in Grim 2 as is. Here's what I have so far:
First, I have the two functions from the post above.
To fix an error, I modified party:getChampion(i) to party.party:getChampion(i)
Code: Select all
function checkForItemParty(item)
local i = 1
repeat
if checkForItem(party.party:getChampion(i), item) then
return true
end
i = i + 1
until i == 5
return false
end
function checkForItem(champion, item)
local i = 1
repeat
local itemObj = champion:getItem(i)
if itemObj ~= nil then
if itemObj.name == item then
return true
end
end
i = i+1
until i == 32
return false
end
Code: Select all
if checkForItemParty("figure_skeleton") then
ok_to_pass = false
end
My guess is that champion.getItem() doesn't work in Grim 2 but I don't know how to fix it.