Sannom Posted January 7, 2015 Share Posted January 7, 2015 So. Whenever a character that emits light ( Example: A character with a lightbulb for a head ) dies and gets revived in DST, it comes back... without the light. At least, for me.Here's what I did-- I'm probably forgetting something. local function stuff(inst) inst.entity:AddLight() inst.Light:SetRadius(2.5) inst.Light:SetFalloff(.5) inst.Light:SetIntensity(0.3) inst.Light:SetColour(245/255,255/255,245/255) inst.Light:Enable(true)endlocal master_postinit = function(inst) -- choose which sounds this character will play inst.soundsname = "wilson" inst:ListenForEvent("ms_respawnedfromghost", stuff) stuff(inst) endOf course, this is in the prefabs file.Oh and if it was possible, could anyone suggest code solution for being able to emit light -only- at night? That would be neat. I can't seem to nail one. Link to comment https://forums.kleientertainment.com/forums/topic/48578-emit-light-resets-after-revive/ Share on other sites More sharing options...
Batmanwarrior Posted January 7, 2015 Share Posted January 7, 2015 @SannomI can help you with the light on night-only. Make a function with these lines of code:local function nightlight(inst)if TheWorld.state.phase == "day" theninst.Light:Enable(false)elseif TheWorld.state.phase == "dusk" theninst.Light:Enable(false)elseif TheWorld.state.phase == "night" theninst.Light:Enable(true)inst.Light:SetRadius(2.5)inst.Light:SetFalloff(0.5)inst.Light:SetIntensity(.3)inst.Light:SetColour(245/255,255/255,245/255)endend And also a periodic task that will check constantly if it's day or night:local timecheck = 1/5inst:DoPeriodicTask(timecheck, function() nightlight(inst, timecheck) end) That should do the trick It will also solve the issue where the light turns off when you revive, because the function will constantly be ran every 1/5 of a second. Best regards Link to comment https://forums.kleientertainment.com/forums/topic/48578-emit-light-resets-after-revive/#findComment-598174 Share on other sites More sharing options...
Kzisor Posted January 7, 2015 Share Posted January 7, 2015 @Batmanwarrior, having a task run every 1/5 of a second could result in performance issues. There are a lot cleaner ways of handling this in DST. @Sannom, for night only light emition simply watch for the world state for phase change. Example:local function PhaseChanged(inst, phase) if phase == "night" then inst.Light:Enabled(true) -- DO OTHER LIGHT THINGS HERE. else -- WE DON'T CARE ABOUT CHECKING OTHER PHASE TYPES, WE ONLY CARE ABOUT NIGHT. -- LIGHT WILL BE DISABLED ON ALL OTHER PHASES. inst.Light:Enabled(false) endendlocal fn(inst)inst:WatchWorldState("phase", PhaseChanged)return instend As far as your respawned from ghost function, you should check to see if there is a light already on the character instead of constantly adding additional lights, that is bad practice and could lead to memory leakage. Example:local function stuff(inst) if not inst.Light then inst.entity:AddLight() end inst.Light:SetRadius(2.5) inst.Light:SetFalloff(.5) inst.Light:SetIntensity(0.3) inst.Light:SetColour(245/255,255/255,245/255) inst.Light:Enable(true) end local master_postinit = function(inst) -- choose which sounds this character will play inst.soundsname = "wilson" inst:ListenForEvent("ms_respawnedfromghost", stuff) -- ADDED THIS LINE TO ENSURE WE HAVE RESPAWNED. -- ITS PUSHED FROM THE HEALTH COMPONENT. inst:ListenForEvent("respawn", stuff) stuff(inst) end I'm not saying that this will work after a revive, I'm simply stating that it might reduce further issues in the future. Link to comment https://forums.kleientertainment.com/forums/topic/48578-emit-light-resets-after-revive/#findComment-598277 Share on other sites More sharing options...
rezecib Posted January 7, 2015 Share Posted January 7, 2015 @Sannom, All characters have light already (it's used when being a ghost). So you don't ever need to add light to a character, you just need to enable it and tweak its brightness/radius/etc. And I would use an approach like Kzisor suggested, but I think using inst:WatchWorldState("startnight", somefunction) and "startday" would be the minimalist way to do it. As long as you also have it run the somefunction when the character spawns in and gets revived, it should be fine. Link to comment https://forums.kleientertainment.com/forums/topic/48578-emit-light-resets-after-revive/#findComment-598338 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