Jump to content

Don't Starve Shipwrecked - Questions about waves, wetness, and death


Recommended Posts

I'm working on some mods for Don't Starve Shipwrecked and I was hoping someone could answer some questions for me.


1. I want to modify how waves behave, but I can't find which file handles it. Specifically, I want to change how Walani's surfboard and the Wave hit ability from tropical bouillabaisse interact with waves.

2. Where is the ondeath event handled in the game's code? Neither the life giving amulet or the life jacket give any sort of insight on this despite being items that can save you from death. I want to create a 1-UP mushroom item that saves the player from death but functions differently depending on how they died (monsters, fire, drowning, etc).

3. I want to give a character a base amount of wetness resistance. Is there and easy way to do this or would I have to rewrite functions in the moisture component?

4. Is there a way to remove the sanity drain from carrying wet items or having wet items equipped?

4. And while we are on the topic of water and wetness, is there a way to remove the slow down caused by walking through puddles?

Link to comment
Share on other sites

I found a few of the answers while doing my own research. I'll share what I've found.

 

Quote

1. I want to modify how waves behave, but I can't find which file handles it. Specifically, I want to change how Walani's surfboard and the Wave hit ability from tropical bouillabaisse interact with waves.

Turns out these are handled in two different different files.

"Wave Hit" is handled in the file "prefabs/wave_ripple.lua" under the "oncollidewave" function. If the player has the locomotion tag "SURF", then the script will ignore the angle of which the player hit a wave and always gives them a speed boost. The locomotion tag "SURF" is given to the character in "components/edible.lua" under the "OnEaten" function if the item consumed has a "surferdelta" value that isn't 0. In prefabs/preparedfoods.lua", which is used to construct crock pot foods, "surferdelta" is set to non zero if the food in question has a "boost_surf" property. And if you check "scripts/preparedfoods.lua" you will find that tropical bouillabasisse does indeed have a property called "boost_surf" that is set to true.

So what does this all mean? Well, in order to give an innate Wave Hit to a character, you need them to have that SURF tag. However, due to the way the game handles tags, it can be overridden. This means that if the Wave Hit character eats tropical bouillabasisse, they will lose the permanent version of Wave Hit by having it be overridden by a temporary version. The best way to avoid this is to change the "oncollidewave" function to also check for a second tag like "SURF2" when checking for Wave Hit.

Walani's surfboard is handled in a few places, the boost effect is handled in "oncollidewave" but the sanity boost is found in found in "stategraphs/SGwilsonboating.lua". Look in the events variable for the EventHandler "boostbywave" and you will find where it occurs. You can also search for "Walani" and you will find the line. "prefabs/boats.lua" sets the appropriate property for Walani's surfboard to allow for the sanity boost.

 

Quote

2. Where is the ondeath event handled in the game's code? Neither the life giving amulet or the life jacket give any sort of insight on this despite being items that can save you from death. I want to create a 1-UP mushroom item that saves the player from death but functions differently depending on how they died (monsters, fire, drowning, etc).

ondeath is found in "scripts/gamelogic.lua" under "OnPlayerDeath". But for resurrecting, check "components/resurrectable.lua" for how the Lifejacket and Life Giving Amulet work.

So there is a big problem with the 1-UP mushroom idea. Long story short, the script is only setup to let you use equipped items to revive.

Short story long, you drop all items on death. This happens before any Listen Event Handler for "death" will fire. By the time you try to search the character's inventory for the item, it will already be on the ground. Also, the DropEverything function in "components/inventory.lua" will only keep items with "inventoryitem.keepondeath" IF THEY ARE IN AN EQUIPMENT SLOT. Meaning that even if you set the item as keepondeath to true, it will still drop to the ground if it isn't equipped. Further, even if you do force the game to keep the item in your inventory, you will need extra code to make sure the item isn't missed if it was in a backpack, which will still be dropped on the ground. Fun huh? It turns out that this requires a lot of code rewriting and is more trouble than it's worth.

 

Quote

3. I want to give a character a base amount of wetness resistance. Is there and easy way to do this or would I have to rewrite functions in the moisture component?

Moisture and wetness are handled in a lot of different places. It's a really complicated system with a lot of parts. But as luck would have it, it turns out there IS a way to do this with minimal code. "GetWaterproofness" is a method in the "components/inventory.lua" file that is used to determine the total wetness resistance of all equipped items. If we edit this function we can added innate wetness resistance. To do this with a few changes as possible and to not disturb the rest of inventory system, we need to use the "AddComponentPostInit" function inside our modmain.lua script to change it. Add the following to modmain.lua:

Quote

-- This allows innate wetness resistance.
AddComponentPostInit("inventory", function(self)
    local oldfunction = self.GetWaterproofness         -- Keep the old function in case we need it later.

    function self:GetWaterproofness(slot)             -- overriding that function
        local waterproofness = self.innate_waterproofness or 0   -- This is the different line that allows innate wetness resistance. Will be 0 if it isn't set.
        if slot then
            local item = self:GetItemInSlot(slot)
            if item and item.components.waterproofer then
                waterproofness = waterproofness + item.components.waterproofer:GetEffectiveness()
            end
        else
            for k,v in pairs(self.equipslots) do
                if v and v.components.waterproofer then
                    waterproofness = waterproofness + v.components.waterproofer:GetEffectiveness()  
                end
            end
        end
        
        return waterproofness    
    end
end)

Next, add this line in your character's prefab file. This will give the character and innate 25% wetness resistance:

Quote

inst.components.inventory.innate_waterproofness = 0.25

 

Here is how this works. We override the "GetWaterproofness" function in "components/inventory.lua" with our own function. The function we are using is the exact same as the original GetWaterproofness except for this line:

Quote

local waterproofness = self.innate_waterproofness or 0

Normally, this variable, waterproofness, is always 0. However, we changed it to use the inventory's innate_waterproofness property. In the event that self.innate_waterproofness (self in this case is referring to the inventory component) is nil (meaning it was never set) the script will just use 0 instead. This simple change allows innate wetness resistance AND prevents crashes if the innate wetness resistance property isn't set.

 

As for the inventory sanity drain and puddles, I haven't had any luck. I hope that is information will be useful to anyone who comes across it when looking for mechanics on waves, wetness, or resurrection. Happy modding and good luck to you!

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