Jump to content

[SOLVED] Question.


Recommended Posts

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 :D!!

Edited by SuperDavid
Link to comment
Share on other sites

@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 by rezecib
Link to comment
Share on other sites

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

@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 by SuperDavid
Link to comment
Share on other sites

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

@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

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

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
 Share

×
  • Create New...