Jump to content

Recommended Posts

Hello, I need help :)... So, I know there are some other night vision topics out there but i'm really dumb & couldn't understand or get those to work for me (crash, crash, crash). So, i'm really dumb I had to make my own topic on how can I add night vision to my character :(...

So, if someone can help me :)! I'd like my character to have a plain simple night vision for when hhe goes insane & loses it when not insane that's literally all, if anyone can help me I would cry tears of joy!

Thank you so, so much for reading my problem!! I wish you have a amazing, wonderful, fantanstic day/night :D!!!!!!!!!!!!!!!

Edited by SuperDavid

I can't make the sanity part but i can give you the nightvision code that Works, you test it yourself to see that is working and then you modify it to your desier maybe with the help of the amazing coders in this fórum.

 

This goes into your modmain,lua

--Darkxero's code

local function UpdateNightVision(inst)
	local enable = GLOBAL.TheWorld.state.phase == "night" and inst.discordnightvision:value()
	inst.components.playervision:ForceNightVision(enable)
	inst.components.playervision:SetCustomCCTable(enable and {} or nil)
end

local function OnInitNightVision(inst)
	if GLOBAL.TheWorld.ismastersim or inst.HUD then
		inst:WatchWorldState("phase", UpdateNightVision)
		inst:ListenForEvent("discordnightvisiondirty", UpdateNightVision)
		UpdateNightVision(inst)
	end
end

