Jump to content

Help with finding specific items - Sewing Kit Script


Recommended Posts

Hey I figured this would be the best place to ask this - Where and how can I find a specific item if I'm looking for code?

 

I have this idea of combining weapons/items/clothes for repairing(Similar to other sandbox type games)instead of having such clutter at times. I know the sewing kit does something like this as it repairs some clothing, I'd like to find that code and some how get that to apply from any weapon/item/cloth to another of the same name. 

 

Any help would be appreciated and if any experienced modders want to let me know that this isn't so feasible that's fine as well.

Link to comment
Share on other sites

Don't Starve Together Beta\data\scripts\components\sewing.lua

Don't Starve Together Beta\data\scripts\prefabs\sewingkit.lua

 

These two should get you started.

 

If you find something and you're wondering where it gets declared, notepad++'s find in files feature works wonders, just set it to Don't Starve Together Beta\data\scripts\ and let it work its magic.

Link to comment
Share on other sites

I've searched pretty hard looking for the connection between the sewing kit.lua and sewing.lua and the items it's used on but I can't figure it out, I don't understand how it's determined what can be sewed and what can't be.

local Sewing = Class(function(self, inst)    self.inst = inst    self.repair_value = 1end)function Sewing:DoSewing(target, doer)    if target:HasTag("needssewing") then				target.components.fueled:DoDelta(self.repair_value)		if self.inst.components.finiteuses then			self.inst.components.finiteuses:Use(1)		end		if self.onsewn then			self.onsewn(self.inst, target, doer)		end		return true	endendreturn Sewing
local function walrus()        local inst = simple()        if not TheWorld.ismastersim then            return inst        end        inst:AddComponent("dapperness")        inst.components.dapperness.dapperness = TUNING.DAPPERNESS_LARGE        inst:AddComponent("insulator")        inst.components.insulator.insulation = TUNING.INSULATION_MED        inst:AddComponent("fueled")        inst.components.fueled.fueltype = FUELTYPE.USAGE        inst.components.fueled:InitializeFuelLevel(TUNING.WALRUSHAT_PERISHTIME)        inst.components.fueled:SetDepletedFn(inst.Remove)                return inst    end

Looking at all of the hats that could be sewn in game I couldn't find out where DoSewing, or onsewn, or needsewing are used :(.. any help? what part of the code is telling the item it can be sewn? or repaired? 

Link to comment
Share on other sites

@outseeker, this is probably the most useful function of Notepad++!  :-)

 

@Notant, using the Find in Files feature they were talking about, I was able to find that:

  • The DoSewing function is actually used to define an action in scripts/actions.lua:
ACTIONS.SEW.fn = function(act)	if act.target and act.target.components.fueled and act.invobject and act.invobject.components.sewing then		return act.invobject.components.sewing:DoSewing(act.target, act.doer)	endend 

which is then used in the stategraph of wilson on both SGwilson.lua and SGwilson_client.lua:

ActionHandler(ACTIONS.SEW, "dolongaction"), 
  • The needsewing tag is set in the fueled component in components/fueled.lua.
  • onsewn is a function of the sewingkit prefab that is called when DoSewing is called.

Hope that helped!

Link to comment
Share on other sites

@Notant: That, and having their fuel type set to FUELTYPE.USAGE, from what I gathered:

inst:AddComponent("fueled")inst.components.fueled.fueltype = FUELTYPE.USAGE

This will automatically add the needsewing tag to the item when its durability is lowered, allowing it to be repaired using a sewing kit.

Edited by Jjmarco
Link to comment
Share on other sites

@Jjmarco

 

That is what I thought, but I'm having issues actually making it work. I can't really find how to properly test a mod, should I just change the main files and test that way? I've looked all over for proper mod file set ups and how I should go about that but man information seems not that helpful. 

 

I'll try testing changing the main files since it's not a lot of work. Thank you for all the help!

 

 

Edit - Didn't work for me, only added the timer(As if the item could run out but the clock was 0:00)under the pickaxes but didn't allow for sewing when the durability was under 100%, or even at 100%. 

 

Maybe a perish time is needed? Btw I'm using this on a pickaxe just to try and figure it out, really want to be able to repair items and I do know that there is a repair and repairable function, not that I could figure out those any better though.

Edited by Notant
Link to comment
Share on other sites

@Notant, Ah yes, you have to add a perish time, I forgot ;)

 

To test a mod, you have to create a new folder in the mods directory of the game's files.

Name it whatever you like, then add two files, one named "modmain.lua" and the other "modinfo.lua".

 

In modinfo.lua, put this:

name = "<Name of the mod here>"version = "1.0"author = "Notant"description = "This is a test mod."forumthread = ""api_version = 10dst_compatible = trueclient_only_mod = false -- change this if your mod is client-side onlyall_clients_require_mod = false -- change this if everybody on the server needs this mod in order to enter

In modmain.lua, put your mod's actual code. For instance, to add the fueled component to an item and make it sewable:

AddPrefabPostInit("<item prefab here>", function(inst)    -- Only the host should run this    if GLOBAL.TheNet:GetIsServer() then        inst:AddComponent("fueled")        inst.components.fueled.fueltype = GLOBAL.FUELTYPE.USAGE    endend)

Note that this only applies to items that have the fueld component. The pickaxe uses the finiteuses component to handle durability. This is different from the fueled component, as it handles losses of durability overtime (Hats, amulets, etc).

 

About your mod idea, you would need to define a function that takes two items, combine their durabilities using whatever logic you want, delete them, then create a new item of the same type on which you set that new durability. This function would be activated when you click on an item with another one of the same type.

Edited by Jjmarco
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...