Jump to content

Applying Nightvision conditions to character?


Aleyck

Recommended Posts

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    end

This 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
Share on other sites

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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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.
Link to comment
Share on other sites

 

===

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...