Jump to content

Changing code: Night Vision


Recommended Posts

Hey everybody,

I can't seem to figure out how to make my night vision turn on if it's dark (Not only night!) so it works with mods that add new areas like the basement. I tried a few things but everytime I replaced the "TheWorld.state.isnight" with "inst.LightWatcher:GetLightValue() < (0.1)" my nightvision wouldn't work if i enter a light source and walk into the darkness again. I also tried to check the light value with a periodic task but my world wouldn't start if i did so.

	-- Night Vision
	local NIGHTVISION_COLOURCUBES =
{
    day = "images/colour_cubes/mole_vision_on_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_on_cc.tex",
}
local function SetNightVision(inst, enable) 										-- Enables Nightvision
    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
	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

 

Link to comment
Share on other sites

Hmm this basement mod is weird, but I'll offer a quick fix:

inst:ListenForEvent("enterdark", SetNightVision)
inst:ListenForEvent("enterlight", DisableNightVision) --disable nightvision

hopefully you can take it from here cause that basement mod has too much code for me to take the time and decode. Heh you don't get extra points for doing the hard route if the easy route takes you to the same destination.

Link to comment
Share on other sites

Huh i didn't even know there was an easier way xD tho i think i broke something my world isn't starting anymore again everytime i have my char enabled and try to start the world i get this massage:5b18d7c6851f7_Screenshot(21).thumb.png.3360154bbceee65f9c15c5e783174c85.png

 

I'm a 100% positive i missed something ^^'

 

Spoiler


local MakePlayerCharacter = require "prefabs/player_common"


local assets = {
    Asset("SCRIPT", "scripts/prefabs/player_common.lua"),
}
local prefabs = {}

-- Custom starting items
local start_inv = {

        "spear",
        "blowdart_pipe",
        "blowdart_pipe",
        "trap",
        "fish",
        "fish",
}
    
-- When the character is revived from human
local function onbecamehuman(inst)
    -- Set speed when reviving from ghost (optional)
    inst.components.locomotor:SetExternalSpeedMultiplier(inst, "narisa_speed_mod", 1)
end

local function onbecameghost(inst)
    -- Remove speed modifier when becoming a ghost
   inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "narisa_speed_mod")
end

-- When loading or spawning the character
local function onload(inst)
    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
    inst:ListenForEvent("ms_becameghost", onbecameghost)

    if inst:HasTag("playerghost") then
        onbecameghost(inst)
    else
        onbecamehuman(inst)
    end
end

local common_postinit = function(inst) -- Add tags here

inst:AddTag("mycharactertag")

    -- Minimap icon
    inst.MiniMapEntity:SetIcon( "narisa.tex" )
    
    -- Night Vision
    local NIGHTVISION_COLOURCUBES =
{
    day = "images/colour_cubes/mole_vision_on_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_on_cc.tex",
}
local function SetNightVision(inst, enable)                                            -- Enables Nightvision
        inst.components.playervision:ForceNightVision(true)
        inst.components.playervision:SetCustomCCTable(NIGHTVISION_COLOURCUBES)
    else
        inst.components.playervision:ForceNightVision(false)
        inst.components.playervision:SetCustomCCTable(nil)
end
    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

-- Insanity/sanity Aura
 local function CalcSanityAura(inst, observer)
    

if (inst.components.sanity:GetPercent() > .5) and not  observer:HasTag("mycharactertag") then

 return TUNING.SANITYAURA_LARGE

elseif (inst.components.sanity:GetPercent() < .5) and not  observer:HasTag("mycharactertag") then

 return -TUNING.SANITYAURA_LARGE                                                     --small,med,large
 
end
end

-- Hunger drain on low sanity
 local function sanityhunger(inst)
    if (inst.components.sanity:GetPercent() < .5)then

inst.components.hunger.hungerrate = 1.5

else

inst.components.hunger.hungerrate = 0.5

end
    end

