Jump to content

How can I make these small changes? (attempting to create a more challenging WX-78 experience)


Kempshaw

Recommended Posts

Hello guys!

I just want to change these things for playing WX-78:

- Hunger drain x3

- Sanity drain x2

- Damage received x1,5

- Infinite number of gears that can be consumed to increase my stats from.

Compatible with Hamlet, Shipwrecked and RoG.

I have tried to look around to learn how to make these changes, and I have found a couple of videos, but I still don't understand how I can make these changes really. For example, in the wx78.lua file I found the "local max_upgrades = 15" and I changed it up to 5000, but when I load up the game and try it out it still doesn't change anything?? And for the other stuff I couldn't find anything at all, but I don't understand the coding language anyway (except for what is obvious).

So how on earth do I make these seemingly easy modifications to my game? Any pointers?

Link to comment
Share on other sites

You should not be replacing game files directly. That will likely make your mod incompatible with other mods. You should use the modding API to make changes. Most of these are easy to change. A question, though.

On 28.9.2019 at 2:50 PM, Kempshaw said:

- Sanity drain x2

Sanity drain from what, exactly? Everything? Just dusk/night? Also the enemy sanity auras? Wetness? Having wet items in the inventory? Having wet items equipped?

Now to the things I can help you with.

To start with, in order to edit WX78, you need this in your modmain.lua:

AddPrefabPostInit("wx78", function(inst)
	-- Put the code snippets below in here.
end)

This makes use of the modding API to make changes, so use this instead of editing the wx78.lua file directly. Delete that file from your mod, and only use the modmain.lua.

 

On 28.9.2019 at 2:50 PM, Kempshaw said:

- Damage received x1,5

The code snippet below will make WX78 take more damage from things attacking it/him. Note that this does not affect damage from starving, drowning, eating, picking roses or evil flowers, etc. Just combat. The other things can be changed using TUNING variables.

local oldGetAttacked = inst.components.combat.GetAttacked
inst.components.combat.GetAttacked = function(self, attacker, damage, weapon, stimuli, ...)
	oldGetAttacked(self, attacker, damage * 1.5, weapon, stimuli, ...)
end

 

On 28.9.2019 at 2:50 PM, Kempshaw said:

- Hunger drain x3

This code snippet should do what you want.

inst.components.hunger:AddBurnRateModifier("my_unique_burnrate_modifier_name", 3.0)

 

On 28.9.2019 at 2:50 PM, Kempshaw said:

- Infinite number of gears that can be consumed to increase my stats from.

In this particular case, you will probably have to basically copy the local function, alter it to your liking, and then override the original oneat function for WX78. I don't like it, but this is where we're at. Also, it calls this local function applyupgrades() in the fn() function, which could be a problem, but with the way it's made, it should actually work if we just call our own function afterwards.

local _G = GLOBAL
local _T = _G.TUNING
-- Change this to whatever you want, but be sensible about it.
local max_upgrades = 9999

-- The following three lines change the maximum hunger, health and sanity achievable
-- in a way that is proportionate to the original maximum values.
-- If we did not do this, you would simply need the new max_upgrades amount of
-- upgrades in order to reach the original maximum values.
-- This way, level 15 will yield the same values as they normally would, but lets
-- the values continue to increase at the same rate for each upgrade beyond that.
-- If you want to set the maximum hunger, health and sanity to custom values,
-- simply replace the calculations with the numbers you want.
-- You can also set _T.WX78_MIN_HUNGER, _T.WX78_MIN_HEALTH and
-- _T.WX78_MIN_SANITY to whatever starting values you want for WX78.
_T.WX78_MAX_HUNGER = _T.WX78_MAX_HUNGER / 15 * max_upgrades
_T.WX78_MAX_HEALTH = _T.WX78_MAX_HEALTH / 15 * max_upgrades
_T.WX78_MAX_SANITY = _T.WX78_MAX_SANITY / 15 * max_upgrades

-- A copy of the original function from the game code, but altered a little bit
-- to use our new maximum level, and to work from the modmain.
local function myapplyupgrades(inst)
	local upgrades = math.min(inst.level, max_upgrades)

	local hunger_percent = inst.components.hunger:GetPercent()
	local health_percent = inst.components.health:GetPercent()
	local sanity_percent = inst.components.sanity:GetPercent()

	inst.components.hunger.max = math.ceil(_T.WX78_MIN_HUNGER + upgrades* (_T.WX78_MAX_HUNGER - _T.WX78_MIN_HUNGER)/max_upgrades)
	inst.components.health.maxhealth = math.ceil(_T.WX78_MIN_HEALTH + upgrades* (_T.WX78_MAX_HEALTH - _T.WX78_MIN_HEALTH)/max_upgrades)
	inst.components.sanity.max = math.ceil(_T.WX78_MIN_SANITY + upgrades* (_T.WX78_MAX_SANITY - _T.WX78_MIN_SANITY)/max_upgrades)

	inst.components.hunger:SetPercent(hunger_percent)
	inst.components.health:SetPercent(health_percent)
	inst.components.sanity:SetPercent(sanity_percent)
