TheGamerDracul Posted June 22, 2016 Share Posted June 22, 2016 I just made a character and one of his perks is night vision. I found some codes AND they work thankfully. However the night vision affects not just me but all other players as well, thus taking out the challenge. Does ANYONE know how to fix this? I'm basically using the code provided in this link >>> If anyone has a solution to this problem please let me know asap. Thank you~ Link to comment Share on other sites More sharing options...
DarkXero Posted June 22, 2016 Share Posted June 22, 2016 That's because lights in the server will protect all people even if they can't see it. DST has the playervision component to get player specific ambient lighting. Use this: local function UpdateNightVision(inst, phase) local enable = phase == "night" inst:DoTaskInTime(enable and 0 or 1, function(inst) inst.components.playervision:ForceNightVision(enable) inst.components.playervision:SetCustomCCTable(enable and {} or nil) end) end local function OnInitNightVision(inst) if TheWorld.ismastersim or inst.HUD then inst:WatchWorldState("phase", UpdateNightVision) UpdateNightVision(inst, TheWorld.state.phase) end end and put in common_postinit: local function common_postinit(inst) inst:DoTaskInTime(0, OnInitNightVision) end Link to comment Share on other sites More sharing options...
polygone Posted June 30, 2016 Share Posted June 30, 2016 On 6/21/2016 at 10:14 PM, DarkXero said: That's because lights in the server will protect all people even if they can't see it. DST has the playervision component to get player specific ambient lighting. Use this: -- and put in common_postinit: -- So the night vision works rather well via this method for characters who are meant to always have night vision, but is there a way to set it up so that the night vision only works under certain conditions/when x variable is true on the inst? Specifically, I'm trying to get a character to have night vision only when their sanity is below 20%, but am having trouble assigning any other condition to the night vision other than the world phase. Link to comment Share on other sites More sharing options...
DarkXero Posted June 30, 2016 Share Posted June 30, 2016 local function UpdateNightVision(inst) local phase = TheWorld.state.phase local sanitypercent = inst.replica.sanity:GetPercentNetworked() local enable = phase == "night" and sanitypercent < 0.2 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 Link to comment Share on other sites More sharing options...
polygone Posted June 30, 2016 Share Posted June 30, 2016 Works perfectly. Thank you very much! Going to guess that the sanity replica is for the serverside information? Or something to that extent? I seem to have been going about the wrong component in that regard, oops. Networked information is odd. Will learn how to wield it eventually. x_x; But yes, the help is much appreciated. ^_^ Link to comment Share on other sites More sharing options...
DarkXero Posted June 30, 2016 Share Posted June 30, 2016 11 hours ago, polygone said: Going to guess that the sanity replica is for the serverside information? Sanity is a replicatable component, which means that clients get a stub component generated for them on their side too. In this case, it provides clients with their own sanity value, which they need, because they have to display it. If you wanted to make a weird combination of triggers that required server side information, then you would a net variable to trigger the nightvision for the client. But luckily, clients have their own sanity value networked, and the event "sanitydelta" is also pushed locally (clients use it to update the sanity badge). Link to comment Share on other sites More sharing options...
Eremus007 Posted July 3, 2016 Share Posted July 3, 2016 On 30-6-2016 at 8:48 PM, DarkXero said: Sanity is a replicatable component, which means that clients get a stub component generated for them on their side too. In this case, it provides clients with their own sanity value, which they need, because they have to display it. If you wanted to make a weird combination of triggers that required server side information, then you would a net variable to trigger the nightvision for the client. But luckily, clients have their own sanity value networked, and the event "sanitydelta" is also pushed locally (clients use it to update the sanity badge). Hey DarkXero, Eremus here. You did an amazing job for me on the dwarven tonic for my dwarven character mod. But I am having the same problem as stated above and others are able to survive on the light the tonic spawns upon drinking. Is there any way to help that by putting another code in the 'dwarfbrewdrinker' component? dwarfbrewdrinker.lua Link to comment Share on other sites More sharing options...
DarkXero Posted July 6, 2016 Share Posted July 6, 2016 On 3/7/2016 at 5:23 PM, Eremus007 said: Is there any way to help that by putting another code in the 'dwarfbrewdrinker' component? Not the component. The replica. Skyminer 3000.zip Link to comment Share on other sites More sharing options...
Eremus007 Posted July 6, 2016 Share Posted July 6, 2016 3 hours ago, DarkXero said: Not the component. The replica. Skyminer 3000.zip Thank you Link to comment 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