Jump to content

Help nightvision when holding item


Seilakk

Recommended Posts

I am working on a char that has night vision when holding a torch, i already have a nightvision code that works at night but i want it to only work when i equip a torch

Spoiler

local FODASE =
{
    night = "images/colour_cubes/purple_moon_cc.tex",
    full_moon = "images/colour_cubes/purple_moon_cc.tex",
}

local function toneiai(inst, enable)
    if TheWorld.state.isnight or TheWorld:HasTag("cave") then
        inst.components.playervision:ForceNightVision(true)
        inst.components.playervision:SetCustomCCTable(FODASE)
    else
        inst.components.playervision:ForceNightVision(false)
        inst.components.playervision:SetCustomCCTable(nil)
    end
end

local function common_init(inst)
	toneiai(inst)
	inst:WatchWorldState( "isday", function() toneiai(inst) end)
  	inst:WatchWorldState( "isdusk", function() toneiai(inst) end)
  	inst:WatchWorldState( "isnight", function() toneiai(inst)  end)
	inst:WatchWorldState( "iscaveday", function() toneiai(inst) end)
  	inst:WatchWorldState( "iscavedusk", function() toneiai(inst) end)
  	inst:WatchWorldState( "iscavenight", function() toneiai(inst)  end)
end

 

Could anyone help me?

Link to comment
Share on other sites

I think that using something like this may work...

local function equiptorch(inst)
local hand = inst.replica.inventory:GetEquippedItem(EQUIPSLOTS.HANDS)
	if hand.prefab == "torch" then
		inst:DoTaskInTime(0.0, function()
			if TheWorld.state.isnight or TheWorld:HasTag("cave") then
				inst.components.playervision:ForceNightVision(true)
				inst.components.playervision:SetCustomCCTable(FODASE)
			else
				inst.components.playervision:ForceNightVision(false)
				inst.components.playervision:SetCustomCCTable(nil)
			end
		end)
	end
end


inst:ListenForEvent("equip", equiptorch)

One problem I can see with using this is that you will need to reequip the torch to update it if you equip it before night.

I'm sorry if this doesn't help, I thought id try.

-Taps

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...