end

-- The original oneat function already increments the level, and allows it to become higher
-- than the max level (for some reason). It also plays all the pulses and sounds, regardless
-- of whether you have already reached the maximum level.
-- So, all we have to do, is call the original function, and then call ours.
local origoneat = inst.components.eater.oneatfn
local function myoneat(inst, food)
	origoneat(inst, food)
	if food and food.components.edible and food.components.edible.foodtype == "GEARS" then
		myapplyupgrades(inst)
	end
end
inst.components.eater:SetOnEatFn(myoneat)

-- The game code also calls the applyupgrades function in the preload function,
-- so we have to do the same there as we did for the oneat function.
local origonpreload = inst.OnPreLoad

local function myonpreload(inst, data)
	origonpreload(inst, data)
	if data then
		if data.level then
			inst.level = data.level
			myapplyupgrades(inst)
			--re-set these from the save data, because of load-order clipping issues
			if data.health and data.health.health then inst.components.health.currenthealth = data.health.health end
			if data.hunger and data.hunger.hunger then inst.components.hunger.current = data.hunger.hunger end
			if data.sanity and data.sanity.current then inst.components.sanity.current = data.sanity.current end
			inst.components.health:DoDelta(0)
			inst.components.hunger:DoDelta(0)
			inst.components.sanity:DoDelta(0)
		end
	end
end
inst.OnPreLoad = myonpreload

 

Link to comment
Share on other sites

On 10/1/2019 at 7:53 AM, Ultroman said:

You should not be replacing game files directly. That will likely make your mod incompatible with other mods. You should use the modding API to make changes. Most of these are easy to change. A question, though.

Sanity drain from what, exactly? Everything? Just dusk/night? Also the enemy sanity auras? Wetness? Having wet items in the inventory? Having wet items equipped?

Now to the things I can help you with.

To start with, in order to edit WX78, you need this in your modmain.lua:


AddPrefabPostInit("wx78", function(inst)
	-- Put the code snippets below in here.
end)

This makes use of the modding API to make changes, so use this instead of editing the wx78.lua file directly. Delete that file from your mod, and only use the modmain.lua.

 

The code snippet below will make WX78 take more damage from things attacking it/him. Note that this does not affect damage from starving, drowning, eating, picking roses or evil flowers, etc. Just combat. The other things can be changed using TUNING variables.


local oldGetAttacked = inst.components.combat.GetAttacked
inst.components.combat.GetAttacked = function(self, attacker, damage, weapon, stimuli, ...)
	oldGetAttacked(self, attacker, damage * 1.5, weapon, stimuli, ...)
end

 

This code snippet should do what you want.


inst.components.hunger:AddBurnRateModifier("my_unique_burnrate_modifier_name", 3.0)

 

In this particular case, you will probably have to basically copy the local function, alter it to your liking, and then override the original oneat function for WX78. I don't like it, but this is where we're at. Also, it calls this local function applyupgrades() in the fn() function, which could be a problem, but with the way it's made, it should actually work if we just call our own function afterwards.


local _G = GLOBAL
local _T = _G.TUNING
-- Change this to whatever you want, but be sensible about it.
local max_upgrades = 9999

-- The following three lines change the maximum hunger, health and sanity achievable
-- in a way that is proportionate to the original maximum values.
-- If we did not do this, you would simply need the new max_upgrades amount of
-- upgrades in order to reach the original maximum values.
-- This way, level 15 will yield the same values as they normally would, but lets
-- the values continue to increase at the same rate for each upgrade beyond that.
-- If you want to set the maximum hunger, health and sanity to custom values,
-- simply replace the calculations with the numbers you want.
-- You can also set _T.WX78_MIN_HUNGER, _T.WX78_MIN_HEALTH and
-- _T.WX78_MIN_SANITY to whatever starting values you want for WX78.
_T.WX78_MAX_HUNGER = _T.WX78_MAX_HUNGER / 15 * max_upgrades
_T.WX78_MAX_HEALTH = _T.WX78_MAX_HEALTH / 15 * max_upgrades
_T.WX78_MAX_SANITY = _T.WX78_MAX_SANITY / 15 * max_upgrades

-- A copy of the original function from the game code, but altered a little bit
-- to use our new maximum level, and to work from the modmain.
local function myapplyupgrades(inst)
	local upgrades = math.min(inst.level, max_upgrades)

	local hunger_percent = inst.components.hunger:GetPercent()
	local health_percent = inst.components.health:GetPercent()
	local sanity_percent = inst.components.sanity:GetPercent()

	inst.components.hunger.max = math.ceil(_T.WX78_MIN_HUNGER + upgrades* (_T.WX78_MAX_HUNGER - _T.WX78_MIN_HUNGER)/max_upgrades)
	inst.components.health.maxhealth = math.ceil(_T.WX78_MIN_HEALTH + upgrades* (_T.WX78_MAX_HEALTH - _T.WX78_MIN_HEALTH)/max_upgrades)
	inst.components.sanity.max = math.ceil(_T.WX78_MIN_SANITY + upgrades* (_T.WX78_MAX_SANITY - _T.WX78_MIN_SANITY)/max_upgrades)

	inst.components.hunger:SetPercent(hunger_percent)
	inst.components.health:SetPercent(health_percent)
	inst.components.sanity:SetPercent(sanity_percent)