-- Sanity drain on low Health
local function healthsanity(inst)
    if (inst.components.health:GetPercent() < .2) then
    
inst.components.sanity.night_drain_mult= 2

else

inst.components.sanity.night_drain_mult= 0.3

end
  end  

-- This initializes for the server only. Components are added here.
local master_postinit = function(inst)

-- Invisibility
 local function DropTargets(inst)
    local x,y,z = inst.Transform:GetWorldPosition()    
    local ents = TheSim:FindEntities(x, y, z, 50, nil, {"hound", "shadow"}, nil)    --get the creatures within the screen radius
    for k,v in pairs(ents) do
        if v.components.combat and v.components.combat.target == inst then          --if the creature is targeting inst
            v.components.combat.target = nil                                          --drop inst
        end
    end
end

local function GoInvisible(inst)
    inst.components.hunger.hungerrate = 0.8            --high hunger rate
    inst.components.locomotor.walkspeed = 3.5        --lower speed
    inst.components.locomotor.runspeed = 5.5
    inst.components.combat.canattack = false        --unable to attack
    inst:AddTag("notarget")                         --non-targetable
    inst.AnimState:SetMultColour(0.1,0.1,0.1,.1)     --hardly visible too ghostly for me
    if inst.DynamicShadow then                         --no shadow
        inst.DynamicShadow:Enable(false)
    end
    if inst.MiniMapEntity then                         --remove the minimap icon
        inst.MiniMapEntity:SetEnabled(false)
    end
    if not inst:HasTag("noplayerindicator") then     --other players cant see your icon when getting near or faraway
        inst:AddTag("noplayerindicator")
    end
end

local function GoVisible(inst)
    if not inst:HasTag("beefalo") then
    inst.components.hunger.hungerrate = 0.5
    inst.components.locomotor.walkspeed = 6
    inst.components.locomotor.runspeed = 8
    inst.components.combat.canattack = true            --can attack again
    inst:RemoveTag("notarget")                         --npcs can now target inst
    inst.AnimState:SetMultColour(1,1,1,1)            --regular color
    if inst.DynamicShadow then                         --put back the shadow
        inst.DynamicShadow:Enable(true)
    end
    if inst.MiniMapEntity then                         --icon back
        inst.MiniMapEntity:SetEnabled(true)
    end
    if inst:HasTag("noplayerindicator") then         --players can now see your indicater
        inst:RemoveTag("noplayerindicator")
    end
    end
end

    local function stealthmode(inst)
    if inst:HasTag("beefalo") then                    --does inst have this tag? replace it with beefalo and equip a beefalo hat if you don't believe me
    inst:AddTag("notarget")                         --put notarget so no npcs can target them
    DropTargets(inst)                                 --do this function
    GoInvisible(inst)                                 --this one as well
    end
end

-- Can eat monstermeat
inst.components.eater.strongstomach = true

-- Sanity Aura
inst:AddComponent("sanityaura")
    inst.components.sanityaura.aurafn = CalcSanityAura
    
    -- Choose which sounds this character will play
    inst.soundsname = "willow"
    
    -- Stats    
    inst.components.health:SetMaxHealth(150)
    inst.components.hunger:SetMax(75)
    inst.components.sanity:SetMax(150)
    inst.components.temperature.mintemp = 15.
    inst.components.locomotor.walkspeed = 6
    inst.components.locomotor.runspeed = 8
    
    
    -- Damage Multiplier
    if (inst.components.temperature:GetCurrent() > 55) then
    
    inst.components.combat.damagemultiplier = 0.5
    
    else
    
    inst.components.combat.damagemultiplier = 2
    
    end
    
    -- Peridocic Tasks
    inst:DoPeriodicTask(4, healthsanity, nil, inst)--checks every 4 seconds on your health
    inst:DoPeriodicTask(4, sanityhunger, nil, inst)--checks every 4 seconds on your sanity
    
    -- Listen For Event
    inst:ListenForEvent("equip", stealthmode) --listen when inst puts on something see if inst can go invisible
    inst:ListenForEvent("unequip", GoVisible) --listen when inst removes something see if inst goes back to visible
    inst:ListenForEvent("enterdark", SetNightVision) --listen when inst enters darkness set nightvision
    inst:ListenForEvent("enterlight", DisableNightVision)--listen when inst enters light disable nightvision
    
    inst.OnLoad = onload
    inst.OnNewSpawn = function()
      onload(inst)
    local backpack = SpawnPrefab("backpack")
    inst.components.inventory:Equip(backpack)
    end
