Jump to content

Insane Power - My first look into Don't Starve modding


Recommended Posts

Hi everyone, I've decided to share my first forray into making a mod for Don't Starve. This mod enables you to refuel the 6 magic staves in the game with nightmare fuel. (I'll be adding the 6 amulets later)

 

I did run into some issues though, and could use some help from those of you more familliar with the lua scripts in Don't Starve than I.

 

Let me run you through my thought prosses while making this mod.

  • First and formost, I realised that to make these items refuelable, I needed to add the "fueled" component to them. Since nightmare fuel is already a fuel item (for the night light), specifying the fuel type of "NIGHTMARE" was easy.
  • The next problem came from the fact that these items already have durabilities in the form of a "finiteuses" component that both the "weapons" component and the "staff" prefab make heavy use of.
  • The solution turned out to be simple. By overriding the ontakefuelfn function, I set the percent of the "finightuses" component inside the function, leaving the "fueled" percent alone. I increased the "finightuses" percent by 5%, and added in a condition so you couldn't go over 100%.
  • Next up is where things get messy. I wanted to make it so the staves do not break when depleated, but instead loose their power. The solution I came up with was to remove the relevent component from the staves when they went below 5% power, and then re-add it when fuel was added. This method seems really messy to me, and if you have suggestions on how I could "turn off" the staves I would love to hear them. Unfortunatly, there isn't a "canUse" boolean in the "finiteuses" prefab. That would be really handy.
  • Everything works properly right now except for the telestaff. For some reason, it allows me to use it from outside of my hand slot, crashing the game. If I equip it like normal then it works just fine.

 

I would love it if you could download it and give it a try. Any suggestions for improvements are more than welcome.

 

As a side note, I set you to creative mode automatically, when you enter a world, to help with testing. This will be disabled in the final release.

insanepower.zip

Link to comment
Share on other sites

Hi everyone, I've decided to share my first forray into making a mod for Don't Starve. This mod enables you to refuel the 6 magic staves in the game with nightmare fuel. (I'll be adding the 6 amulets later)

 

I did run into some issues though, and could use some help from those of you more familliar with the lua scripts in Don't Starve than I.

 

Let me run you through my thought prosses while making this mod.

  • First and formost, I realised that to make these items refuelable, I needed to add the "fueled" component to them. Since nightmare fuel is already a fuel item (for the night light), specifying the fuel type of "NIGHTMARE" was easy.
  • The next problem came from the fact that these items already have durabilities in the form of a "finiteuses" component that both the "weapons" component and the "staff" prefab make heavy use of.
  • The solution turned out to be simple. By overriding the ontakefuelfn function, I set the percent of the "finightuses" component inside the function, leaving the "fueled" percent alone. I increased the "finightuses" percent by 5%, and added in a condition so you couldn't go over 100%.
  • Next up is where things get messy. I wanted to make it so the staves do not break when depleated, but instead loose their power. The solution I came up with was to remove the relevent component from the staves when they went below 5% power, and then re-add it when fuel was added. This method seems really messy to me, and if you have suggestions on how I could "turn off" the staves I would love to hear them. Unfortunatly, there isn't a "canUse" boolean in the "finiteuses" prefab. That would be really handy.
  • Everything works properly right now except for the telestaff. For some reason, it allows me to use it from outside of my hand slot, crashing the game. If I equip it like normal then it works just fine.

 

I would love it if you could download it and give it a try. Any suggestions for improvements are more than welcome.

 

As a side note, I set you to creative mode automatically, when you enter a world, to help with testing. This will be disabled in the final release.

 

Its a mess for sure.

You don't need to use fueled component to refuel the staffs. Using repairable and repairer components would  be much simplier, you could just add new action and call it whatever you like (refuel for example) and make a copy of 2 components mentioned earlier to use that action. For the 0% durability you just take a look at on:

inst.components.finiteuses:SetOnFinished( onfinished )

the standard onfinished function removes the item if it gets to 0%

local function onfinished(inst)    inst.SoundEmitter:PlaySound("dontstarve/common/gem_shatter")    inst:Remove()end

You need to replace that function with your new function that won't remove the item:

local function onfinished_mod(inst)    inst.SoundEmitter:PlaySound("dontstarve/common/gem_shatter")end

Then use that in your prefabpostinit:

function staffPrefabPostInit(inst)		if inst and inst.components.finiteuses then	inst.components.finiteuses:SetOnFinished( onfinished_mod )	end	endAddPrefabPostInit("telestaff", staffPrefabPostInit)

If you leave finiteuses compoent in place there won't be any problmes with item being usable at 0%.

 

 

 

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