Jump to content

[Post Actually Written] [Custom Character Help] Increasing durability consumption


Recommended Posts

(Edit: Now a finished post. I suppose my character's trait actually carries over to me, as well.)

I've been working on a character mod for Shipwrecked, and I've been having some trouble getting one of his traits to function. I have little prior understanding of Lua, though I do have some programming experience in other languages. So far, I've been able to get by adding my character's abilities through scraping together bits of code from the game and these forums, but so far I still have very little lower-level understanding of the game's infrastructure. Most of my understanding comes from dissecting code in this way, so I apologize if anything I mention in this thread seems ignorant.

Let's establish the design of the trait in question. Due to the character's recklessness, any items that have durability deplete faster than usual. Being able to tweak each individual item's durability consumption would be ideal, but a global multiplier of 1.5x for tools and 2x for weapons would also suffice. Besides creating balance alongside the character's positive traits, my main thought in design is to drive a player to consider use of the character's unique tool as a weapon, even late into the game, thanks to its infinite durability and decent damage value.

I've tried to code in this durability multiplier in a variety of ways, all of which so far have centered around the more complex problem; tools. My earliest attempts made an effort to create a system that would automatically generate new consumption values for a given tool each time it was equipped by my character. I ran into issues here because of the number of different "ACTIONS" that are associated with different tools. Consumption is linked to a specific task, and those tasks can have differing consumption values, so it seems to becomes a clunky, convoluted mess if you try to detect the actions available to a given item. There are a number of other approaches I've taken, but I feel it isn't necessary to describe them at this time.

Although I'm making the mod for Shipwrecked, I do intend to make a Don't Starve Together version in the future, and so I'd like to be able to write my code in such a way that I won't need to completely re-do it in the future. I'll discuss my basic structure of logic in a reply, because somehow, I've had yet another mishap in editing this post, and it could take some time to describe.

I hope all I've said here isn't too confusing. I've been toiling away on this for some time now on my own, so there's quite a bit for me to try to include here (and I've already excluded a good deal). If any additional information is needed, feel free to ask.

Link to comment
Share on other sites

I think I understand the basic structure of logic could be something like the following:

  1. In modmain, listen for the player to equip an item, triggering function_1.
    1. I believe [reference to player]:ListenForEvent("equipped", function_1) would accomplish this. But referencing the player is the difficult part, and I tend to struggle with this in general. What is the proper approach? Also, does the "equipped" event include armors as well?
  2. First, function_1 checks if player equipping the item is my character to ensure that the trait only activates for him.
    1. This is perhaps the biggest issue for me. I am not sure how to reference the player equipping the item, or how to reference the equipped item itself. It is important to write this in such a way that it works in DST as well - I suppose this could be done by checking for a character tag, but I'm not sure how I would write this in proper syntax.
  3. Next, function_1 checks if the equipped item is a tool and if it has the component finiteuses.
    1. This should easy enough to do, if I can determine how to reference the equipped item.
  4. Then, function_1 defines var_1 as [reference to equipped item].components.finiteuses.consumption. It then redefines [reference to equipped item].components.finiteuses.consumption to [reference to equipped item].components.finiteuses.consumption * 1.5.
    1. In reality, I have no idea if this would function the way I think it would or not because I do not know what kind of data type components.finiteuses.consumption actually is. If I'm interpreting finiteuses.lua correctly, it would seem that it's actually a table, but I can't confirm this because I still do not know how I could make a reference to the player's currently held item, so I also cannot print it in the console.
  5. At the end of function_1, listen for the player to unequip the currently held item, triggering function_2, which inputs var_1.
    1. I'm assuming there is an ListenForEvent for unequipping items, here. I will do my best to see if there is such a thing somewhere in the code, but if there isn't, how could I return it to its old value? Maybe listen for percentage change?
  6. function_2 changes [reference to equipped item].components.finiteuses.consumption to the value of var_1, theoretically returning it to normal.

I'm sure there are a few steps I've left out, but in theory, would this function correctly? If not, I hope it can at least help some of you to identify where I'm fundamentally misunderstanding. If anyone has any superior suggestions for how to approach this problem, I'm very open to hearing them.

Thank you very much for your time.

Link to comment
Share on other sites


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