end

return MakePlayerCharacter("narisa", prefabs, assets, common_postinit, master_postinit, start_inv)

 

 

Link to comment
Share on other sites

The error is clear as day you put the code in the wrong section:

 -- Night Vision
    local NIGHTVISION_COLOURCUBES =
{
    day = "images/colour_cubes/mole_vision_on_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_on_cc.tex",
}
local function SetNightVision(inst, enable)                                            -- Enables Nightvision
        inst.components.playervision:ForceNightVision(true)
        inst.components.playervision:SetCustomCCTable(NIGHTVISION_COLOURCUBES)
    else
        inst.components.playervision:ForceNightVision(false)
        inst.components.playervision:SetCustomCCTable(nil)
end
    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

-- Insanity/sanity Aura
 local function CalcSanityAura(inst, observer)
    

if (inst.components.sanity:GetPercent() > .5) and not  observer:HasTag("mycharactertag") then

 return TUNING.SANITYAURA_LARGE

elseif (inst.components.sanity:GetPercent() < .5) and not  observer:HasTag("mycharactertag") then

 return -TUNING.SANITYAURA_LARGE                                                     --small,med,large
 
end
end

-- Hunger drain on low sanity
 local function sanityhunger(inst)
    if (inst.components.sanity:GetPercent() < .5)then

inst.components.hunger.hungerrate = 1.5

else

inst.components.hunger.hungerrate = 0.5

end
    end

-- Sanity drain on low Health
local function healthsanity(inst)
    if (inst.components.health:GetPercent() < .2) then
    
inst.components.sanity.night_drain_mult= 2

else

inst.components.sanity.night_drain_mult= 0.3

end
  end  

-- This initializes for the server only. Components are added here.
local master_postinit = function(inst)

-- Invisibility
 local function DropTargets(inst)
    local x,y,z = inst.Transform:GetWorldPosition()    
    local ents = TheSim:FindEntities(x, y, z, 50, nil, {"hound", "shadow"}, nil)    --get the creatures within the screen radius
    for k,v in pairs(ents) do
        if v.components.combat and v.components.combat.target == inst then          --if the creature is targeting inst
            v.components.combat.target = nil                                          --drop inst
        end
    end
end

local function GoInvisible(inst)
    inst.components.hunger.hungerrate = 0.8            --high hunger rate
    inst.components.locomotor.walkspeed = 3.5        --lower speed
    inst.components.locomotor.runspeed = 5.5
    inst.components.combat.canattack = false        --unable to attack
    inst:AddTag("notarget")                         --non-targetable
    inst.AnimState:SetMultColour(0.1,0.1,0.1,.1)     --hardly visible too ghostly for me
    if inst.DynamicShadow then                         --no shadow
        inst.DynamicShadow:Enable(false)
    end
    if inst.MiniMapEntity then                         --remove the minimap icon
        inst.MiniMapEntity:SetEnabled(false)
    end
    if not inst:HasTag("noplayerindicator") then     --other players cant see your icon when getting near or faraway
        inst:AddTag("noplayerindicator")
    end
end

