FrontierHero Posted February 25, 2017 Share Posted February 25, 2017 So, on the mod I've been working on, I've been wanting to add night vision. My character is an android, and his eyes work as lenses; they adjust to light. I wanted to be able to add this mechanic into the game, so I asked about this before, and got a response. So I added in what I was told to add, where I was told to put it in. I played the game to see if it would work, and unless it doesn't turn on automatically and you have to do something for it to work, the code is not allowing the character to have night vision. I was told to add this into the character's .lua file, above the master_postit/master_postinit: Spoiler local NIGHTVISION_COLOURCUBES = { day = "images/colour_cubes/ruins_light_cc.tex", dusk = "images/colour_cubes/ruins_dim_cc.tex", night = "images/colour_cubes/purple_moon_cc.tex", full_moon = "images/colour_cubes/purple_moon_cc.tex", } local function SetNightVision(inst, enable) if TheWorld.state.isnight or TheWorld:HasTag("cave") then inst.components.playervision:ForceNightVision(true) inst.components.playervision:SetCustomCCTable(NIGHTVISION_COLOURCUBES) else inst.components.playervision:ForceNightVision(false) inst.components.playervision:SetCustomCCTable(nil) end end -- This initializes for both the server and client. Tags can be added here. local common_postinit = function(inst) inst:WatchWorldState( "isday", function() SetNightVision(inst) end) inst:WatchWorldState( "isdusk", function() SetNightVision(inst) end) inst:WatchWorldState( "isnight", function() SetNightVision(inst) end) inst:WatchWorldState( "iscaveday", function() SetNightVision(inst) end) inst:WatchWorldState( "iscavedusk", function() SetNightVision(inst) end) inst:WatchWorldState( "iscavenight", function() SetNightVision(inst) end) SetNightVision(inst) end is this wrong? if so, what do I need to fix in order to provide night vision to the character? thank you for your help! Link to comment Share on other sites More sharing options...
AkaiNight Posted February 25, 2017 Share Posted February 25, 2017 try this local function NightVision(inst) if TheWorld.state.isnight then inst.Light:Enable(true) inst.Light:SetRadius(18) inst.Light:SetFalloff(0.75) inst.Light:SetIntensity(.7) inst.Light:SetColour(70/255,230/255,12/170) end end and put this into local master_postinit = function(inst) inst:WatchWorldState("isnight", NightVision) 1 Link to comment Share on other sites More sharing options...
Leonardo Cox Posted February 25, 2017 Share Posted February 25, 2017 9 hours ago, FrontierHero said: So, on the mod I've been working on, I've been wanting to add night vision. My character is an android, and his eyes work as lenses; they adjust to light. I wanted to be able to add this mechanic into the game, so I asked about this before, and got a response. So I added in what I was told to add, where I was told to put it in. I played the game to see if it would work, and unless it doesn't turn on automatically and you have to do something for it to work, the code is not allowing the character to have night vision. I was told to add this into the character's .lua file, above the master_postit/master_postinit: Hide contents local NIGHTVISION_COLOURCUBES = { day = "images/colour_cubes/ruins_light_cc.tex", dusk = "images/colour_cubes/ruins_dim_cc.tex", night = "images/colour_cubes/purple_moon_cc.tex", full_moon = "images/colour_cubes/purple_moon_cc.tex", } local function SetNightVision(inst, enable) if TheWorld.state.isnight or TheWorld:HasTag("cave") then inst.components.playervision:ForceNightVision(true) inst.components.playervision:SetCustomCCTable(NIGHTVISION_COLOURCUBES) else inst.components.playervision:ForceNightVision(false) inst.components.playervision:SetCustomCCTable(nil) end end -- This initializes for both the server and client. Tags can be added here. local common_postinit = function(inst) inst:WatchWorldState( "isday", function() SetNightVision(inst) end) inst:WatchWorldState( "isdusk", function() SetNightVision(inst) end) inst:WatchWorldState( "isnight", function() SetNightVision(inst) end) inst:WatchWorldState( "iscaveday", function() SetNightVision(inst) end) inst:WatchWorldState( "iscavedusk", function() SetNightVision(inst) end) inst:WatchWorldState( "iscavenight", function() SetNightVision(inst) end) SetNightVision(inst) end is this wrong? if so, what do I need to fix in order to provide night vision to the character? thank you for your help! This should give you nightvision once it turns night (or when you enter caves). Is it not working? Link to comment Share on other sites More sharing options...
RedHairedHero Posted February 25, 2017 Share Posted February 25, 2017 13 hours ago, FrontierHero said: So, on the mod I've been working on, I've been wanting to add night vision. My character is an android, and his eyes work as lenses; they adjust to light. I wanted to be able to add this mechanic into the game, so I asked about this before, and got a response. So I added in what I was told to add, where I was told to put it in. I played the game to see if it would work, and unless it doesn't turn on automatically and you have to do something for it to work, the code is not allowing the character to have night vision. I was told to add this into the character's .lua file, above the master_postit/master_postinit: Reveal hidden contents local NIGHTVISION_COLOURCUBES = { day = "images/colour_cubes/ruins_light_cc.tex", dusk = "images/colour_cubes/ruins_dim_cc.tex", night = "images/colour_cubes/purple_moon_cc.tex", full_moon = "images/colour_cubes/purple_moon_cc.tex", } local function SetNightVision(inst, enable) if TheWorld.state.isnight or TheWorld:HasTag("cave") then inst.components.playervision:ForceNightVision(true) inst.components.playervision:SetCustomCCTable(NIGHTVISION_COLOURCUBES) else inst.components.playervision:ForceNightVision(false) inst.components.playervision:SetCustomCCTable(nil) end end -- This initializes for both the server and client. Tags can be added here. local common_postinit = function(inst) inst:WatchWorldState( "isday", function() SetNightVision(inst) end) inst:WatchWorldState( "isdusk", function() SetNightVision(inst) end) inst:WatchWorldState( "isnight", function() SetNightVision(inst) end) inst:WatchWorldState( "iscaveday", function() SetNightVision(inst) end) inst:WatchWorldState( "iscavedusk", function() SetNightVision(inst) end) inst:WatchWorldState( "iscavenight", function() SetNightVision(inst) end) SetNightVision(inst) end is this wrong? if so, what do I need to fix in order to provide night vision to the character? thank you for your help! You should just be able to change this part inst:WatchWorldState( "iscavenight", function() SetNightVision(inst) end) to inst:WatchWorldState( "iscavenight", SetNightVision) I always recommend adding a Print inside of the function you're calling to see if it's being called or not. Example would be local function SetNightVision(inst, enable) Print "SetNightVision has been called" if TheWorld.state.isnight or TheWorld:HasTag("cave") then Print "Nightvision is on!" inst.components.playervision:ForceNightVision(true) inst.components.playervision:SetCustomCCTable(NIGHTVISION_COLOURCUBES) else Print "Nightvision is off!" inst.components.playervision:ForceNightVision(false) inst.components.playervision:SetCustomCCTable(nil) endend You can check these messages when you're in a game by going to the command console (press the ` key just below Esc) Link to comment Share on other sites More sharing options...
FrontierHero Posted February 25, 2017 Author Share Posted February 25, 2017 7 hours ago, AkaiNight said: try this 2 hours ago, RedHairedHero said: You should just be able to change this part inst:WatchWorldState( "iscavenight", function() SetNightVision(inst) end) to inst:WatchWorldState( "iscavenight", SetNightVision) I always recommend adding a Print inside of the function you're calling to see if it's being called or not. Example would be local function SetNightVision(inst, enable) Print "SetNightVision has been called" if TheWorld.state.isnight or TheWorld:HasTag("cave") then Print "Nightvision is on!" inst.components.playervision:ForceNightVision(true) inst.components.playervision:SetCustomCCTable(NIGHTVISION_COLOURCUBES) else Print "Nightvision is off!" inst.components.playervision:ForceNightVision(false) inst.components.playervision:SetCustomCCTable(nil) endend You can check these messages when you're in a game by going to the command console (press the ` key just below Esc) I added both of yours, and now night vision works, thank you! but is there still a way to take damage from the darkness? I don't take damage at night anymore, and if I leave it that way, it makes the mod way too OP and kinda defeats the challenge of trying to keep a fire going lol. thank you both so much for your help! 6 hours ago, DarkKingBoo said: This should give you nightvision once it turns night (or when you enter caves). Is it not working? nope, it was not working before, but i fixed it. thanks for asking! Link to comment Share on other sites More sharing options...
RedHairedHero Posted February 26, 2017 Share Posted February 26, 2017 11 hours ago, FrontierHero said: I added both of yours, and now night vision works, thank you! but is there still a way to take damage from the darkness? I don't take damage at night anymore, and if I leave it that way, it makes the mod way too OP and kinda defeats the challenge of trying to keep a fire going lol. thank you both so much for your help! nope, it was not working before, but i fixed it. thanks for asking! Being attacked by Charlie even with nightvision seems to be a bit redundant to me. You could always make a piece of equipment that grants nightvision instead, that way you need to at least recraft it or refuel it and give up an equipment slot for it. That would make it way more balanced. Link to comment Share on other sites More sharing options...
FrontierHero Posted February 27, 2017 Author Share Posted February 27, 2017 15 hours ago, RedHairedHero said: Being attacked by Charlie even with nightvision seems to be a bit redundant to me. You could always make a piece of equipment that grants nightvision instead, that way you need to at least recraft it or refuel it and give up an equipment slot for it. That would make it way more balanced. oh, well then thank you; i may end up replacing the night vision with another perk then, and do what you suggested; thank you! Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now