1. Check out the Store if you're looking to Buy HL2RP or other schemas for your server. You can click Buy Schemas on the very top navigation bar to visit the store.
  2. Use the Plugin Center to easily subscribe to and auto-install Clockwork plugins to your server, or submit and share plugins you have developed.
  3. Having trouble setting up or developing with Clockwork? Check out the Wiki or post in the Support Forum for advice from fellow users.
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!

HL2RP I need help putting bodygroups on my clothing item.

Discussion in 'Development' started by Incognit0, Aug 5, 2018.

  1. Incognit0

    Incognit0 Clockwork Customer

    I downloaded extended citizens recently. They have a wide variety of bodygroups so I wish to make a clothing item that just changes the bodygroup and not the model. I attempted to make a beanie clothing item and it works. I can put on the beanie but the problem is when I unequip the beanie it stays on the model, the same goes for dropping it aswell.

    This is how far I have gotten with it.

    Code:
    local ITEM = Clockwork.item:New("clothes_base");
    ITEM.name = "Green Beanie";
    ITEM.uniqueID = "green_beanie";
    ITEM.cost = 15;
    ITEM.weight = 0.5;
    ITEM.business = true;
    ITEM.category = "Accessories";
    ITEM.access = "z";
    ITEM.description = "A simple green beanie.";
    
    function ITEM:GetReplacement(player)
        player:SetBodygroup(4, 2);
    
        end;
       
    ITEM:Register();
    If there are any solutions I'm all down to try em out.

    Thanks for reading...
     
  2. Svensis

    Svensis Legend | Zigbomb Clockwork Customer

    on unequip remove bodygroup
    with setbodygroup like you set it.

    look how hl2ts2 items do it if you can't figure out the functions yourself.
     
    • Like Like x 1
  3. Incognit0

    Incognit0 Clockwork Customer

    So like this..
    Code:
    local ITEM = Clockwork.item:New("clothes_base");
    ITEM.name = "Green Beanie";
    ITEM.uniqueID = "green_beanie";
    ITEM.cost = 15;
    ITEM.weight = 0.5;
    ITEM.business = true;
    ITEM.category = "Accessories";
    ITEM.access = "z";
    ITEM.description = "A simple green beanie.";
    
    function ITEM:GetReplacement(player)
        player:SetBodygroup(4, 2);
    
        end;
      
    function ITEM:OnPlayerUnequipped (player)
        player:SetBodygroup(0, 0);
    
        end;
      
    ITEM:Register();
    I tried this, I'm not sure I'm correct. When I tried on the item I can equip it but I could not unequipped it. Also when the item is picked up (not equipped) it applied the bodygroup. I'll look into HL2TS2 items but if there any other solutions I'm open...
     
  4. Viz

    Viz Legend Clockwork Customer Active Member

    You probably don't want to use the clothes base for this, as it works completely differently to how bodygroup items would function.
    Only one item is meant to be equipped when using the clothes base, which isn't likely how you would want to program bodygroup clothes, as you have multiple slots available for different bodygroups.

    Instead, you may want to create a bodygroup item base (or you could just put the functions into each item separately) designed more specifically for bodygroups.

    As for the code, the function:
    Code:
    ITEM:GetReplacement()
    end;
    is used in the clothes base for determining what model the player will be changed to when they equip the item; you will want to use the function:
    Code:
    ITEM:OnUse()
    end;
    This function is called when the player uses the item. Depending on how advanced you want to go, you can either put the majority of the bodygroup changing code in here, or look at how the clothes base works and try coding a base similar to that.

    If you want to do the former, you'll need to check whether the player has the clothing item equipped already in OnUse, and if so, set that bodygroup slot back to 0 so that the player is able to unequip bodygroup items.

    Another thing you'll want to look into is making sure that bodygroups don't persist when changing characters. To do this, you can make it so when a player changes character, set all their bodygroup slots back to 0.
    I would use the following hook for that:
    Code:
    -- Called when a player's character has loaded.
    function Clockwork:PlayerCharacterLoaded(player)
    end;
    
     
    • Like Like x 1
  5. Incognit0

    Incognit0 Clockwork Customer

    I've finally completed making a working bodygroup clothing item. I scrolled on the internet and found Gr4SS's equipable item base. I used its essential code to create a working bodygroup item that can be used. Here is the code..

    Code:
    local ITEM = Clockwork.item:New("clothes_base");
    ITEM.name = "Green Beanie";
    ITEM.uniqueID = "green_beanie";
    ITEM.cost = 15;
    ITEM.weight = 0.5;
    ITEM.business = true;
    ITEM.category = "Accessories";
    ITEM.access = "z";
    ITEM.description = "A simple green beanie.";
    
    ITEM:AddData("equipped", false, true);
    
    -- Called when the player equips the item.
    -- Override this function if you need to add your own behaviour for when a player equips/unequips this item
    function ITEM:OnWearEquipableItem(player, bIsWearing) end;
    
    -- Called when the player tries to equip the item.
    -- Override this functions if you need to add your own behaviour for if a player can equip this item
    -- Returning false will keep a player from equipping it, returning true or nil will allow him to equip it
    function ITEM:CanPlayerWear(player, itemEntity) end;
    
    -- Called when a player equips the item.
    function ITEM:OnWearItem(player, bIsWearing)
        self:SetData("equipped", bIsWearing);
        self:OnWearEquipableItem(player, bIsWearing);
    end;
    
    function ITEM:HasPlayerEquipped(player, bIsValidWeapon)
        return self:GetData("equipped", false);
    end;
    
    -- Called when a player uses the item.
    function ITEM:OnUse(player, itemEntity)
        player:SetBodygroup(4, 2);
        if (player:Alive() and !player:IsRagdolled()) then
            if (self:GetData("equipped") != true) then
                if (self:CanPlayerWear(player, itemEntity) != false) then
                    self:SetData("equipped", true);
                    self:OnWearItem(player, true);
                    player:RebuildInventory();
                    return true;
                end;
            else
                Clockwork.player:Notify(player, "You are already wearing this item!");
            end;
        else
            Clockwork.player:Notify(player, "You cannot do this action at the moment!");
        end;
       
        return false;
    end;
    
    function ITEM:OnPlayerUnequipped(player, extraData)
        player:SetBodygroup(4, 0);
        self:OnWearItem(player, false);
        player:RebuildInventory();
    end;
    
    function ITEM:OnStorageGive(player, storageTable)
        if (self:GetData("equipped") == true) then
            self:OnWearItem(player, false);
        end;
    end;
    
    function ITEM:OnDrop(player, position)
        player:SetBodygroup(4, 0);
        if (self:GetData("equipped") == true) then
            self:OnWearItem(player, false);
        end;
    end;
    
    -- Called when a player's character has loaded.
    function Clockwork:PlayerCharacterLoaded(player)
        player:SetBodygroup(4, 0);
    end;
    
    ITEM:Register();
    It works and I'm satisfied. Although I have another question. How do you change the thumbnail for the item?
    The item shows by default as a barrel, does anyone know how to change this?
     
  6. Viz

    Viz Legend Clockwork Customer Active Member

    This code will only affect the icon of the item:
    Code:
    ITEM.iconModel = "models/example.mdl";
    ITEM.iconSkin = 1;
    
    This code will affect both the icon and the real model (as long as iconModel or iconSkin hasn't been defined, respectively)
    Code:
    ITEM.model = "models/example.mdl";
    ITEM.skin = 1;
    
     
    • Friendly Friendly x 1
  7. Incognit0

    Incognit0 Clockwork Customer

    Thanks Viz. You're a saint...

    I have the same problem still... I can change the Icons skin (the oil drum skin) but I still can't change its model. This is what I put in..

    Code:
    local ITEM = Clockwork.item:New("clothes_base");
    ITEM.name = "Black Beanie";
    ITEM.uniqueID = "black_beanie";
    ITEM.model = "models/props_junk/garbage_bag001a.mdl";
    ITEM.iconModel = "models/props_junk/garbage_bag001a.mdl";
    ITEM.iconSkin = 1;
    ITEM.cost = 10;
    ITEM.weight = 0.2;
    ITEM.business = true;
    ITEM.category = "Clothing";
    ITEM.access = "z";
    ITEM.description = "A simple black beanie.";
     
    Last edited: Aug 29, 2018
  8. Viz

    Viz Legend Clockwork Customer Active Member

    Assuming that you have the equipable item base plugin installed, you will want to change your item to use the equipable item base instead of the clothes base, as they work very differently.

    Also, if you plan on using the same model for the icon and the in-game model, you do not need to provide the iconModel value.
    Code:
    local ITEM = Clockwork.item:New("equipable_item_base");
    ITEM.name = "Black Beanie";
    ITEM.uniqueID = "black_beanie";
    ITEM.model = "models/props_junk/garbage_bag001a.mdl";
    ITEM.cost = 10;
    ITEM.weight = 0.2;
    ITEM.business = true;
    ITEM.category = "Clothing";
    ITEM.access = "z";
    ITEM.description = "A simple black beanie.";
    

    When you use an item base, all of the functions defined within that base are included in your item. This means you do not need to add the functions yourself - unless you want to add custom functionality to the item.

    To clarify, you do not need to add the following to your item.
    Code:
    ITEM:AddData("equipped", false, true);
    
    -- Called when the player equips the item.
    -- Override this function if you need to add your own behaviour for when a player equips/unequips this item
    function ITEM:OnWearEquipableItem(player, bIsWearing) end;
    
    -- Called when the player tries to equip the item.
    -- Override this functions if you need to add your own behaviour for if a player can equip this item
    -- Returning false will keep a player from equipping it, returning true or nil will allow him to equip it
    function ITEM:CanPlayerWear(player, itemEntity) end;
    
    -- Called when a player equips the item.
    function ITEM:OnWearItem(player, bIsWearing)
        self:SetData("equipped", bIsWearing);
        self:OnWearEquipableItem(player, bIsWearing);
    end;
    
    function ITEM:HasPlayerEquipped(player, bIsValidWeapon)
        return self:GetData("equipped", false);
    end;
    
     
    • Like Like x 1
  9. Incognit0

    Incognit0 Clockwork Customer

    It all works, thanks for helping me out Viz. You are really the 'Legend' your title proclaims you to be.
     
    • Funny Funny x 1
    • Friendly Friendly x 1

Previous Readers (Total: 0)