local function GoVisible(inst)
    if not inst:HasTag("beefalo") then
    inst.components.hunger.hungerrate = 0.5
    inst.components.locomotor.walkspeed = 6
    inst.components.locomotor.runspeed = 8
    inst.components.combat.canattack = true            --can attack again
    inst:RemoveTag("notarget")                         --npcs can now target inst
    inst.AnimState:SetMultColour(1,1,1,1)            --regular color
    if inst.DynamicShadow then                         --put back the shadow
        inst.DynamicShadow:Enable(true)
    end
    if inst.MiniMapEntity then                         --icon back
        inst.MiniMapEntity:SetEnabled(true)
    end
    if inst:HasTag("noplayerindicator") then         --players can now see your indicater
        inst:RemoveTag("noplayerindicator")
    end
    end
end

    local function stealthmode(inst)
    if inst:HasTag("beefalo") then                    --does inst have this tag? replace it with beefalo and equip a beefalo hat if you don't believe me
    inst:AddTag("notarget")                         --put notarget so no npcs can target them
    DropTargets(inst)                                 --do this function
    GoInvisible(inst)                                 --this one as well
    end

all the above do not belong in the common_postinit, they belong in the master_postinit. Idk exactly what the common_postinit is beside that it looks like the server/game uses it but that code is what the character uses which is the master_postinit and the character doesn't always have access to common_postinit. And the functions go to the very top of the master_postinit.

Link to comment
Share on other sites

So like that?

local common_postinit = function(inst) -- Add tags here

inst:AddTag("mycharactertag")

	-- Minimap icon
	inst.MiniMapEntity:SetIcon( "narisa.tex" )
	
-- This initializes for the server only. Components are added here.
local master_postinit = function(inst)
	-- Night Vision
	local NIGHTVISION_COLOURCUBES =
{
    day = "images/colour_cubes/mole_vision_on_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_on_cc.tex",
}
local function SetNightVision(inst, enable) --This should be obvious
    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
	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

-- Insanity/sanity Aura
 local function CalcSanityAura(inst, observer)
    

if (inst.components.sanity:GetPercent() > .5) and not  observer:HasTag("mycharactertag") then

 return TUNING.SANITYAURA_LARGE

elseif (inst.components.sanity:GetPercent() < .5) and not  observer:HasTag("mycharactertag") then

 return -TUNING.SANITYAURA_LARGE 													--small,med,large
 
end
end

-- Hunger drain on low sanity

 local function sanityhunger(inst)
    if (inst.components.sanity:GetPercent() < .5)then

inst.components.hunger.hungerrate = 1.5

else

inst.components.hunger.hungerrate = 0.5

end
	end

-- Sanity drain on low Health
local function healthsanity(inst)
	if (inst.components.health:GetPercent() < .2) then
    
inst.components.sanity.night_drain_mult= 2

else

inst.components.sanity.night_drain_mult= 0.3

end
  end  

-- Invisibility
 local function DropTargets(inst)
    local x,y,z = inst.Transform:GetWorldPosition()    
    local ents = TheSim:FindEntities(x, y, z, 50, nil, {"hound", "shadow"}, nil)	--get the creatures within the screen radius
    for k,v in pairs(ents) do
        if v.components.combat and v.components.combat.target == inst then  		--if the creature is targeting inst
            v.components.combat.target = nil  										--drop inst
        end
    end
end

local function GoInvisible(inst)
    inst.components.hunger.hungerrate = 0.8			--high hunger rate
    inst.components.locomotor.walkspeed = 3.5		--lower speed
    inst.components.locomotor.runspeed = 5.5
	inst.components.combat.canattack = false		--unable to attack
    inst:AddTag("notarget") 						--non-targetable
    inst.AnimState:SetMultColour(0.1,0.1,0.1,.1) 	--hardly visible too ghostly for me
    if inst.DynamicShadow then 						--no shadow
        inst.DynamicShadow:Enable(false)
    end
    if inst.MiniMapEntity then 						--remove the minimap icon
        inst.MiniMapEntity:SetEnabled(false)
    end
    if not inst:HasTag("noplayerindicator") then 	--other players cant see your icon when getting near or faraway
        inst:AddTag("noplayerindicator")
    end
