Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

CBuizel

[Custom Character] Gain health while raining or wet?

Recommended Posts

CBuizel    0

I'm trying to create a character (not a robot) that, in contrast to WX78, gains health from rain rather than lose it. 

I've looked into WX78's lua, but I'm not certain with what I should be looking for. I figured it would be the rainsparks function, but it didn't seem like the one...
 

local function dorainsparks(inst, dt)local mitigates_rain = falsefor k,v in pairs (inst.components.inventory.equipslots) doif v.components.dapperness thenif v.components.dapperness.mitigates_rain thenmitigates_rain = trueendendendif GetSeasonManager() and GetSeasonManager():IsRaining() and not mitigates_rain theninst.spark_time = inst.spark_time - dtif inst.spark_time <= 0 then--GetClock():DoLightningLighting()inst.spark_time = 3+math.random()*2inst.components.health:DoDelta(-.5, false, "rain")local pos = Vector3(inst.Transform:GetWorldPosition())pos.y = pos.y + 1 + math.random()*1.5local spark = SpawnPrefab("sparks")spark.Transform:SetPosition(pos:Get())endendend 

 
Basically, what would I have to use to make my character love the rain (gain health from it)?

Share this post


Link to post
Share on other sites
Amalleus    13

One question... Don't you see keywords in the text-code which you attached? =(

You want robot to gain health, 154 string does lower health 

DoDelta(-.5, false, "rain")

1. -.5 means lose health by 0.5.

2. false as i remember defined to godmod

3. why he lost health - because of "rain"

What time needed to lose health - read conditions before

Share this post


Link to post
Share on other sites
CBuizel    0

One question... Don't you see keywords in the text-code which you attached? =(

You want robot to gain health, 154 string does lower health 

DoDelta(-.5, false, "rain")

1. -.5 means lose health by 0.5.

2. false as i remember defined to godmod

3. why he lost health - because of "rain"

What time needed to lose health - read conditions before

Oh wow, I need to get a stronger prescription for my glasses xD Thank you for pointing that out, I will test this out...

Share this post


Link to post
Share on other sites
CBuizel    0

Actually, I tried
 

inst.components.health:DoDelta(-.5, false, "rain")-- Also tried the belowinst.components.health:DoDelta(-.5, true, "rain")

Both did not work. My character didn't care that it was raining at all. No damage taken. There has to be much more code to it than this single line. I'll have to dig deeper... unless somebody can help me out if they know what I should do. Ultimately, I want to also set the movement speed to something greater while raining as well. But first I want to restore health when raining.

Share this post


Link to post
Share on other sites
Amalleus    13

I didn't tell you that only this string will make your character to always regen or degen health if it is raining. Dude, learn programming, mostly about how code works and about "if else" conditions

As i told earlier i may repeat

inst.components.health:DoDelta(-.5, false, "rain")

this string only makes manipulation with health. Right in this one: lower current health of "inst" by -0.5

there is no conditions to repeat it again so it will do it once after game starts (if it is not in repeated events)

Share this post


Link to post
Share on other sites
CBuizel    0

Thanks. I am learning programming; I'm not the best, but I'm learning.
I've gotten it to work now and it won't have any visual effects. It'll just regenerate health every second or two while raining.

In the charactermod.lua:
 

local function dorainheal(inst, dt)	local mitigates_rain = false	for k,v in pairs (inst.components.inventory.equipslots) do		if v.components.dapperness then			if v.components.dapperness.mitigates_rain then				mitigates_rain = true			end		end			end	    if GetSeasonManager() and GetSeasonManager():IsRaining() and not mitigates_rain then    	inst.heal_time = inst.heal_time - dt    	if inst.heal_time <= 0 then    		inst.heal_time = 3+math.random()*2    		inst.components.health:DoDelta(0.5, false, "rain") -- Adjust health regen in rain		local pos = Vector3(inst.Transform:GetWorldPosition())		pos.y = pos.y + 1 + math.random()*1.5			    	end    endend

In the charactermod.lua, within the "local fn = function(inst)", add these lines

inst.heal_time = 3
inst:DoPeriodicTask(1/10, function() dorainheal(inst, 1/10) end)

Share this post


Link to post
Share on other sites