AddPlayerPostInit(function(inst)
	-- Sword nightvision
	inst.discordnightvision = GLOBAL.net_bool(inst.GUID, "player.discordnightvision", "discordnightvisiondirty")
	inst.discordnightvision:set(false)
	inst:DoTaskInTime(0, OnInitNightVision)
end

And this i used it in my item:

   local function OnEquip(inst, owner) 
	     owner.discordnightvision:set(true)
    end

   local function OnUnEquip(inst, owner) 
	     owner.discordnightvision:set(false)
    end

This is so when i equip the item i get nightvision, and lose it when i unequip it.

Hope it helps you, the code i got it from @DarkXero so i take no credit for it, thanks him. :D

13 minutes ago, SuperDavid said:

Unfortunately, it seems this code is for items only, I think... Tt doesn't work on my character at all (edited a litte but still crashedR9mG9xk.gif) but thanks so much for replying & trying to help me :D!!

instead of owner.discordnightvision:set(true)" i would use "inst.discordnightvision:set(true)" since "owner" is for ítems, "inst" would be posible to install in the char.lua so go ahed and try adding that code to the common_postinit.

Edited by Jpianist
9 minutes ago, Jpianist said:

instead of owner.discordnightvision:set(true)" i would use "inst.discordnightvision:set(true)" since "owner" is for ítems, "inst" would be posible to install in the char.lua

I did that but it didn't work, I guess will both have to wait for someone with more skill than us to help us :lol:...

8 minutes ago, SuperDavid said:

I did that but it didn't work, I guess will both have to wait for someone with more skill than us to help us :lol:...

Yeah :lol::lol: Allthough it might be easier for the pros to help if you give us the error you get when the game is crashing with the line that the game suggest is the problem.

I'm done for today :lol: but tomorrow i'll try this myself.

This message is a Microsoft edge mistake, it wasn't ment to be sent.

EDIT: Now that is sent... Well ill tell you something extra.

Add this :

local function common_postinit(inst)
inst:DoTaskInTime(0, OnInitNightVision)
end

Edited by Jpianist
This message was sent by browser error
local function UpdateNightVision(inst)
	local phase = TheWorld.state.phase
	local iscrazy = not inst.replica.sanity:IsSane()
	local enable = phase == "night" and iscrazy
	if enable ~= inst.components.playervision.forcenightvision then
		inst:DoTaskInTime(enable and 0 or 1, function(inst)
			inst.components.playervision:ForceNightVision(enable)
			inst.components.playervision:SetCustomCCTable(enable and {} or nil)
		end)
	end
end

local function OnInitNightVision(inst)
	if TheWorld.ismastersim or inst.HUD then
		inst:WatchWorldState("phase", UpdateNightVision)
		inst:ListenForEvent("sanitydelta", UpdateNightVision)
		UpdateNightVision(inst)
	end
end

local function common_postinit(inst)
	inst:DoTaskInTime(0, OnInitNightVision)
end

I posted character examples already.

  • Like 1

@DarkXero Thanks so much :D! If I can ask one more question would it be possible to make the night vision a little darker? Maybe more like this

20160822222147_1.jpg

because my character screen is super bright as if it's morning with this night vision but if it's not possible that's 100% fine :D

20160822235757_1.jpg

Edited by SuperDavid
local NIGHTVISION_COLOURCUBES = {
	day = "images/colour_cubes/mole_vision_off_cc.tex",
	dusk = "images/colour_cubes/mole_vision_on_cc.tex",
	night = "images/colour_cubes/mole_vision_on_cc.tex",
	full_moon = "images/colour_cubes/mole_vision_off_cc.tex",
}

local function UpdateNightVision(inst)
	local phase = TheWorld.state.phase
	local iscrazy = not inst.replica.sanity:IsSane()
	local enable = phase == "night" and iscrazy
	if enable ~= inst.components.playervision.forcenightvision then
		inst:DoTaskInTime(enable and 0 or 1, function(inst)
			inst.components.playervision:ForceNightVision(enable)
			inst.components.playervision:SetCustomCCTable(enable and NIGHTVISION_COLOURCUBES or nil)
		end)
	end
end

Like this?

51 minutes ago, DarkXero said:

local NIGHTVISION_COLOURCUBES = {
	day = "images/colour_cubes/mole_vision_off_cc.tex",
	dusk = "images/colour_cubes/mole_vision_on_cc.tex",
	night = "images/colour_cubes/mole_vision_on_cc.tex",
	full_moon = "images/colour_cubes/mole_vision_off_cc.tex",
}

local function UpdateNightVision(inst)
	local phase = TheWorld.state.phase
	local iscrazy = not inst.replica.sanity:IsSane()
	local enable = phase == "night" and iscrazy
	if enable ~= inst.components.playervision.forcenightvision then
		inst:DoTaskInTime(enable and 0 or 1, function(inst)
			inst.components.playervision:ForceNightVision(enable)
			inst.components.playervision:SetCustomCCTable(enable and NIGHTVISION_COLOURCUBES or nil)
		end)
	end
end

Like this?

@DarkXero That made all the colors weird xD

20160822235821_1.jpg

So I guess it's not possible to make it darker but thanks you are a huge help :D!!!! Maybe would it be possible I make my own custom color cube or something or is that super hard?

Edited by SuperDavid
5 minutes ago, Lokoluna said:

Where does it exactly go?

In your character.lua file.

local function common_postinit(inst)
	inst:DoTaskInTime(0, OnInitNightVision)
end

common_postinit is a function that belongs there.

Maybe you saw it as

local common_postinit = function(inst)
end

but it's the same.

16 minutes ago, DarkXero said:

In your character.lua file.

common_postinit is a function that belongs there.

Maybe you saw it as

but it's the same.

Pasted it in my character.lua file, and it ceases to work. it goes pitch black and night, and i take damage like normal.

1 minute ago, Lokoluna said:

Pasted it in my character.lua file, and it ceases to work. it goes pitch black and night, and i take damage like normal.

Right, that code has a caveat, you have to be insane for it to work.

local function UpdateNightVision(inst)
	local phase = TheWorld.state.phase
	local enable = phase == "night"
	if enable ~= inst.components.playervision.forcenightvision then
		inst:DoTaskInTime(enable and 0 or 1, function(inst)
			inst.components.playervision:ForceNightVision(enable)
			inst.components.playervision:SetCustomCCTable(enable and {} or nil)
		end)
	end
end

local function OnInitNightVision(inst)
	if TheWorld.ismastersim or inst.HUD then
		inst:WatchWorldState("phase", UpdateNightVision)
		UpdateNightVision(inst)
	end
end

local function common_postinit(inst)
	inst:DoTaskInTime(0, OnInitNightVision)
end

This just cares about the night.

9 minutes ago, DarkXero said:

Right, that code has a caveat, you have to be insane for it to work.

This just cares about the night.

local common_postinit = function(inst)
    -- Minimap icon
    inst.MiniMapEntity:SetIcon( "kutsil.tex" )
    
    inst:AddTag("valkyrie")
    
    local function UpdateNightVision(inst)
    local phase = TheWorld.state.phase
    local enable = phase == "night"
    if enable ~= inst.components.playervision.forcenightvision then
        inst:DoTaskInTime(enable and 0 or 1, function(inst)
            inst.components.playervision:ForceNightVision(enable)
            inst.components.playervision:SetCustomCCTable(enable and {} or nil)
        end)
    end
end

local function OnInitNightVision(inst)
    if TheWorld.ismastersim or inst.HUD then
        inst:WatchWorldState("phase", UpdateNightVision)
        UpdateNightVision(inst)
    end
end

local function common_postinit(inst)
    inst:DoTaskInTime(0, OnInitNightVision)
end
    
end

this is my current code in my char.lua common postinit, but I do not gain night vision wether insane or non insane, I wish to gaint night vision whether i am sane or not, But I don't know if i'm doing something wrong.. or if coding is conflicting with one another.

Edited by Lokoluna
5 minutes ago, Lokoluna said:

But I don't know if i'm doing something wrong.. or if coding is conflicting with one another.

local function UpdateNightVision(inst)
	local phase = TheWorld.state.phase
	local enable = phase == "night"
	if enable ~= inst.components.playervision.forcenightvision then
		inst:DoTaskInTime(enable and 0 or 1, function(inst)
			inst.components.playervision:ForceNightVision(enable)
			inst.components.playervision:SetCustomCCTable(enable and {} or nil)
		end)
	end
end

local function OnInitNightVision(inst)
	if TheWorld.ismastersim or inst.HUD then
		inst:WatchWorldState("phase", UpdateNightVision)
		UpdateNightVision(inst)
	end
end

local common_postinit = function(inst)
	-- Minimap icon
	inst.MiniMapEntity:SetIcon( "kutsil.tex" )

	inst:AddTag("valkyrie")

	inst:DoTaskInTime(0, OnInitNightVision)
end

 

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...