Jump to content

Help with Character Mod Creation


Recommended Posts

Alright, so I'm trying to make a character mod. There are a few things that I have no idea how to do and have been unable to figure out after about an hour of google-ing. The things that I would like to change with my character are:

  • Movement speed based on time of day (day/dusk/night)
  • Health regen based on rain/wetness (and removing sanity drain from rain)
  • Damage per second taken from fire and freezing

If this needs stating, I am very new to coding in lua. If you can help, then it is much appreciated. Thanks in advance :-)

Link to comment
Share on other sites

I assume you know some basics of the language though?

local speed = {day = 1, dusk = 1.2, night = 1.4} --Tweak those as you wantlocal function onphase()   inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED*speed[TheWorld.state.phase]endinst:ListenForEvent("phasechanged", onphase, TheWorld) --We want the speed to change along the phasesonphase() --And right after the character spawns
local function checkregen()    if inst.components.moisture:IsWet() then        inst.components.health:StartRegen(1, 5) --Again, you can tweak those. Now it's 1 point every 5 seconds    else        inst.components.health:StopRegen()    endendinst:ListenForEvent("moisturedelta", checkregen)checkregen()
inst.components.temperature.hurtrate = 1.25 --Unfortunately, freezing and overheating share the same damage. By default it's 1.25 a secondinst.components.health.fire_damage_scale = 1

There you go. All of the above should go into the master_postinit function in your character's .lua file.

Edited by przemolsz
Link to comment
Share on other sites

I assume you know some basics of the language though?

local speed = {"day" = 1, "dusk" = 1.2, "night" = 1.4} --Tweak those as you wantlocal function onphase()   inst.components.locomotor.runspeed = TUNING.WILSON_RUN_SPEED*speed[TheWorld.state.phase]endinst:ListenForEvent("phasechanged", onphase, TheWorld) --We want the speed to change along the phasesonphase() --And right after the character spawns
local function checkregen()    if inst.components.moisture:IsWet() then        inst.components.health:StartRegen(1, 5) --Again, you can tweak those. Now it's 1 point every 5 seconds    else        inst.components.health:StopRegen()    endendinst:ListenForEvent("moisturedelta", checkregen)checkregen()
inst.components.temperature.hurtrate = 1.25 --Unfortunately, freezing and overheating share the same damage. By default it's 1.25 a secondinst.components.health.fire_damage_scale = 1

There you go. All of the above should go into the master_postinit function in your character's .lua file.

 

First of all, thank you very much for helping :)

The mod is running into a few issues. When I turn on the mod, the game gives me an error with the line where the variable "speed" is defined, saying "'}' expected near '='"

I temporarily changed the portion within the {} to 2, and that fixed that error. But now, whenever I choose the character when joining a world, it gives me an error like this:

"attempt to index upvalue 'speed' (a number value)"

targeted at the line where "speed" is multiplied by Wilson's speed.

I have tried a few things to fix this, none have worked. If you know anything about these errors, it would mean a lot to me. Thank you for helping in the first place, and thanks even more if you continue to help. :lemo:

Link to comment
Share on other sites

Whoops. The quotes around "day", "dusk" and "night" were unnecessary. Fixed it.

 

That fixed it, thank you so much <3

It's gonna take a bit to balance out everything and get the animations done, but I'm hoping to have the mod done relatively soon. Thanks for your assistance :joyous:

Link to comment
Share on other sites

Okay, new issue. The health regen during rain does not seem to be working. I would also like to possibly lower the rate at which my character gets wet. If you can help, thanks a ton, this should be the last issue. Again, thanks for helping so far, it means a lot :)

Link to comment
Share on other sites

@rubikluke

Sorry for such a late reply, I didn't even notice that you replied once more. If the issue still exists, you should change the regeneration code to:

local function checkregen(_, data)    if ((inst.components.moisture:GetMoisture() > 0) or TheWorld.state.israining) then        if not (inst.components.health.regen and inst.components.health.regen.task) then        inst.components.health:StartRegen(1, 5) --1 point every 5 seconds        end    else        inst.components.health:StopRegen()    endendinst:ListenForEvent("weathertick", checkregen, TheWorld)checkregen()

For the moisture rate, use:

inst.components.moisture:SetInherentWaterproofness(0.9) --gives your character additional rain protection just like waterproof clothes. 0 is no waterproofness, 1 is absolute. Umbrella has 0.9
Edited by przemolsz
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...