Jump to content

Coding help related to weather


Recommended Posts

I’m making a rather simple character, strong in the cold, weak in the heat.  I’m currently using the player’s heat to determine their stats, but for some reason that’s not working yet..  the stats are set initially, but don’t charge when their temps turn changes.  I think it might be tied to the ambient temps true, but don’t exothermic fires play into that?

I also tried having their stats change based on the phase of the moon, but the full moon is so rare it’s hard to test.

I’d like to fix these, but also cause their stats to change during snowstorms.  Does anyone know how to do that?

oh, and I know most people affect the character’s sanity using a small aura, but how it looks like a lot of code for simply causing sanity to decrease.  Is there no simpler way?  I’ve yet to try coding auras.

Link to comment
Share on other sites

You can make a character more powerful depending on the temperature using inst:GetTemperature(). Add a listener for "temperaturedelta" to you your character and make a simple math equation that calculates the damage multiplier. Then you can use inst.components.combat.damagemultiplier = your_damage_multiplier to set it up.

EDIT

For the fullmoon buff you can use inst:WatchWorldState("isfullmoon", YourFunction) and externaldamagemultiplier. 

Externaldamagemultiplier has 3 values in it - source (which is usually inst), value (e.g 1.25, which translates to 125% damage) and a key (a unique name for your damagemodifier so you can later remove it using RemoveModifier)

The function should look something like this:

local function YourFunction(inst) -- You can change the name of the function to whatever you want
	if inst.components.combat ~= nil and inst.components.health ~= nil then -- Checking for nil values to prevent crashing
		if GLOBAL.TheWorld.state.isfullmoon then -- Checking if it's full moon
			inst.components.combat.externaldamagemultipliers:SetModifier(inst, 1.25, "fullmoon_buff") -- Setting an external damage multiplier with (source, value, key)
			inst.components.health:SetMaxHealth(250) -- Buffing the hp a little bit
		else -- If it's not full moon
			inst.components.combat.externaldamagemultipliers:RemoveModifier(inst, "fullmoon_buff") -- Remove external damage multiplier with (source, key)
			inst.components.health:SetMaxHealth(TUNING.WILSON_HEALTH) -- Setting the hp back to normal (in my case I used Wilson as example so I set it back to Wilsons original hp)
		end
	end
end

 

The only problem with this code is that the hp will always be max when its max value is changed. Using this should fix the issue tho:

local function OnIsFullmoon(inst)
	if inst.components.health ~= nil and inst.components.combat ~= nil then
		
		local hp_percent = inst.components.health:GetPercent() -- Before changing the hp, get its percentage
		
		if GLOBAL.TheWorld.state.isfullmoon then
			inst.components.combat.externaldamagemultipliers:SetModifier(inst, 1.25, "fullmoon_buff")
			inst.components.health:SetMaxHealth(250)
			inst.components.health:SetCurrentHealth(hp_percent * inst.components.health.maxhealth) -- Then set hp percent after the change
		else
			inst.components.combat.externaldamagemultipliers:RemoveModifier(inst, "fullmoon_buff")
			inst.components.health:SetMaxHealth(TUNING.WILSON_HEALTH)
			inst.components.health:SetCurrentHealth(hp_percent * inst.components.health.maxhealth) -- Then set hp percent after the change
		end
	end
end

 

Edited by IThatGuyI
  • Like 1
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...