Continuing the discussion from Do you use a custom backpack and/or custom tool objects?:
It can be useful to prevent tools from being unequipped under circumstances, or doing stuff before unequipping tools. Tool.OnUnequip would be like game.OnClose – it would be invoked whenever a tool was requested to be unequipped, and the tool would wait to unequip until the OnUnequip callback was completed (this is what makes OnUnequip different from tool.Unequipped). Subsequent calls to OnUnequip should be ignored if the previous call has not returned yet. If OnUnequip returns false, the tool should not be unequipped. It might also be nice to have Tool.UnequipDisabled, but OnUnequip might cover that functionality by just setting it to function() return false end
– I’m not sure.
Use cases:
-Unequip animation before unequipping a tool (currently impossible with current tools AFAIK)
-Cancel out abilities (e.g. sword that splits in two – needs to return to one piece) on unequip
-Prevent fishing rod from being unequipped until you reel it in (have OnUnequip return false while line is cast)
-And a lot of other stuff that’s generally the same idea as those
Further clarification:
With OnClose, if I press ‘3’ to equip tool #3 and #1 was currently equipped:
- If #1’s OnClose callback is
function() return false end
, it is impossible to unequip #1 and #3 will never be equipped - If #1’s OnClose callback plays an unequip animation that lasts 5 seconds, #1’s unequip animation will play an animation for 5 seconds, return, and #3 will then be equipped
- If #1 does not have a OnClose callback, it is unequipped instantly (current behavior) and #3 is equipped immediately afterwards