Jump to content

Item durability coding. Need help!


Recommended Posts

I am making(trying the hardest I can) my own [DST] character mod and I wanted for him to rely on his starter item mainly... is there a way to increase this item durability? etc. pan flute have, I think 10 uses, can I increase this to 100?

Edited by Veketh
Link to comment
Share on other sites

what kind of item is it?
There are several kinds of durability: "Finiteuses" for weapons and tools. "fueled" for lantern and that stuff. "persihable" for hambat and food. "armor" for armors.

I guess it is a tool/weapon and therefore using finiteuses?
You set the max finiteuses after adding this component with: inst.components.finiteuses:SetMaxUses(val)
Is it a new item you made? Then put it into your master-postinit.
If it is a item that already exists, you can o this within an AddPrefabPostInit , but this will also change the item for every other player.
If you only want it to be changed for your player, it is a bit more complicated, so I will wait for your reply.

Edited by Serpens
  • Like 1
Link to comment
Share on other sites

@Serpens wow, thanks so much for such long and understandable answer. Well, I wanted for this character to use Pan Flute (I have no idea if it's a weapon or a tool) and in the best scenario, I wanted it to be unlimited use, only for that character. If you could help me with that I would be very grateful.

Link to comment
Share on other sites

AddPrefabPostInit("panflute",function(inst)
    if inst.components~=nil then
        local old_Use = inst.components.finiteuses.Use
        inst.components.finiteuses.Use = function(self,val,...)
            if self.inst~=nil and self.inst.components~=nil and self.inst.components.inventoryitem~=nil and self.inst.components.inventoryitem.owner~=nil and self.inst.components.inventoryitem.owner.prefab=="mycharacter" then
                val = 0 -- set usage to 0 if it is in inventory of our character
            end
            return old_Use(self,val,...) -- call the original function now
        end
    end
end)

try this in modmain.lua and replace "mycharacter" with you character prefab.
It changes the consumed value to 0, if in inventory of your character.

Edited by Serpens
  • Like 1
Link to comment
Share on other sites

downside is that if you play it while it is in a chest, the code wont work. I think if in backpack it still should work, but better try.

The problem is that finiteuses has no information about the user, so we need other way to find the user and check if it is your character. In this case I used the inventory.

Link to comment
Share on other sites

So if I got this right... you can use this item only when it's in your inventory(eventually in a backpack - didn't test yet) and this will work for other players too?

In the future, I hoped to do that this item can be used only by that character, but I think there will be a lot of problems in that.

Edited by Veketh
Link to comment
Share on other sites

3 minutes ago, Veketh said:

So if I got this right... you can use this item only when it's in your inventory(eventually in a backpack - didn't test yet) and this will work for other players too?

In the future, I hoped to do that this item can be used only by that character, but I think there will be a lot of problems in that.

no, the code does check for your character. But it only knows that it is you, if the flute is in your inventory. If the flute is in a chest and you play it with your character, it will lose durability.  For other characters the flute will work like normal.

Link to comment
Share on other sites

Ok, I just misunderstood then... thank you so much for your work. I hope I'll be able to help someone in the future like you. When I get a bit of experience in this of course. 

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