end

local function GoVisible(inst)
    if not inst:HasTag("beefalo") then
    inst.components.hunger.hungerrate = 0.5
    inst.components.locomotor.walkspeed = 6 
    inst.components.locomotor.runspeed = 8
	inst.components.combat.canattack = true        	--can attack again
    inst:RemoveTag("notarget") 						--npcs can now target inst
    inst.AnimState:SetMultColour(1,1,1,1)			--regular color
    if inst.DynamicShadow then 						--put back the shadow
        inst.DynamicShadow:Enable(true)
    end
    if inst.MiniMapEntity then 						--icon back
        inst.MiniMapEntity:SetEnabled(true)
    end
    if inst:HasTag("noplayerindicator") then 		--players can now see your indicater
        inst:RemoveTag("noplayerindicator")
    end
    end
end

    local function stealthmode(inst)
    if inst:HasTag("beefalo") then					--does inst have this tag?
    inst:AddTag("notarget") 						--put notarget so no npcs can target them
    DropTargets(inst) 								--do this function
    GoInvisible(inst) 								--this one as well
    end
end 

-- Can eat monstermeat
inst.components.eater.strongstomach = true

-- Sanity Aura
inst:AddComponent("sanityaura")
    inst.components.sanityaura.aurafn = CalcSanityAura
	
	-- Choose which sounds this character will play
	inst.soundsname = "willow"
	
	-- Stats	
	inst.components.health:SetMaxHealth(150)
	inst.components.hunger:SetMax(75)
	inst.components.sanity:SetMax(150)
	inst.components.temperature.mintemp = 15.
	inst.components.locomotor.walkspeed = 6
	inst.components.locomotor.runspeed = 8
	
	
	-- Damage Multiplier
	if (inst.components.temperature:GetCurrent() > 55) then
	
	inst.components.combat.damagemultiplier = 0.5
	
	else
	
	inst.components.combat.damagemultiplier = 2
	
	end
	
	-- Peridocic Tasks
	inst:DoPeriodicTask(4, healthsanity, nil, inst)--checks every 4 seconds on your health
	inst:DoPeriodicTask(4, sanityhunger, nil, inst)--checks every 4 seconds on your sanity
	
	-- Listen For Event
	inst:ListenForEvent("equip", stealthmode) --listen when inst puts on something see if inst can go invisible
    inst:ListenForEvent("unequip", GoVisible) --listen when inst removes something see if inst goes back to visible
	inst:ListenForEvent("enterdark", SetNightVision) --listen when inst enters darkness set nightvision
	inst:ListenForEvent("enterlight", DisableNightVision)--listen when inst enters light disable nightvision
	
	inst.OnLoad = onload
    inst.OnNewSpawn = function()
  	onload(inst)
	local backpack = SpawnPrefab("backpack")
	inst.components.inventory:Equip(backpack)
	end
end

return MakePlayerCharacter("narisa", prefabs, assets, common_postinit, master_postinit, start_inv)



Tho it worked until i changed the nightvision

EDIT:
Still doesnt work tho sry im stupid ^^'

Edited by _FrostyFoxy
Link to comment
Share on other sites

If you copied right you got a couple of eof errors. so ill post where your missing lots of ends

local common_postinit = function(inst)

inst:AddTag("mycharactertag")

inst.MiniMapEntity:SetIcon( "narisa.tex" )

end

local function SetNightVision(inst, enable) --This should be obvious
    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

    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

fix those functions otherwise its really turning into a mess that I can't see if everything is properly placed.

Link to comment
Share on other sites

Seems like I accidently deleated the end after the common_postinit whoopsies ^^'
Still didnt fix it though ^^'


local MakePlayerCharacter = require "prefabs/player_common"


local assets = {
    Asset("SCRIPT", "scripts/prefabs/player_common.lua"),
}
local prefabs = {}

