Thanks for the report. The issues you've identified lie with Clockwork, rather than with your implementation. As such, I've opened two issues on the repository, and added them to the to-do:
https://github.com/CloudSixteen/Clockwork/issues/464
https://github.com/CloudSixteen/Clockwork/issues/465
In the mean time, until this issue is resolved properly in development, you can perform a non-ideal partial patch:
- The ITEM:OnUse(player, itemEntity) function call provides the spawned entity for a given item as the second parameter, so you can simply check if itemEntity is a valid entity. If it is, you continue to execute self:OpenFor(player, itemEntity). Otherwise, you don't execute that line. This would mean that the "Open" button would still appear in the inventory, but it wouldn't do anything.
- Regarding your second issue, I was going to recommend the use of ITEM.CanPickup, but looking at it it seems that this is more accurately described as "ITEM.CanPickupAndUse", and as such these behaviours cannot seemingly be controlled individually at the moment. I have opened an issue for this as well: https://github.com/CloudSixteen/Clockwork/issues/466. As such, my recommendation is to advise users of the issue until it is fixed in development.
On a separate note, your item code can be simplified. You needn't copy the container base code into your own, but rather you can call upon that code via Clockwork.item.New, as follows:
Code:
local ITEM = Clockwork.item:New("container_base");
ITEM.name = "Tall Drawers";
ITEM.uniqueID = "talldrawers3";
ITEM.model = "models/props_c17/FurnitureDrawer003a.mdl";
ITEM.plural = "Tall Drawers";
ITEM.weight = 4;
ITEM.category = "Furniture";
ITEM.batch = 1;
ITEM.useText = "Open";
ITEM.description = "Tall drawers. I wouldn't put anything heavy in here as it looks like it might collapse out of misery alone.";
ITEM.storageSpace = 6;
ITEM:Register();
By passing "container_base" to Clockwork.item.New, it will base your item off of the container base.
EDIT: Working this in with the OnUse patch, the following should work:
Code:
local ITEM = Clockwork.item:New("container_base");
ITEM.name = "Tall Drawers";
ITEM.uniqueID = "talldrawers3";
ITEM.model = "models/props_c17/FurnitureDrawer003a.mdl";
ITEM.plural = "Tall Drawers";
ITEM.weight = 4;
ITEM.category = "Furniture";
ITEM.batch = 1;
ITEM.useText = "Open";
ITEM.description = "Tall drawers. I wouldn't put anything heavy in here as it looks like it might collapse out of misery alone.";
ITEM.storageSpace = 6;
function ITEM:OnUse(player, itemEntity)
if (IsValid(itemEntity)) then
self:OpenFor(player, itemEntity);
end;
return false;
end;
ITEM:Register();
Click to expand...