Don't Starve

Don't Starve

38 ratings
[API] Floatable Items
   
Award
Favorite
Favorited
Unfavorite
File Size
Posted
224.913 KB
28 Oct, 2023 @ 7:02am
1 Change Note ( view )

Subscribe to download
[API] Floatable Items

Description
This API is for modders who want to make their items floatable without making a new ripple effect in their build.

For this API to work you'll need to have this mod enabled alongside your mods at all times. This API is useless in Reign of Giants and Vanilla Don't Starve, it only works for Shipwrecked and Hamlet.

How to Install
1. Download/Subscribe to the API,
2. Go to the mods folder located in "Local Disk (C:) > Program Files (x86) > Steam > steamapps > common > dont_starve > mods",
3. Go to your mod's folder and go to "scripts > prefabs > myprefab.lua" (myprefab being THE item you want to make floatable, !!!DO NOTE: THE ITEM IN QUESTION MUST HAVE THE "INVENTORYITEM" COMPONENT!!!)
4. Open your prefab and add the following to your prefab's function:
inst:AddComponent("modfloatable") inst:AddComponent("inventoryitem") inst.components.inventoryitem.nosink = true
5. Launch Don't Starve, go to Mods and enable both the API and your mod,
6. Test in your Shipwrecked/Hamlet worlds if your item floats and has its own ripple effect when on water, if it does then you successfully installed the API.

Additional Information
You can add the following code in your prefab's function to further modify the item when on water and land:
inst.components.modfloatable.landanim = "idle" -- Set the animation of the item to play when on land. inst.components.modfloatable.loopland = true -- Set to true or false if you want the landanim to loop. inst.components.modfloatable.wateranim = "idle_water" -- Set the animation of the item to play when on water. inst.components.modfloatable.loopwater = true -- Set to true or false if you want the wateranim to loop. inst.components.modfloatable:SetOnHitWaterFn(fn) -- Set a custom function to play when the item hits water. inst.components.modfloatable:SetOnHitLandFn(fn) -- Set a custom function to play when the item hits land. inst.components.modfloatable.size = "med" -- Set to either "small", "med" or "large" for how big you want the ripple effect on your item to be. inst.components.modfloatable.xscale = 1.0 -- Set a number value here to make the x-axis of the ripple effect wider or thinner. inst.components.modfloatable.yscale = 1.0 -- Set a number value here to make the y-axis of the ripple effect taller or shorter. inst.components.modfloatable.heavyitem = true -- Set to true to make the item not slide when it hits the water. inst.components.modfloatable.bobbing = true -- Set to true if you want the item to bob up and down when on water.
2 Comments
Hello_Han 3 Dec, 2024 @ 7:41pm 
十分感谢您的API,这对我很有帮助!
Rage of Sparta 23 Dec, 2023 @ 4:17am 
Ooooh, this is gonna be useful for my future mods! Thanks mate.