Checking content in hands + Spell light is active [Solved]
Checking content in hands + Spell light is active [Solved]
Hello, can you someone help me how can I get information if the party holds the torch in hand? I would like to create codnition if there's (or not) a light in room do something
Last edited by Jouki on Fri Dec 05, 2014 4:30 pm, edited 1 time in total.
Re: Checking content in hands
Jouki, I think the torchEquipped() script below should do the trick.
It checks all the champions with an item in their hand with the "TorchItemComponent", which should for all torches.
However, there might be other items with lightsources that don't have this component. This script does not check for those.
It checks all the champions with an item in their hand with the "TorchItemComponent", which should for all torches.
However, there might be other items with lightsources that don't have this component. This script does not check for those.
Code: Select all
function torchEquipped()
local hasTorch = false
for i = 1,4 do
local c = party.party:getChampionByOrdinal(i)
hasTorch = hasTorch or checkSlotForTorch(c, 1) or checkSlotForTorch(c, 2)
end
return hasTorch
end
function checkSlotForTorch(champion, slot)
local torchInSlot = false
local j = champion:getItem(slot)
if j then
torchInSlot = (j.go:getComponent("torchitem") ~= nil)
end
return torchInSlot
end
Did you visit the Wine Merchant's Basement? And heard about the Awakening of Taarnab?
Re: Checking content in hands
this line sends errormahric wrote:Jouki, I think the torchEquipped() script below should do the trick.
It checks all the champions with an item in their hand with the "TorchItemComponent", which should for all torches.
However, there might be other items with lightsources that don't have this component. This script does not check for those.
Code: Select all
function torchEquipped() local hasTorch = false for i = 1,4 do local c = party.party:getChampionByOrdinal(i) hasTorch = hasTorch or checkSlotForTorch(c, 1) or checkSlotForTorch(c, 2) end return hasTorch end function checkSlotForTorch(champion, slot) local torchInSlot = false local j = champion:getItem(slot) if j then torchInSlot = (j.go:getComponent("torchitem") ~= nil) end return torchInSlot end
local j = champion:getItem(slot)
"getItem a nil value", I have no idea why is it doing, it looks everything is right...
Re: Checking content in hands
*I was wrong... I get a different error...Jouki wrote:..."getItem a nil value", I have no idea why is it doing, it looks everything is right...
Ah... This happened when I called the wrong function.
Try this:
Temporarily add this to the script and call it with a button.
Code: Select all
function check()
print(torchEquipped())
end

Re: Checking content in hands
You have probably linked both functions to the same floor trigger. The torchEquipped function calls on the checkSlotForTorch function (which doesn't need to be connected up). Because you've linked the second function it's running twice, but in the second instance it doesn't know what item in what slot it's supposed to be looking for (the torch called by the first function).
Re: Checking content in hands
Isaac wrote:*I was wrong... I get a different error...Jouki wrote:..."getItem a nil value", I have no idea why is it doing, it looks everything is right...
Ah... This happened when I called the wrong function.
Try this:
Temporarily add this to the script and call it with a button.It should [when the button is pressed] print true or false ~whether anyone has a torch equipped. It's a neat script.Code: Select all
function check() print(torchEquipped()) end
oh god, idk if I was calling wrong function, nevermind it works (printing true/false)

Re: Checking content in hands
I don't know if that's possible; it was not [really] possible in LoG1.Jouki wrote: btw could you write script checking if the spell "light" is actived, please? ^^
Re: Checking content in hands
Code: Select all
-- Returns true if the Light spell is activated.
function lightSpellOn()
-- no light source: 0.1, 0.13, 0.25
-- torch: 1.2, 0.8, 0.6
-- light spell: 0.56, 0.75, 1.2
-- both: 1.76, 1.55, 1.8
return party.torch:getColor()[3] > 1.19
end
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.
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Re: Checking content in hands
This is new...minmay wrote:Code: Select all
-- Returns true if the Light spell is activated. function lightSpellOn() -- no light source: 0.1, 0.13, 0.25 -- torch: 1.2, 0.8, 0.6 -- light spell: 0.56, 0.75, 1.2 -- both: 1.76, 1.55, 1.8 return party.torch:getColor()[3] > 1.19 end
Worked out from the light components in the asset pack definitions? Very neat.

Re: Checking content in hands
wow, thanks. It's much easier way to figure out.minmay wrote:Code: Select all
-- Returns true if the Light spell is activated. function lightSpellOn() -- no light source: 0.1, 0.13, 0.25 -- torch: 1.2, 0.8, 0.6 -- light spell: 0.56, 0.75, 1.2 -- both: 1.76, 1.55, 1.8 return party.torch:getColor()[3] > 1.19 end