1. This forum is ARCHIVED! Visit the new Cloud Sixteen forums, codename Eden, at https://eden.cloudsixteen.com. These forums will remain archived for a few months before being closed down, so try to encourage plugin developers to begin moving their content across to the new forums.
Dismiss Notice
Hi Guest, you need a Steam account to register and post on these forums. Login with Steam at the top of the forums to get started!
Dismiss Notice
Hi Guest, do you want to buy HL2RP or another Clockwork schema? Visit the Cloud Sixteen Store to get started!

Backpack Accessory

Discussion in 'Development' started by Bloodprime, Jul 24, 2013.

  1. Bloodprime

    Bloodprime WARPAC Lead

    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!
     
  2. Kezter

    Kezter Certified Old Fag

    Here this should fix it Click here Btw mind if I steal this idea and make it a plugin?
     
  3. Dub

    Dub Guest

    -SNIP-
    I DUN GOOFED
     
  4. Bloodprime

    Bloodprime WARPAC Lead

    These are for WARPAC, so I'd prefer if it wasn't widely used before launch.

    Thank you for the fix however. I'll try it once I'm home and let you know if it works.
     
  5. Kezter

    Kezter Certified Old Fag

    Okidokiloki
     

Previous Readers (Total: 0)