Make tools more useful - Tool.OnUnequip (Tool equivelant of game.OnClose)

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
4 Likes

This would be amazing, though it might be awkward having a tool “queued up” to be equipped (the second clarification). That functionality would have to be present in the Backpack CoreGui, and not be a native feature of trying to equip a new tool.

There’s not a queue. There’s an equipped tool, and the tool you want to equip. If you try to equip #2, #1’s OnUnequip callback is running, and then you try to equip #s 3-0 while #1’s OnUnequip is running, it doesn’t go “OnUnequip 1, Equip 2, OnUnequip 2, Equip 3, etc” – it goes “OnUnequip 1, Equip 0 (latest tool requested to be equipped)”

Humanoid:EquipTool() and Humanoid:UnequipTools() are ROBLOX API members – not parts of the backpack corescript. The backpack corescript uses those API members to equip/unequip tools (actually it doesn’t use EquipTool due to a bug right now, but it is intended to use EquipTool). Also, Tool.OnUnequip would be a change to the API which couldn’t be implemented with a corescript.

If I recall correctly, someone made the core of the backpack GUI, and showed it to ROBLOX and they simply refined it.