LDaldrup Posted May 14, 2015 Share Posted May 14, 2015 (edited) 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 May 14, 2015 by LDaldrup Link to comment Share on other sites More sharing options...
DarkXero Posted May 15, 2015 Share Posted May 15, 2015 -- 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) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now