Aleyck Posted April 30, 2014 Share Posted April 30, 2014 With the Moggles bringing about true nightvsion potential, I wanted to try my hand at applying the code to Webber to provide a nighttime advantage and a daytime disadvantage(sanity drain during the day as well as much brightness). I can't seem to sort out all of the confusing code to make it happen, however, and it crashes when I try. local function mole_onequip(inst, owner) onequip(inst, owner) if owner ~= GetPlayer() then return end owner.SoundEmitter:PlaySound("dontstarve_DLC001/common/moggles_on") if GetClock() and GetWorld() and GetWorld().components.colourcubemanager then GetClock():SetNightVision(true) if GetClock():IsDay() and not GetWorld():IsCave() then GetWorld().components.colourcubemanager:SetOverrideColourCube("images/colour_cubes/mole_vision_off_cc.tex", .25) else -- Dusk and Night GetWorld().components.colourcubemanager:SetOverrideColourCube("images/colour_cubes/mole_vision_on_cc.tex", .25) end end end local function mole_onunequip(inst, owner) onunequip(inst, owner) if owner ~= GetPlayer() then return end owner.SoundEmitter:PlaySound("dontstarve_DLC001/common/moggles_off") if GetClock() then GetClock():SetNightVision(false) end if GetWorld() and GetWorld().components.colourcubemanager then GetWorld().components.colourcubemanager:SetOverrideColourCube(nil, .5) end end local function mole_perish(inst) if inst.components.inventoryitem:GetGrandOwner() == GetPlayer() and inst.components.equippable and inst.components.equippable:IsEquipped() then if GetClock() then GetClock():SetNightVision(false) end if GetWorld() and GetWorld().components.colourcubemanager then GetWorld().components.colourcubemanager:SetOverrideColourCube(nil, .5) end end generic_perish(inst) end local function mole() local inst = simple() inst.components.equippable:SetOnEquip( mole_onequip ) inst.components.equippable:SetOnUnequip( mole_onunequip ) inst:AddComponent("fueled") inst.components.fueled.fueltype = "MOLEHAT" inst.components.fueled:InitializeFuelLevel(TUNING.MOLEHAT_PERISHTIME) inst.components.fueled:SetDepletedFn( mole_perish ) inst.components.fueled.accepting = true inst:AddTag("no_sewing") inst:ListenForEvent("daytime", function(it) if GetWorld():IsCave() then return end if inst.components.equippable and inst.components.equippable:IsEquipped() and inst.components.inventoryitem:GetGrandOwner() == GetPlayer() and not GetWorld():IsCave() then GetWorld().components.colourcubemanager:SetOverrideColourCube("images/colour_cubes/mole_vision_off_cc.tex", 2) end end, GetWorld()) inst:ListenForEvent("dusktime", function(it) if GetWorld():IsCave() then return end if inst.components.equippable and inst.components.equippable:IsEquipped() and inst.components.inventoryitem:GetGrandOwner() == GetPlayer() then GetWorld().components.colourcubemanager:SetOverrideColourCube("images/colour_cubes/mole_vision_on_cc.tex", 2) end end, GetWorld()) inst:ListenForEvent("nighttime", function(it) if GetWorld():IsCave() then return end if inst.components.equippable and inst.components.equippable:IsEquipped() and inst.components.inventoryitem:GetGrandOwner() == GetPlayer() then GetWorld().components.colourcubemanager:SetOverrideColourCube("images/colour_cubes/mole_vision_on_cc.tex", 2) end end, GetWorld()) return inst endThis code shows exactly how the moggles work in the 'hats' file in prefabs. How would I go about applying the nightvision effect for a character like Webber? Link to comment https://forums.kleientertainment.com/forums/topic/35684-applying-nightvision-conditions-to-character/ Share on other sites More sharing options...
MidrealmDM Posted April 30, 2014 Share Posted April 30, 2014 (edited) The following might work - local function dodarkvision(inst, dt) if GetClock() and GetWorld() and GetWorld().components.colourcubemanager then GetClock():SetNightVision(true) if GetClock():IsDay() and not GetWorld():IsCave() then-- Set the vision style for daytime-- you can also set an inherent negative dapperness to take effect at daytime to achieve your sanity loss GetWorld().components.colourcubemanager:SetOverrideColourCube("images/colour_cubes/mole_vision_off_cc.tex", .25) else -- Dusk and Night-- Set the vision style for dusk, night, or cave GetWorld().components.colourcubemanager:SetOverrideColourCube("images/colour_cubes/mole_vision_on_cc.tex", .25) end endend -- the above lines are a function that check the current condition and sets the appropriate vision style-- the lines below force the above function to check and re-evaluate every 0.2 seconds local fn = function(inst) inst:DoPeriodicTask(0.2, function() dodarkvision(inst, 0.2) end)end place it in your character.lua Edited April 30, 2014 by MidrealmDM Link to comment https://forums.kleientertainment.com/forums/topic/35684-applying-nightvision-conditions-to-character/#findComment-466341 Share on other sites More sharing options...
Aleyck Posted May 1, 2014 Author Share Posted May 1, 2014 That does seem like a great bit of code, and I thought it might work. It is apparently lacking something, as it doesn't seem to work nor crash anything when I play as the character with the coding added on. I'm thinking it has to do with the inst:ListenForEvent parts of the code, but when I tried to put them in it either just plain doesn't work or I'm doing it wrong. Link to comment https://forums.kleientertainment.com/forums/topic/35684-applying-nightvision-conditions-to-character/#findComment-467197 Share on other sites More sharing options...
julz1981 Posted May 1, 2014 Share Posted May 1, 2014 Interesting, but it makes me remember, didn't the devs said they would add something more unique to webber? I was sure they would give him nightvision or something like that.Hope you find out how to do this XD Link to comment https://forums.kleientertainment.com/forums/topic/35684-applying-nightvision-conditions-to-character/#findComment-467230 Share on other sites More sharing options...
MidrealmDM Posted May 1, 2014 Share Posted May 1, 2014 (edited) That does seem like a great bit of code, and I thought it might work. It is apparently lacking something, as it doesn't seem to work nor crash anything when I play as the character with the coding added on. I'm thinking it has to do with the inst:ListenForEvent parts of the code, but when I tried to put them in it either just plain doesn't work or I'm doing it wrong.===inst:ListenForEvent("nighttime", function(it) if GetWorld():IsCave() then return end-- listens for 'night' if inst.components.equippable and inst.components.equippable:IsEquipped() and inst.components.inventoryitem:GetGrandOwner() == GetPlayer() then-- checks if the item is equipped and that it is being used by a player-- if so set the override color GetWorld().components.colourcubemanager:SetOverrideColourCube("images/colour_cubes/mole_vision_on_cc.tex", 2) end end, GetWorld())==== The code i suggested does the same thing, only doesnt check for equipped or player, since it is the player itself doing it.However one thing I just noticed. ("images/colour_cubes/mole_vision_on_cc.tex", 2)The value at the end is higher ... 2 instead of .25 - so you might try changing the number and see what effect it has. Edited May 1, 2014 by MidrealmDM Link to comment https://forums.kleientertainment.com/forums/topic/35684-applying-nightvision-conditions-to-character/#findComment-467488 Share on other sites More sharing options...
Aleyck Posted May 1, 2014 Author Share Posted May 1, 2014 (edited) ===inst:ListenForEvent("nighttime", function(it) if GetWorld():IsCave() then return end-- listens for 'night' if inst.components.equippable and inst.components.equippable:IsEquipped() and inst.components.inventoryitem:GetGrandOwner() == GetPlayer() then-- checks if the item is equipped and that it is being used by a player-- if so set the override color GetWorld().components.colourcubemanager:SetOverrideColourCube("images/colour_cubes/mole_vision_on_cc.tex", 2) end end, GetWorld())==== The code i suggested does the same thing, only doesnt check for equipped or player, since it is the player itself doing it.However one thing I just noticed. ("images/colour_cubes/mole_vision_on_cc.tex", 2)The value at the end is higher ... 2 instead of .25 - so you might try changing the number and see what effect it has. Changed the value, still nothing. Started a new game to try to see if that was it, but it wasn't. GetClock():SetNightVision(true) GetWorld().components.colourcubemanager:SetOverrideColourCube("images/colour_cubes/mole_vision_on_cc.tex", 2)However, when I posted just this into the character.lua, I managed to get the night vision, though the effects are the same all day and night. I tried to make the light sensitivity (mole_vision_off in daytime) work, but that is the part that I seem to be unable to do at this point. Edited May 1, 2014 by Aleyck Link to comment https://forums.kleientertainment.com/forums/topic/35684-applying-nightvision-conditions-to-character/#findComment-467707 Share on other sites More sharing options...
rsrs Posted May 3, 2014 Share Posted May 3, 2014 The character mod "Wulfe" has night vision in the night and normal vision during the day. Maybe looking at Wulfe's code would help. Link to comment https://forums.kleientertainment.com/forums/topic/35684-applying-nightvision-conditions-to-character/#findComment-469408 Share on other sites More sharing options...
MidrealmDM Posted May 3, 2014 Share Posted May 3, 2014 (edited) Changed the value, still nothing. Started a new game to try to see if that was it, but it wasn't. GetClock():SetNightVision(true) GetWorld().components.colourcubemanager:SetOverrideColourCube("images/colour_cubes/mole_vision_on_cc.tex", 2)However, when I posted just this into the character.lua, I managed to get the night vision, though the effects are the same all day and night. I tried to make the light sensitivity (mole_vision_off in daytime) work, but that is the part that I seem to be unable to do at this point. I am thinking you need to somehow turn off the SetOverrideColorCube, not just change it to something else.would putting it to SetOverrideColorCube() work?I don't think it would, but I'm at the limit of my knowledge of lua. Edited May 3, 2014 by MidrealmDM Link to comment https://forums.kleientertainment.com/forums/topic/35684-applying-nightvision-conditions-to-character/#findComment-469501 Share on other sites More sharing options...
Aleyck Posted May 3, 2014 Author Share Posted May 3, 2014 Tried that. Didn't really work at all. Then again I am a pretty inexperienced coder and may be doing it wrong. The character mod "Wulfe" has night vision in the night and normal vision during the day. Maybe looking at Wulfe's code would help. You may be thinking of the 'nightvision' that makes a character give off light. That's the kind of 'nightvision' Wulfe has, if I'm not mistaken, and that's not exactly what I'm looking for. http://dont-starve-game.wikia.com/wiki/Moggles take a look at the screenshots. I'm trying to achieve those effects when playing as Webber. Link to comment https://forums.kleientertainment.com/forums/topic/35684-applying-nightvision-conditions-to-character/#findComment-469524 Share on other sites More sharing options...
Rincevvind Posted May 3, 2014 Share Posted May 3, 2014 this effects still doesnt allow grue to appearso what difference - this or just source of light? Link to comment https://forums.kleientertainment.com/forums/topic/35684-applying-nightvision-conditions-to-character/#findComment-469575 Share on other sites More sharing options...
Aleyck Posted May 10, 2014 Author Share Posted May 10, 2014 The difference is the visual effects and that there is no actual 'light' involved. I am still interested in getting this to work but have had no success. Any ideas? Link to comment https://forums.kleientertainment.com/forums/topic/35684-applying-nightvision-conditions-to-character/#findComment-476835 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