Sign in to follow this  
LDaldrup

[Help] Set custom item durability on use

Recommended Posts

LDaldrup    0

Hello fellow DST modders,

 

I am in the progress of making a character mod and need some help with the scripting.

 

My problem:

One of the character perks is that items have a small chance to instantly break on use (regardless of remaining item durability).

 
I just need a pointer on how to get the and item that the player is currently using and on how to change the durability of the item on use.

 

Thanks a bunch in advance!

 

 

Edited by LDaldrup

Share this post


Link to post
Share on other sites
DarkXero    2889

-- Tools and weapons have durability, given by finiteuses

-- Using a tool or attacking with weapon consumes it

-- We use AddComponentPostInit so all tools/weapons using the component have the modification from the base class

AddComponentPostInit("finiteuses", function(self)

-- When consuming something this event gets pushed to the tool/weapon

self.inst:ListenForEvent("percentusedchange", function(inst, data)

local owner = nil

-- We look for the person that is holding the weapon when its durability changes

if inst.components.inventoryitem then

owner = inst.components.inventoryitem.owner

end

-- If the person exists and its wilson...

if owner and owner.prefab == "wilson" then

-- we roll, if we get a 0-0.9 out of 0-1, we win, if not, we lose our weapon

if math.random() > 0.9 and data.percent > 0 then

-- we lost, we set the uses remaining in our weapon to 0, so it breaks

inst.components.finiteuses:SetUses(0)

end

end

end)

end)

Share this post


Link to post
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
Sign in to follow this