Re: Detect light level
Posted: Thu Nov 22, 2012 10:55 pm
There you go!
This should go in objects.lua
then this should go in a script entity named lightTracker
You then need to put a 0.25 interval timer on every level that activates lightTracker.lightTrack()
There is a lightLevel variable which goes from -600 to 600 and expresses light/darkness remaining time. You can access it directly in other scripts/script entities through lightTracker.lightLevel.
I've also provided a function to easily check light, which you can call through lightTracker.lightState(). It checks for active light and darkness spells, if champions carry any active torches or magic orb, and interactions between torches and spells, and returns true or false. (For example, if you carry a torch in the hand, but a Darkness spell is active, it will return false). An example usage:
lightState() doesn't check for wall torches, of course, but these can be easily taken into acount separately.
Enjoy!
Credits to LordYig's darkness zone script from which I borrowed and modified some elements for the above code.
This should go in objects.lua
SpoilerShow
Code: Select all
cloneObject{
name = "party",
baseObject = "party",
onCastSpell = function(caster, spell)
return lightTracker.spellTrack(caster, spell)
end,
}SpoilerShow
Code: Select all
lightLevel = 0
function lightTrack(sourceTimer)
if sourceTimer.level == party.level then
if lightLevel > 0 then
lightLevel = lightLevel - 0.25
elseif lightLevel < 0 then
lightLevel = lightLevel + 0.25
end
end
end
function spellTrack(caster, spell)
if spell == "light" then
if lightLevel >= 0 then
lightLevel = 600
elseif lightLevel < 0 then
lightLevel = 0
end
end
if spell == "darkness" then
if lightLevel > 0 then
lightLevel = 0
elseif lightLevel <= 0 then
lightLevel = -600
end
end
end
function lightState()
local lightReturn = false
local currentItem
local champion
for champID=1,4 do
champion = party:getChampion(champID)
currentItem = champion:getItem(7)
if currentItem ~= nil then
if currentItem.name == "torch"
or currentItem.name == "torch_everburning"
or currentItem.name == "magic_orb" then
lightReturn = true
end
end
currentItem = champion:getItem(8)
if currentItem ~= nil then
if currentItem.name == "torch"
or currentItem.name == "torch_everburning"
or currentItem.name == "magic_orb" then
lightReturn = true
end
end
end
if lightLevel > 0 then
lightReturn = true
end
if lightLevel < 0 then
lightReturn = false
end
return lightReturn
endThere is a lightLevel variable which goes from -600 to 600 and expresses light/darkness remaining time. You can access it directly in other scripts/script entities through lightTracker.lightLevel.
I've also provided a function to easily check light, which you can call through lightTracker.lightState(). It checks for active light and darkness spells, if champions carry any active torches or magic orb, and interactions between torches and spells, and returns true or false. (For example, if you carry a torch in the hand, but a Darkness spell is active, it will return false). An example usage:
SpoilerShow
Code: Select all
function lightTest()
if lightTracker.lightState() == true then
hudPrint("There is Light")
end
if lightTracker.lightState() == false then
hudPrint("It is dark")
end
endEnjoy!
Credits to LordYig's darkness zone script from which I borrowed and modified some elements for the above code.