end

-- The original oneat function already increments the level, and allows it to become higher
-- than the max level (for some reason). It also plays all the pulses and sounds, regardless
-- of whether you have already reached the maximum level.
-- So, all we have to do, is call the original function, and then call ours.
local origoneat = inst.components.eater.oneatfn
local function myoneat(inst, food)
	origoneat(inst, food)
	if food and food.components.edible and food.components.edible.foodtype == "GEARS" then
		myapplyupgrades(inst)
	end
end
inst.components.eater:SetOnEatFn(myoneat)

-- The game code also calls the applyupgrades function in the preload function,
-- so we have to do the same there as we did for the oneat function.
local origonpreload = inst.OnPreLoad

local function myonpreload(inst, data)
	origonpreload(inst, data)
	if data then
		if data.level then
			inst.level = data.level
			myapplyupgrades(inst)
			--re-set these from the save data, because of load-order clipping issues
			if data.health and data.health.health then inst.components.health.currenthealth = data.health.health end
			if data.hunger and data.hunger.hunger then inst.components.hunger.current = data.hunger.hunger end
			if data.sanity and data.sanity.current then inst.components.sanity.current = data.sanity.current end
			inst.components.health:DoDelta(0)
			inst.components.hunger:DoDelta(0)
			inst.components.sanity:DoDelta(0)
		end
	end
end
inst.OnPreLoad = myonpreload

 

Thank you for the comprehensive reply!

I might have messed things up a bit though (prior to reading your reply), I am not sure. The big problem is that I don't have any idea what I am doing. I don't really know what I don't know, or what I need to know. You mention using the API, what is that and is it difficult to use?

I have changed a few things in the gamefiles, but I don't know to what effect. Maybe I need to re-install the game altogether? But I still haven't figured out how to make anything I do work in any other modes than the regular Don't Starve, nothing I have done has any effect in RoG, SW or Hamlet. I managed to change the character speed in the locomotor-file, and it works in regular don't starve but not in any of the DLCs.

When I tried to look it up, I found:

But I didn't even have the "modinfo" folder at first. Then later when I followed some other guides on here and downloaded the "basic character template" and the "mod tools" or something through steam, I got the folder. But THEN, there was no line that even said "porkland_compatible" in the folder, and even if I added it myself it didn't work. Also, Even when I put all the other game-modes compatible status to "true", nothing happened there either.

Now I get a little black-box feeding me a few lines for about 5 seconds everytime I open Don't Starve.

So I got a bit disillusioned by the whole modding thing. It seems that whatever I try to replicate, something doesn't work quite as it should, things aren't as they should and so on.

Should I just re-install and start from scratch then? But I still feel like there's a bit of knowledge that I don't know which is probably important... I just don't know what it is.

 

Thank you for the coding, but before I can get to implement the lines I probably need to do something else first (because right now I can implement whatever and it won't have any effect).

 

 

Link to comment
Share on other sites

It's because you have been going at it very wrongly from the beginning. It sounds like you edited the game files directly in the game folder, which is the biggest no-no I can think of :) If you have done so, then you need to go to Steam, right-click the game, go to "Properties", click "Local Files" and then "Verify integrity of game files" to get the original files back.

Before you can start modding, you need to do some studying. You need to know how a mod is structured, which files go into them, learn how to code Lua and learn how to debug your code. A great starting point would be the newcomer post I wrote a long time ago. It has much of this information, a link to a good starter tutorial for Lua, some links to information about what goes into the modinfo file, and some extremely simple sample mods you can look at. Some of the stuff you want to do is intermediate level stuff, so you need to know what you're doing to succeed. And you can. We can help you. But our help is of no use if you haven't learned the basics, because you won't understand our guidance.

Return when you're ready and perhaps have played around with the sample mods, and I shall continue to help you :)

Of course, ask questions here, if there's some information you can't find.

P.S. The reason why your edits of the game files only worked in DS and not the expansions, is because you only edited the WX78 files for DS. The expansions have many of the same files which then override the files from the original DS when you run them. Especially the character prefab files have many differences between the three expansions. The overriding files from each expansion are placed in the DLC0001 (RoG), DLC0002 (Shipwrecked) and DLC0003 (Hamlet) folders. Inside those, you will find a similar structure to the structure of the "scripts" folder, which are the files for the base game (DS), which are the ones you seem to have found.

Link to comment
Share on other sites

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.

×
  • Create New...