-- Custom starting items
local start_inv = {

		"spear",
		"blowdart_pipe",
		"blowdart_pipe",
		"trap",
		"fish",
		"fish",
}
	
-- When the character is revived from human
local function onbecamehuman(inst)
	-- Set speed when reviving from ghost (optional)
	inst.components.locomotor:SetExternalSpeedMultiplier(inst, "narisa_speed_mod", 1)
end

local function onbecameghost(inst)
	-- Remove speed modifier when becoming a ghost
   inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "narisa_speed_mod")
end

-- When loading or spawning the character
local function onload(inst)
    inst:ListenForEvent("ms_respawnedfromghost", onbecamehuman)
    inst:ListenForEvent("ms_becameghost", onbecameghost)

    if inst:HasTag("playerghost") then
        onbecameghost(inst)
    else
        onbecamehuman(inst)
    end
end

local common_postinit = function(inst) -- Add tags here

inst:AddTag("mycharactertag")

	-- Minimap icon
	inst.MiniMapEntity:SetIcon( "narisa.tex" )
	
	end
	
-- This initializes for the server only. Components are added here.
local master_postinit = function(inst)
	
	-- Night Vision
	local NIGHTVISION_COLOURCUBES =
{
    day = "images/colour_cubes/mole_vision_on_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_on_cc.tex",
}
local function SetNightVision(inst, enable) --This should be obvious
    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
	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

-- Insanity/sanity Aura
 local function CalcSanityAura(inst, observer)
    

if (inst.components.sanity:GetPercent() > .5) and not  observer:HasTag("mycharactertag") then

 return TUNING.SANITYAURA_LARGE

elseif (inst.components.sanity:GetPercent() < .5) and not  observer:HasTag("mycharactertag") then

 return -TUNING.SANITYAURA_LARGE 													--small,med,large
 
end
end

-- Hunger drain on low sanity

 local function sanityhunger(inst)
    if (inst.components.sanity:GetPercent() < .5)then

inst.components.hunger.hungerrate = 1.5

else

inst.components.hunger.hungerrate = 0.5

end
	end

-- Sanity drain on low Health
local function healthsanity(inst)
	if (inst.components.health:GetPercent() < .2) then
    
inst.components.sanity.night_drain_mult= 2

else

inst.components.sanity.night_drain_mult= 0.3

end
  end  

-- Invisibility
 local function DropTargets(inst)
    local x,y,z = inst.Transform:GetWorldPosition()    
    local ents = TheSim:FindEntities(x, y, z, 50, nil, {"hound", "shadow"}, nil)	--get the creatures within the screen radius
    for k,v in pairs(ents) do
        if v.components.combat and v.components.combat.target == inst then  		--if the creature is targeting inst
            v.components.combat.target = nil  										--drop inst
        end
    end
end

local function GoInvisible(inst)
    inst.components.hunger.hungerrate = 0.8			--high hunger rate
    inst.components.locomotor.walkspeed = 3.5		--lower speed
    inst.components.locomotor.runspeed = 5.5
	inst.components.combat.canattack = false		--unable to attack
    inst:AddTag("notarget") 						--non-targetable
    inst.AnimState:SetMultColour(0.1,0.1,0.1,.1) 	--hardly visible too ghostly for me
    if inst.DynamicShadow then 						--no shadow
        inst.DynamicShadow:Enable(false)
    end
    if inst.MiniMapEntity then 						--remove the minimap icon
        inst.MiniMapEntity:SetEnabled(false)
    end
    if not inst:HasTag("noplayerindicator") then 	--other players cant see your icon when getting near or faraway
        inst:AddTag("noplayerindicator")
    end
end

