Jump to content

How to make character slowly depending on the moisture on their body? (DST)


Recommended Posts

Hey so I've been thinking of making a Koro Sensei mod (Assassination classroom), and he moves slower in the rain, however i can not figure out how to create a attribute like that, I have seen the post about basic perks to your character

however that does not work with dont starve together, someone please help im stupid at coding

korosensei.lua

Edited by Koro sensei
Link to comment
Share on other sites

You could always listen for the "moisturedelta" event on the player's moisture component, and make it call a custom function in your script. which updates the runspeed and walkspeed variables of the player's locomotor component, depending on the "new" variable. Something like this:

local function myMoisureDeltaFunction(inst, data)
	-- data.new holds the new value, and data.old holds the old value. Check out the PushEvent call in the moisture component code.
	-- Do some nice calculation for figuring out how much to lower the movement speed depending on how wet he is.
	-- The following is PSEUDO CODE. I can't remember the possible moisture values, but if the maximum moisture is 100,
	-- then the following will lower his movement speed to 0 when moisture is 100, which is probably not what you want,
	-- but it's an example.
	var speedRatio = (100 - data.new) / 100
	-- normalWalkSpeed and normalRunSpeed should be saved somewhere at the start of your script, so you always know which
	-- value to return to when the player is no longer wet.
	inst.components.locomotor.walkspeed = normalWalkSpeed * speedRatio
	inst.components.locomotor.runspeed = normalRunSpeed * speedRatio
end

-- At the bottom of your player initialization function, add this.
inst:ListenForEvent("moisturedelta", myMoistureDeltaFunction)

 

Edited by Ultroman
Link to comment
Share on other sites

On 9/30/2018 at 9:36 AM, Ultroman said:

You could always listen for the "moisturedelta" event on the player's moisture component, and make it call a custom function in your script. which updates the runspeed and walkspeed variables of the player's locomotor component, depending on the "new" variable. Something like this:


local function myMoisureDeltaFunction(inst, data)
	-- data.new holds the new value, and data.old holds the old value. Check out the PushEvent call in the moisture component code.
	-- Do some nice calculation for figuring out how much to lower the movement speed depending on how wet he is.
	-- The following is PSEUDO CODE. I can't remember the possible moisture values, but if the maximum moisture is 100,
	-- then the following will lower his movement speed to 0 when moisture is 100, which is probably not what you want,
	-- but it's an example.
	var speedRatio = (100 - data.new) / 100
	-- normalWalkSpeed and normalRunSpeed should be saved somewhere at the start of your script, so you always know which
	-- value to return to when the player is no longer wet.
	inst.components.locomotor.walkspeed = normalWalkSpeed * speedRatio
	inst.components.locomotor.runspeed = normalRunSpeed * speedRatio
end

-- At the bottom of your player initialization function, add this.
inst:ListenForEvent("moisturedelta", myMoistureDeltaFunction)

 

u-uh........ i don't really know how to do it... but i get how it works now, I'll try my best, thank you!

Edited by Koro sensei
Link to comment
Share on other sites

Read some of the tutorials pinned in this forum ([Don't Starve Together] Mods and Tools). If you don't know LUA scripting, there's a crash course here, and that site has a bunch more advanced tutorials. You kind of need to learn scripting in order to make mods. There's no easy mode. The code I presented is almost complete for your purposes.

Link to comment
Share on other sites

On 10/1/2018 at 9:28 PM, Ultroman said:

Read some of the tutorials pinned in this forum ([Don't Starve Together] Mods and Tools). If you don't know LUA scripting, there's a crash course here, and that site has a bunch more advanced tutorials. You kind of need to learn scripting in order to make mods. There's no easy mode. The code I presented is almost complete for your purposes.

alright, thanks so much for your help! I'll just try to poke around with wx78's lua

edit:(quick question where exactly is the player initialization function? is it the "local common_postinit = function(inst)" at -- This initializes for both the server and client. Tags can be added here."

Edited by Koro sensei
Link to comment
Share on other sites

Download a popular character mod, which has seen an update within the last 2 months, and look at the code. That's really the best way to figure out how to do things. I can't remember all this stuff, and I don't have time ATM to look. Sorry.

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...