Jump to content

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?

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...