Woodside235 Posted January 7, 2015 Share Posted January 7, 2015 I want to have night vision as a character trait, but I don't want to just emit a server side light around the player that other players can see and hide in. Is there a way to make a client side light? Link to comment Share on other sites More sharing options...
Sarcen Posted January 7, 2015 Share Posted January 7, 2015 http://forums.kleientertainment.com/topic/48328-need-help-to-make-nightvision-player-only/ Link to comment Share on other sites More sharing options...
Dudedude Posted January 7, 2015 Share Posted January 7, 2015 As of right now, that's impossible. Mainly because it'd be possible for you to see Charlie (no art exists for her, and Klei wants her "evil shadow monster" to remain a mystery) attack other players. Link to comment Share on other sites More sharing options...
rezecib Posted January 8, 2015 Share Posted January 8, 2015 @Woodside235, Yes. You'll want to remove the grue component (Charlie), and then make sure the code for lighting is running on the client only. I think otherwise the process for creating light is similar. You can ensure something runs only on the client like this:if not TheWorld.ismastersim then --client-only codeend Link to comment Share on other sites More sharing options...
Kzisor Posted January 8, 2015 Share Posted January 8, 2015 (edited) @rezecib, I think I've narrowed it down to how it needs to work. I just have a few more things I need to set up in order for it to work completely. One problem I am having to nail down is the host obtaining night vision gives everyone night vision. This probably wouldn't be an issue if we use dedicated servers, however, if the host is an actual player then they will give everyone night vision. Client-Side Nightvision Theory:Set up a nightvision component which acts as the light source, separate from the character instance. On the client machine run the code for adding the component and enable the effect. Upon enabling nightvision send a RPC to the server notifying they have entered light to disable the grue. Server-Side Nightvision Theory:In the same nightvision component, set up a new variable which is the night vision instance which will be sent to the client machine. Upon enabling or disabling the nightvision if it's on the server side, disable it for that instance and send a RPC to the server notifying they have entered darkness to enable the grue again. This is all theory, but I have a semi-working concept which has the light enabled on the client machine and not on the server side. I'm going to work on the RPC's to see if I can get a fully working concept. Alternate solution:Remove the grue component from the player with nightvision on the server side. This still has issues with the server giving the light to all players though. That is something I don't know how to fix. Edited January 8, 2015 by Kzisor Link to comment Share on other sites More sharing options...
rezecib Posted January 8, 2015 Share Posted January 8, 2015 host obtaining night vision gives everyone night vision. Hmm... Non-networked host light should definitely be doable, seeing as that's how all the lights worked before they got networked. Although for those, they also provided protection from Charlie, even though clients couldn't see the light... Well, in any case, we'll get to see a proper solution when Woodie is released. Link to comment Share on other sites More sharing options...
Kzisor Posted January 8, 2015 Share Posted January 8, 2015 (edited) @rezecib, the issue arises with the LightWatcher component which I cannot find at all. I have not been able to find the Light component either, so it seems those are API directly from the C code. Here is a semi-working solution, host getting nightvision still seems to give clients protection. script/components/nightvision.luareturn Class(function(self, inst) self.inst = inst self.nightvision = CreateEntity() self.nightvision.entity:AddLight() self.nightvision.Light:Enable(false) self.enabled = false function self:Enable() self.nightvision.Light:Enable(true) self.enabled = true end function self:Disable() self.nightvision.Light:Enable(false) self.enabled = false end function self:SetRadius(amount) self.nightvision.Light:SetRadius(amount) end function self:SetFalloff(amount) self.nightvision.Light:SetFalloff(amount) end function self:SetIntensity(amount) self.nightvision.Light:SetIntensity(amount) end function self:SetColour(r, b, g) self.nightvision.Light:SetColour(r, b, g) endend) modmain.lualocal function PhaseChange(inst, phase) if phase == "night" and inst.components.nightvision then if GLOBAL.ThePlayer == inst then inst.components.nightvision:Enable() end if GLOBAL.TheWorld.ismastersim then inst.components.nightvision.enabled = true end elseif inst.components.nightvision then if GLOBAL.ThePlayer == inst then inst.components.nightvision:Disable() end if GLOBAL.TheWorld.ismastersim then inst.components.nightvision.enabled = false end endendWilson = function(self) self:AddComponent("nightvision") self:WatchWorldState("phase", PhaseChange) self.components.nightvision:SetRadius(100) self.components.nightvision:SetFalloff(.5) self.components.nightvision:SetIntensity(.5) self.components.nightvision:SetColour(0/255,40/255,255/255) self:ListenForEvent("keypressed", OnKeyPressed) return selfendAddPrefabPostInit("wilson", Wilson)function GruePostInit(self) self._CheckForStart = self.CheckForStart self._OnUpdate = self.OnUpdate function self:CheckForStart() if self.inst.components.nightvision then return self.inst.components.nightvision.enabled and self:_CheckForStart() else return self:_CheckForStart() end end function self:OnUpdate(dt) if not self.sleeping and self.inst.components.nightvision and self.inst.components.nightvision.enabled then print("Prefab: "..self.inst.prefab.." does have nightvision.") self:Stop() return else print("Prefab: "..self.inst.prefab.." does not have nightvision.") self:_OnUpdate(dt) end end return selfendAddComponentPostInit("grue", GruePostInit) I think the major issue lies in the event "enterlight" which is called upon the host enabling the Light component/class. There seems to be a data variable being sent, however, nothing in the data variable is being used by any instance that is listening for the "enterlight" event. I guess we will have to wait and see how Klei fixes nightvision they might have a custom solution to the problem. Edited January 9, 2015 by Kzisor Link to comment Share on other sites More sharing options...
Woodside235 Posted January 9, 2015 Author Share Posted January 9, 2015 @ Charlie still attacks in the dark with this enabled, was that intentional? Link to comment Share on other sites More sharing options...
Kzisor Posted January 9, 2015 Share Posted January 9, 2015 (edited) @Woodside235, charlie should not attack if you have it enabled. However, charlie will attack if you do not have it enabled. The server must also be running this mod with it enabled for it to work properly. So apparently I am an idiot and forgot to update the code before posting. It's been updated with the proper code. I was actually modifying the code as I was typing my post so hopefully the edited code works like it's suppose to for clients. NOTE: THIS DOES NOT FIX THE ISSUE WITH CLIENTS GETTING PROTECTION WHEN HOSTS HAVE PROTECTION FORM CHARLIE. Edited January 9, 2015 by Kzisor Link to comment Share on other sites More sharing options...
Woodside235 Posted January 9, 2015 Author Share Posted January 9, 2015 @Kzisor Where does that key handler come from in the modified code? The game doesn't like it. Link to comment Share on other sites More sharing options...
Kzisor Posted January 9, 2015 Share Posted January 9, 2015 @Woodside235, that can be removed. Sorry I will remove it from the example. Thank you for catching that. Link to comment Share on other sites More sharing options...
Woodside235 Posted January 10, 2015 Author Share Posted January 10, 2015 @Kzisor Strange bug I found. If you join a map and it's already night time, you'll be protected from charlie but you won't have night vision. Link to comment Share on other sites More sharing options...
Kzisor Posted January 10, 2015 Share Posted January 10, 2015 Woodside235, bugs are to be expected from semi-working code. The code I posted was never mean't to be used yet as it's not fully functional and bug free. By using it, you're doing so under your own risk and until Klei supports true nightvision we probably won't have fully working code. However, I've got some new ideas on how to make it possibly work. 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