Trying to make a backpack that both appears on your back and operates as extra storage like a boxed backpack, however I'm having an issue. The item does not appear in the inventory of the person given it.
backpack_10l.lua
------------------------------------------------------------------
Code:
--[[
? 2013 CloudSixteen.com do not share, re-distribute or modify
without permission of its author ([email protected]).
--]]
local ITEM = Clockwork.item:New();
ITEM.name = "10L Backpack";
ITEM.model = "models/fallout 3/backpack_1.mdl";
ITEM.weight = 1;
ITEM.category = "Storage";
ITEM.isRareItem = true;
ITEM.description = "A small backpack that will only hold ten litres.";
ITEM.addInvSpace = 5;
ITEM.useText = "Wear";
ITEM.uniqueID = "backpack_10l"
ITEM.isAttachment = true;
ITEM.attachmentBone = "ValveBiped.Bip01_Spine";
ITEM.attachmentOffsetAngles = Angle(0, 0, 0);
ITEM.attachmentOffsetVector = Vector(-2, 0, 0);
-- Phase4
-- Called when a player uses the item.
function ITEM:OnUse(player, itemEntity)
if (player:HasItemByID("backpack_10l") and table.Count(player:GetItemsByID("backpack_10l")) >= 1) then
Clockwork.player:Notify(player, "You can only wear one backpack at a time!");
return false;
end;
player:GiveItem(Clockwork.item:CreateInstance("backpack_10l"));
end;
-- ^^ Phase4
-- Called when the item's drop entity should be created.
function ITEM:OnCreateDropEntity(player, position)
return Clockwork.entity:CreateItem(player, Clockwork.item:CreateInstance("backpack_10"), position);
end;
-- Called when a player attempts to take the item from storage.
function ITEM:CanTakeStorage(player, storageTable)
local target = Clockwork.entity:GetPlayer(storageTable.entity);
if (target) then
local inventoryWeight = Clockwork.inventory:CalculateWeight(
target:GetInventory()
);
if (inventoryWeight > (target:GetMaxWeight() - self("addInvSpace"))) then
return false;
end;
end;
if (player:HasItemByID(self.uniqueID) and table.Count(player:GetItemsByID(self.uniqueID)) >= 1) then
return false;
end;
end;
-- Called when a player attempts to pick up the item.
function ITEM:CanPickup(player, quickUse, itemEntity)
return "boxed_backpack";
end;
-- Called when a player drops the item.
function ITEM:OnDrop(player, position)
if (player:GetInventoryWeight() > (player:GetMaxWeight() - self("addInvSpace"))) then
Clockwork.player:Notify(player, "You cannot drop this while you are carrying items in it!");
return false;
end;
end;
ITEM:Register();
Error Log
------------------------------------------------------------------
Code:
ServerLog: Bloodprime has gained a 10L Backpack 1374533644.
ServerLog: Bloodprime has used '/CharGiveItem blood 10l'.
[.:[dG] Bloodprime|2|STEAM_0:1:20076366] Lua Error:
[ERROR] gamemodes/clockwork/framework/libraries/sh_inventory.lua:125: attempt to index local 'itemTable' (a nil value)
1. AddInstance - gamemodes/clockwork/framework/libraries/sh_inventory.lua:125
2. unknown - gamemodes/clockwork/framework/libraries/sh_inventory.lua:349
3. func - gamemodes/clockwork/framework/libraries/sh_datastream.lua:147
4. unknown - lua/includes/modules/net.lua:31
Thanks!