Recommended Posts

I've recently started making a custom Character, and I'd like them to have Night vision but am unsure how to go about this. For this character only I'd like it to be like the light of a full moon all the time, without affecting the other players. How might I be able to achieve this? I can't seem to figure out how to look at other mods code to find examples, so I'm at a loss here.

Share this post


Link to post
Share on other sites
Ultroman    532

Whenever you want to enable nightvision. If you want it on constantly, I think you can just put that line in the character LUA inside the master_postinit. I'm not sure if it persists after dying and then being resurrected. You'll have to test things like that out.

Share this post


Link to post
Share on other sites
suteneko    7

Sorry for butting in but I wanted to utilize this code for one of my characters as well but it didn't work as intended.

This code actually messes up vision during the daytime. Looks like a filter on top of the game. Is there another way to go about it so it only works during the night?

Share this post


Link to post
Share on other sites
thomas4845    501

    inst:WatchWorldState("phase", function(inst,phasr)
        if phase == "day" then
        inst.components.playervision:ForceNightVision(false)
    elseif phase == "night" then
        inst.components.playervision:ForceNightVision(true)     
    elseif phase == "dusk" then
        inst.components.playervision:ForceNightVision(false)
    end
end)
 

if you want custom colors check out the woodie file

  • Like 1

Share this post


Link to post
Share on other sites
Ultroman    532
23 minutes ago, thomas4845 said:

 inst:WatchWorldState("phase", function(inst, phase)
     if phase == "day" then
        inst.components.playervision:ForceNightVision(false)
    elseif phase == "night" then
        inst.components.playervision:ForceNightVision(true)     
    elseif phase == "dusk" then
        inst.components.playervision:ForceNightVision(false)
    end
end)

Fixed the typo ;)

  • Thanks 2

Share this post


Link to post
Share on other sites
suteneko    7

@thomas4845 Thank you! I just tested it and it worked! I'll look into the color thing since I was dumb and got the wrong idea. My idea of "night vision" was just making it so night wasn't pitch black and there was still some visibility from star and moonlight (which isn't what night vision means--).

Share this post


Link to post
Share on other sites
Hornete    953

Don't you need to add a net bool and also activate the night vision for clients? It's what I had to do for Wilba in Hamlet characters, and Woodie does it too

  • Like 1

Share this post


Link to post
Share on other sites
Ultroman    532
14 minutes ago, Hornete said:

Don't you need to add a net bool and also activate the night vision for clients? It's what I had to do for Wilba in Hamlet characters, and Woodie does it too

Yeah, I just got back to this one because I remembered that. Good catch, @Hornete!! The "parent" is just the player inst, right?

local function ToggleMoggleRPC(inst)
    inst.player_classified.mogglevision:set(not inst.components.playervision.forcenightvision)
end
AddModRPCHandler("mycustomnamespace", "togglemoggle", ToggleMoggleRPC)

and then where you want to toggle the nightvision you use

SendModRPCToServer(MOD_RPC["mycustomnamespace"]["togglemoggle"], parent) 

You can still split it into an On and Off toggle, though, like this:

local function TurnOnMoggleVisionRPC(inst)
    inst.player_classified.mogglevision:set(true)
end
local function TurnOffMoggleVisionRPC(inst)
    inst.player_classified.mogglevision:set(false)
end
AddModRPCHandler("mycustomnamespace", "turnonmoggle", TurnOnMoggleVisionRPC)
AddModRPCHandler("mycustomnamespace", "turnoffmoggle", TurnOffMoggleVisionRPC)

and then call these to turn it on or off:

-- To turn it on
SendModRPCToServer(MOD_RPC["mycustomnamespace"]["turnonmoggle"], parent) 

-- To turn it off
SendModRPCToServer(MOD_RPC["mycustomnamespace"]["turnoffmoggle"], parent) 

 

Edited by Ultroman

Share this post


Link to post
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