. . . Posted August 22, 2016 Share Posted August 22, 2016 (edited) 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 !!!!!!!!!!!!!!! Edited August 23, 2016 by SuperDavid Link to comment https://forums.kleientertainment.com/forums/topic/69707-solved-ish-how-to-give-character-night-vision/ Share on other sites More sharing options...
Jpianist Posted August 22, 2016 Share Posted August 22, 2016 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. Link to comment https://forums.kleientertainment.com/forums/topic/69707-solved-ish-how-to-give-character-night-vision/#findComment-805785 Share on other sites More sharing options...
. . . Posted August 22, 2016 Author Share Posted August 22, 2016 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 crashed) but thanks so much for replying & trying to help me !! Link to comment https://forums.kleientertainment.com/forums/topic/69707-solved-ish-how-to-give-character-night-vision/#findComment-805793 Share on other sites More sharing options...
Jpianist Posted August 22, 2016 Share Posted August 22, 2016 (edited) 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 crashed) but thanks so much for replying & trying to help me !! 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 August 22, 2016 by Jpianist Link to comment https://forums.kleientertainment.com/forums/topic/69707-solved-ish-how-to-give-character-night-vision/#findComment-805795 Share on other sites More sharing options...
. . . Posted August 22, 2016 Author Share Posted August 22, 2016 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 ... Link to comment https://forums.kleientertainment.com/forums/topic/69707-solved-ish-how-to-give-character-night-vision/#findComment-805796 Share on other sites More sharing options...
Jpianist Posted August 22, 2016 Share Posted August 22, 2016 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 ... Yeah 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 but tomorrow i'll try this myself. Link to comment https://forums.kleientertainment.com/forums/topic/69707-solved-ish-how-to-give-character-night-vision/#findComment-805797 Share on other sites More sharing options...
Jpianist Posted August 22, 2016 Share Posted August 22, 2016 (edited) 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 August 22, 2016 by Jpianist This message was sent by browser error Link to comment https://forums.kleientertainment.com/forums/topic/69707-solved-ish-how-to-give-character-night-vision/#findComment-805799 Share on other sites More sharing options...
DarkXero Posted August 23, 2016 Share Posted August 23, 2016 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. 1 Link to comment https://forums.kleientertainment.com/forums/topic/69707-solved-ish-how-to-give-character-night-vision/#findComment-806088 Share on other sites More sharing options...
. . . Posted August 23, 2016 Author Share Posted August 23, 2016 (edited) @DarkXero Thanks so much ! If I can ask one more question would it be possible to make the night vision a little darker? Maybe more like this 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 Edited August 23, 2016 by SuperDavid Link to comment https://forums.kleientertainment.com/forums/topic/69707-solved-ish-how-to-give-character-night-vision/#findComment-806109 Share on other sites More sharing options...
DarkXero Posted August 23, 2016 Share Posted August 23, 2016 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? Link to comment https://forums.kleientertainment.com/forums/topic/69707-solved-ish-how-to-give-character-night-vision/#findComment-806126 Share on other sites More sharing options...
. . . Posted August 23, 2016 Author Share Posted August 23, 2016 (edited) 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 So I guess it's not possible to make it darker but thanks you are a huge help !!!! Maybe would it be possible I make my own custom color cube or something or is that super hard? Edited August 23, 2016 by SuperDavid Link to comment https://forums.kleientertainment.com/forums/topic/69707-solved-ish-how-to-give-character-night-vision/#findComment-806138 Share on other sites More sharing options...
Lokoluna Posted November 4, 2016 Share Posted November 4, 2016 I'd like to know this too.. However no matter where i put the code from @DarkXero I never actually get night vision.. it was in my character.lua in my modmain.lua.. Where does it exactly go? Link to comment https://forums.kleientertainment.com/forums/topic/69707-solved-ish-how-to-give-character-night-vision/#findComment-833010 Share on other sites More sharing options...
DarkXero Posted November 4, 2016 Share Posted November 4, 2016 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. Link to comment https://forums.kleientertainment.com/forums/topic/69707-solved-ish-how-to-give-character-night-vision/#findComment-833015 Share on other sites More sharing options...
Lokoluna Posted November 4, 2016 Share Posted November 4, 2016 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. Link to comment https://forums.kleientertainment.com/forums/topic/69707-solved-ish-how-to-give-character-night-vision/#findComment-833027 Share on other sites More sharing options...
DarkXero Posted November 4, 2016 Share Posted November 4, 2016 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. Link to comment https://forums.kleientertainment.com/forums/topic/69707-solved-ish-how-to-give-character-night-vision/#findComment-833028 Share on other sites More sharing options...
Lokoluna Posted November 4, 2016 Share Posted November 4, 2016 (edited) 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 November 4, 2016 by Lokoluna Link to comment https://forums.kleientertainment.com/forums/topic/69707-solved-ish-how-to-give-character-night-vision/#findComment-833031 Share on other sites More sharing options...
DarkXero Posted November 4, 2016 Share Posted November 4, 2016 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 Link to comment https://forums.kleientertainment.com/forums/topic/69707-solved-ish-how-to-give-character-night-vision/#findComment-833033 Share on other sites More sharing options...
Lokoluna Posted November 4, 2016 Share Posted November 4, 2016 @DarkXero I am so sorry, I'm new to the whole coding thing, Thank you so much worked like a charm! Link to comment https://forums.kleientertainment.com/forums/topic/69707-solved-ish-how-to-give-character-night-vision/#findComment-833038 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