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 Getting Clothing to Match Playermodels

Discussion in 'Development' started by NoahtheBoah36™, Nov 4, 2018.

  1. NoahtheBoah36™

    NoahtheBoah36™ Clockwork Retard Clockwork Customer Active Member

    Hey, so I have a question that is probably dumb and really easy, but I just can't wrap my head around what it is I'm doing wrong, so here goes.

    As you may be aware, the resistance uniform from base hl2rp somehow manages to pick the rebel outfit that matches your playermodel's head (at least for vanilla models and most tnb packs, etc.) despite its' function only consisting of
    Code:
    -- Called when a replacement is needed for a player.
    function ITEM:GetReplacement(player)
        if (string.lower( player:GetModel() ) == "models/humans/group01/jasona.mdl") then
            return "models/humans/group03/male_02.mdl";
        end;
    end;
    
    So, as I'm creating a custom clothing item, I have the exact same function, and I set the ITEM.group equal to the group that is listed in the model path for the model I'm trying to set the clothing item to, but then when I test my custom clothing item it just turns me into an error.

    For reference, I set the ITEM.group to "group011"
    And this is the model path:
    Code:
     models/thespireroleplay/humans/group011/male_09.mdl 
    Also, sorry for always being an idiot who can't figure sh*t out but this one just has me stumped. Thanks in advance to anybody who can help!
     
  2. Viz

    Viz Legend Clockwork Customer Active Member

    Code:
    --[[
       © 2015 CloudSixteen.com do not share, re-distribute or modify
       without permission of its author ([email protected]).
    
       Clockwork was created by Conna Wiles (also known as kurozael.)
       http://cloudsixteen.com/license/clockwork.html
    --]]
    
    local Clockwork = Clockwork;
    
    local ITEM = Clockwork.item:New(nil, true);
    ITEM.name = "TSR Clothes Base";
    ITEM.model = "models/props_c17/suitcase_passenger_physics.mdl";
    ITEM.weight = 2;
    ITEM.useText = "Wear";
    ITEM.category = "Clothing";
    ITEM.description = "A suitcase full of clothes.";
    
    -- A function to get the model name.
    function ITEM:GetModelName(player, group)
       local modelName = nil;
       
       if (!player) then
         player = Clockwork.Client;
       end;
       
       if (group) then
         modelName = string.gsub(string.lower(Clockwork.player:GetDefaultModel(player)), "^.-/.-/", "");
       else
         modelName = string.gsub(string.lower(Clockwork.player:GetDefaultModel(player)), "^.-/.-/.-/", "");
       end;
       
       if (!string.find(modelName, "male") and !string.find(modelName, "female")) then
         if (group) then
           group = "group05/";
         else
           group = "";
         end;
         
         if (SERVER) then
           if (player:GetGender() == GENDER_FEMALE) then
             return group.."female_04.mdl";
           else
             return group.."male_05.mdl";
           end;
         elseif (player:GetGender() == GENDER_FEMALE) then
           return group.."female_04.mdl";
         else
           return group.."male_05.mdl";
         end;
       else
         return modelName;
       end;
    end;
    
    -- Called when the item's client side model is needed.
    function ITEM:GetClientSideModel()
       local replacement = nil;
       
       if (self.GetReplacement) then
         replacement = self:GetReplacement(Clockwork.Client);
       end;
       
       if (type(replacement) == "string") then
         return replacement;
       elseif (self("replacement")) then
         return self("replacement");
       elseif (self("group")) then
         return "models/thespireroleplay/humans/"..self("group").."/"..self:GetModelName();
       end;
    end;
    
    -- Called when a player changes clothes.
    function ITEM:OnChangeClothes(player, bIsWearing)
       if (bIsWearing) then
         local replacement = nil;
         
         if (self.GetReplacement) then
           replacement = self:GetReplacement(player);
         end;
         
         if (type(replacement) == "string") then
           player:SetModel(replacement);
         elseif (self("replacement")) then
           player:SetModel(self("replacement"));
         elseif (self("group")) then
           player:SetModel("models/thespireroleplay/humans/"..self("group").."/"..self:GetModelName(player));
         end;
       else
         Clockwork.player:SetDefaultModel(player);
         Clockwork.player:SetDefaultSkin(player);
       end;
       
       if (self.OnChangedClothes) then
         self:OnChangedClothes(player, bIsWearing);
       end;
    end;
    
    -- Called to get whether a player has the item equipped.
    function ITEM:HasPlayerEquipped(player, bIsValidWeapon)
       if (CLIENT) then
         return Clockwork.player:IsWearingItem(self);
       else
         return player:IsWearingItem(self);
       end;
    end;
    
    -- Called when a player has unequipped the item.
    function ITEM:OnPlayerUnequipped(player, extraData)
       player:RemoveClothes();
    end;
    
    -- Called when a player drops the item.
    function ITEM:OnDrop(player, position)
       if (player:IsWearingItem(self)) then
         Clockwork.player:Notify(player, "You cannot drop this while you are wearing it!");
         return false;
       end;
    end;
    
    -- Called when a player uses the item.
    function ITEM:OnUse(player, itemEntity)
       if (self("whitelist") and !table.HasValue(self("whitelist"), player:GetFaction())) then
         Clockwork.player:Notify(player, "Your faction cannot wear this clothing!");
         return false;
       end;
       
       if (player:Alive() and !player:IsRagdolled()) then
         if (!self.CanPlayerWear or self:CanPlayerWear(player, itemEntity) != false) then
           player:SetClothesData(self);
           return true;
         end;
       else
         Clockwork.player:Notify(player, "You cannot do this action at the moment!");
       end;
    
       return false;
    end;
    
    if (CLIENT) then
       function ITEM:GetClientSideInfo()
         if (!self:IsInstance()) then return; end;
         
         if (Clockwork.player:IsWearingItem(self)) then
           return "Is Wearing: Yes";
         else
           return "Is Wearing: No";
         end;
       end;
    end;
    
    Clockwork.item:Register(ITEM);
    
    Use this item base instead. Replace "clothes_base" in your item(s) with "tsr_clothes_base" and it should work fine.
     
    • Good Coder Good Coder x 1
  3. NoahtheBoah36™

    NoahtheBoah36™ Clockwork Retard Clockwork Customer Active Member

    I'm assuming if I do so I name the file accordingly?

    Edit: The answer is yes.

    Second Edit: Alright so, I tried using this code, it worked with the base hl2 models (yay!) but unfortunately I guess I was unclear. I was attempting to use models from the same pack as the ones I'm switching to, which have the same model path...

    models/thespireroleplay/humans/group004/male_06.mdl

    And, upon hovering over the error model it creates in my inventory, I can see that it is attempting to load, with the example of the clothing model with group 011...

    models/thespireroleplay/humans/group011/group004/male_06.mdl

    So, how would one make it ignore that group004 from the character's base model to get the clothing to work? (The solution would ideally apply to group### not just group004 as there are many group model options I intend to have as the base.

    I will, however, experiment, google, etc. and keep working at it until I get a response though, so I might post my solution here for sharing purposes but if not then I'm still struggling.

    By the way, thank you Viz, while it didn't do exactly what I wanted the clothes base you whipped up made a whole lot of the junk in the item bases make sense to me that I didn't understand at all before, so thank you.

    Third Edit: I'm not sure why it works, but I found a fix. In the section where it has two lines of code that look like this:

    Code:
    if (group) then
         modelName = string.gsub(string.lower(Clockwork.player:GetDefaultModel(player)), "^.-/.-/", "");
       else
         modelName = string.gsub(string.lower(Clockwork.player:GetDefaultModel(player)), "^.-/.-/.-/", "");
       end;
    
    I changed it to look like this:

    Code:
    if (group) then
         modelName = string.gsub(string.lower(Clockwork.player:GetDefaultModel(player)), "^.-/.-/", "");
       else
         modelName = string.gsub(string.lower(Clockwork.player:GetDefaultModel(player)), "^.-/.-/.-/.-/", "");
       end;
    
    Now the Spire Roleplay models I was using are working, which is what I needed, so yay.

    Perhaps somebody more knowledgeable than me can tell you why that worked, but I think it has to do with the number of sections of folders within which the model is stored. So, by having an additional .-/ there it caused it to delve one level deeper, thus removing the group from the model names in order to make it work.
     
    Last edited: Nov 5, 2018