local function GoVisible(inst)
    if not inst:HasTag("beefalo") then
    inst.components.hunger.hungerrate = 0.5
    inst.components.locomotor.walkspeed = 6 
    inst.components.locomotor.runspeed = 8
	inst.components.combat.canattack = true        	--can attack again
    inst:RemoveTag("notarget") 						--npcs can now target inst
    inst.AnimState:SetMultColour(1,1,1,1)			--regular color
    if inst.DynamicShadow then 						--put back the shadow
        inst.DynamicShadow:Enable(true)
    end
    if inst.MiniMapEntity then 						--icon back
        inst.MiniMapEntity:SetEnabled(true)
    end
    if inst:HasTag("noplayerindicator") then 		--players can now see your indicater
        inst:RemoveTag("noplayerindicator")
    end
    end
end

    local function stealthmode(inst)
    if inst:HasTag("beefalo") then					--does inst have this tag?
    inst:AddTag("notarget") 						--put notarget so no npcs can target them
    DropTargets(inst) 								--do this function
    GoInvisible(inst) 								--this one as well
    end
end 

-- Can eat monstermeat
inst.components.eater.strongstomach = true

-- Sanity Aura
inst:AddComponent("sanityaura")
    inst.components.sanityaura.aurafn = CalcSanityAura
	
	-- Choose which sounds this character will play
	inst.soundsname = "willow"
	
	-- Stats	
	inst.components.health:SetMaxHealth(150)
	inst.components.hunger:SetMax(75)
	inst.components.sanity:SetMax(150)
	inst.components.temperature.mintemp = 15.
	inst.components.locomotor.walkspeed = 6
	inst.components.locomotor.runspeed = 8
	
	
	-- Damage Multiplier
	if (inst.components.temperature:GetCurrent() > 55) then
	
	inst.components.combat.damagemultiplier = 0.5
	
	else
	
	inst.components.combat.damagemultiplier = 2
	
	end
	
	-- Peridocic Tasks
	inst:DoPeriodicTask(4, healthsanity, nil, inst)--checks every 4 seconds on your health
	inst:DoPeriodicTask(4, sanityhunger, nil, inst)--checks every 4 seconds on your sanity
	
	-- Listen For Event
	inst:ListenForEvent("equip", stealthmode) --listen when inst puts on something see if inst can go invisible
    inst:ListenForEvent("unequip", GoVisible) --listen when inst removes something see if inst goes back to visible
	inst:ListenForEvent("enterdark", SetNightVision) --listen when inst enters darkness set nightvision
	inst:ListenForEvent("enterlight", DisableNightVision)--listen when inst enters light disable nightvision
	
	inst.OnLoad = onload
    inst.OnNewSpawn = function()
  	onload(inst)
	local backpack = SpawnPrefab("backpack")
	inst.components.inventory:Equip(backpack)
	end
end

return MakePlayerCharacter("narisa", prefabs, assets, common_postinit, master_postinit, start_inv)

 

 

Edited by _FrostyFoxy
Link to comment
Share on other sites

Theres an extra end in SetNightVision that I said to remove in the previous post, at this point cant you just give me a picture of the error message that usually pops up. I'm tired of looking at this code without some help(or with only one of us not being a sleep).

Edited by K1NGT1GER609
Link to comment
Share on other sites

On 7.6.2018 at 11:04 PM, K1NGT1GER609 said:

Theres an extra end in SetNightVision that I said to remove in the previous post, at this point cant you just give me a picture of the error message that usually pops up. I'm tired of looking at this code without some help(or with only one of us not being a sleep).

the first end ends the local funtion and the second the "if" so whats the matter there

I dont have an error log its the same as befor

On 7.6.2018 at 9:03 AM, _FrostyFoxy said:

5b18d7c6851f7_Screenshot(21).thumb.png.3360154bbceee65f9c15c5e783174c85.png

 

 

Link to comment
Share on other sites

Oh hey its my ol nightvision code. Anyways:

 

local function SetNightVision(inst, enable) --This should be obvious
    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 --remove this one
	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

Did you remove the end with the --remove this one?

Link to comment
Share on other sites

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
 Share

×
  • Create New...