Page 1 of 1

Checking content in hands + Spell light is active [Solved]

Posted: Thu Dec 04, 2014 5:23 pm
by Jouki
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

Re: Checking content in hands

Posted: Thu Dec 04, 2014 6:20 pm
by mahric
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

Re: Checking content in hands

Posted: Thu Dec 04, 2014 10:49 pm
by Jouki
mahric 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
this line sends error

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

Posted: Fri Dec 05, 2014 12:57 am
by Isaac
Jouki wrote:..."getItem a nil value", I have no idea why is it doing, it looks everything is right...
*I was wrong... I get a different error...

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
It should [when the button is pressed] print true or false ~whether anyone has a torch equipped. It's a neat script. 8-)

Re: Checking content in hands

Posted: Fri Dec 05, 2014 1:36 am
by Grimfan
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

Posted: Fri Dec 05, 2014 3:45 am
by Jouki
Isaac wrote:
Jouki wrote:..."getItem a nil value", I have no idea why is it doing, it looks everything is right...
*I was wrong... I get a different error...

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
It should [when the button is pressed] print true or false ~whether anyone has a torch equipped. It's a neat script. 8-)

oh god, idk if I was calling wrong function, nevermind it works (printing true/false) :) btw could you write script checking if the spell "light" is actived, please? ^^

Re: Checking content in hands

Posted: Fri Dec 05, 2014 4:58 am
by Isaac
Jouki wrote: btw could you write script checking if the spell "light" is actived, please? ^^
I don't know if that's possible; it was not [really] possible in LoG1.

Re: Checking content in hands

Posted: Fri Dec 05, 2014 5:46 am
by minmay

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

Re: Checking content in hands

Posted: Fri Dec 05, 2014 6:16 am
by Isaac
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
This is new...
Worked out from the light components in the asset pack definitions? Very neat. 8-)

Re: Checking content in hands

Posted: Fri Dec 05, 2014 1:32 pm
by Jouki
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
wow, thanks. It's much easier way to figure out.