. . . Posted August 28, 2016 Share Posted August 28, 2016 (edited) Hello, I have a question ! So, when my character enters a certain mode would it be possible to make him exhale frosty breath even when it's not Winter and then be able to cancel it too? Any help would be appreciated, thank you very much & have a wonderful day/night !! Edited August 28, 2016 by SuperDavid Link to comment Share on other sites More sharing options...
rezecib Posted August 28, 2016 Share Posted August 28, 2016 (edited) @SuperDavid Yes. It's controlled by the frostybreather component. Probably the easiest way to do it would be to have your character's master_postinit override FrostyBreather:OnTemperatureChanged: local _OnTemperatureChanged = inst.components.frostybreather.OnTemperatureChanged inst.components.frostybreather.OnTemperatureChanged = function(self, ...) if <however you are keeping track of which state he is in> then self:StartBreath() else _OnTemperatureChanged(self, ...) end end And you might also want to throw in an inst.components.frostybreather:StartBreath()/StopBreath() when transforming in case the world temperature is very stable and OnTemperatureChanged doesn't get called. Edit: Oops, frostybreather exists on clients rather than just the server, so you also need some networking like DarkXero did below. Edited August 28, 2016 by rezecib Link to comment Share on other sites More sharing options...
DarkXero Posted August 28, 2016 Share Posted August 28, 2016 I did it like this. modmain.lua local require = GLOBAL.require local TUNING = GLOBAL.TUNING local frostybreather = require("components/frostybreather") local _OnTemperatureChanged = frostybreather.OnTemperatureChanged frostybreather.OnTemperatureChanged = function(self, temperature) if self.insanebreath and self.insanebreath:value() then temperature = TUNING.FROSTY_BREATH - 1 end _OnTemperatureChanged(self, temperature) end character.lua local function InsaneFrostyBreather(inst) inst.components.frostybreather.insanebreath:set(not inst.replica.sanity:IsSane()) inst.components.frostybreather:OnTemperatureChanged(TheWorld.state.temperature) end local function common_postinit(inst) inst.components.frostybreather.insanebreath = net_bool(inst.GUID, "player.insanebreath") inst.components.frostybreather.insanebreath:set(false) inst:ListenForEvent("sanitydelta", InsaneFrostyBreather) end Link to comment Share on other sites More sharing options...
. . . Posted August 28, 2016 Author Share Posted August 28, 2016 (edited) @DarkXero Sorry but would it be okay you tell me how the frosty breath to activate when he enters "inst.gelid_mode == true" because that's when he's suppose to do frosty breath not when he's insane, sorry I should've said that when I first posted . I tried changing your code but the server doesn't even load anymore, maybe you can help me if you want, sorry ... local function GelidBreath(inst) inst.components.frostybreather.gelidbreath:set(inst.gelid_mode == true()) inst.components.frostybreather:OnTemperatureChanged(TheWorld.state.temperature) end local function common_postinit(inst) inst.components.frostybreather.gelidbreath = net_bool(inst.GUID, "player.gelidbreath") inst.components.frostybreather.gelidbreath:set(false) inst:ListenForEvent("sanitydelta", GelidBreath) end local require = GLOBAL.require local TUNING = GLOBAL.TUNING local frostybreather = require("components/frostybreather") local _OnTemperatureChanged = frostybreather.OnTemperatureChanged frostybreather.OnTemperatureChanged = function(self, temperature) if self.gelidbreath and self.gelidbreath:value() then temperature = TUNING.FROSTY_BREATH - 1 end _OnTemperatureChanged(self, temperature) end Edited August 28, 2016 by SuperDavid Link to comment Share on other sites More sharing options...
rezecib Posted August 28, 2016 Share Posted August 28, 2016 16 minutes ago, SuperDavid said: inst.components.frostybreather.gelidbreath:set(inst.gelid_mode == true()) true is not a function, so the parentheses after it will cause a crash. Also you can just use inst.gelid_mode, assuming that it's true or false already. You only need to use == when you want to convert something that's not boolean (true/false) into something that is. Link to comment Share on other sites More sharing options...
. . . Posted August 28, 2016 Author Share Posted August 28, 2016 8 minutes ago, rezecib said: inst.gelid_mode, assuming that it's true or false already I can use inst.gelid_mode even though it always switches between nil & true? Link to comment Share on other sites More sharing options...
rezecib Posted August 28, 2016 Share Posted August 28, 2016 @SuperDavid I think so. Lua interprets nil to be false when you use it as a boolean. Link to comment Share on other sites More sharing options...
. . . Posted August 28, 2016 Author Share Posted August 28, 2016 @rezecib I put inst.components.frostybreather.gelidbreath:set(inst.gelid_mode) instead of inst.components.frostybreather.gelidbreath:set(inst.gelid_mode == true()) And I get this crash now [00:00:17]: [string "../mods/Adam DST Mod/scripts/prefabs/adam.l..."]:992: calling 'set' on bad self (boolean expected, got nil) LUA ERROR stack traceback: =[C]:-1 in (method) set (C) <-1--1> ../mods/Adam DST Mod/scripts/prefabs/adam.lua:992 in (local) fn (Lua) <991-994> scripts/entityscript.lua:972 in (method) PushEvent (Lua) <959-986> scripts/components/sanity.lua:205 in (method) DoDelta (Lua) <184-229> scripts/components/sanity.lua:150 in (method) SetMax (Lua) <147-151> scripts/prefabs/player_common.lua:1738 in (field) fn (Lua) <1536-1844> scripts/mainfunctions.lua:146 in () ? (Lua) <135-177> I don't understand Link to comment Share on other sites More sharing options...
rezecib Posted August 28, 2016 Share Posted August 28, 2016 @SuperDavid It's saying that inst.components.frostybreather.gelidbreath is nil, which means that code is running before you create it somehow. It's not obvious to me how that's happening from the code you've shown, but maybe you can figure it out from that. Link to comment Share on other sites More sharing options...
DarkXero Posted August 28, 2016 Share Posted August 28, 2016 modmain.lua: local require = GLOBAL.require local TUNING = GLOBAL.TUNING local frostybreather = require("components/frostybreather") local _OnTemperatureChanged = frostybreather.OnTemperatureChanged frostybreather.OnTemperatureChanged = function(self, temperature) if self.gelidbreath and self.gelidbreath:value() then temperature = TUNING.FROSTY_BREATH - 1 end _OnTemperatureChanged(self, temperature) end character.lua: local function GelidFrostyBreather(inst) inst.components.frostybreather:OnTemperatureChanged(TheWorld.state.temperature) end local function common_postinit(inst) inst.components.frostybreather.gelidbreath = net_bool(inst.GUID, "player.gelidbreath", "gelidbreathdirty") inst.components.frostybreather.gelidbreath:set(false) inst:ListenForEvent("gelidbreathdirty", GelidFrostyBreather) end local function master_postinit(inst) inst:WatchWorldState("temperature", function(inst) inst.components.frostybreather.gelidbreath:set(inst.gelid_mode or false) end) end Link to comment Share on other sites More sharing options...
. . . Posted August 28, 2016 Author Share Posted August 28, 2016 @DarkXero Thank you, thank you, thank you so, so, so, so, so much !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 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