PAC3 Clothing

Hey, So I’ve just been playing with PAC3 for the past few days and I’ve discovered a outfit that I’d like all players to spawn with, I’m not sure how to do this so I browse the internet and found this: https://github.com/CapsAdmin/pac3/wiki/PAC-in-gamemodes#how-do-i-attach-parts-to-my-entity I think this is towards the idea that I want although I’m still pretty clueless to how I would get this working.

I’ve also created a NPC that can sell outfits from PAC3 Although I’m unsure on how to make this work too. I’ve tried using the command: pac_wear_parts backpack , Although this replaces the currently worn outfit and just shows the backpack, Is there anyway for it just to add items to the outfit? I’ve created an autoload.txt outfit that applies to the character on spawn but this only works for me because the outfits are clientside.

Sorry for all these questions, I’ve tried contacting the owner of the addon for assistance but he just provided me with the same link I found. If anyone has any questions about what I’m querying about then reply and I will reply! I understand this is a lot to ask!

https://github.com/CapsAdmin/pac3/wiki/PAC-in-gamemodes#how-do-i-attach-parts-to-my-entity
Did you read it mate?

**How do I attach parts to my entity?
**
There’s a few ways to do it.
using pac.AddEntityClassListener



pac.AddEntityClassListener(class_name, outfit_table, check_function, draw_distance)


Example



pac.AddEntityClassListener("npc_someone", pac.luadata.ReadFile("mygamemode/clothing/pants.txt"))


This makes it so every time you spawn “npc_someone” it will attach the outfit “pants.txt” It’s also removed when you remove the npc as well.

using pac.SetupENT



pac.SetupENT(entity_table, owner_override)


Which will add some functions to the entity provided.

The functions added are:



nil = ENT:AttachPACPart(outfit)
nil = ENT:RemovePACPart(outfit)

nil = ENT:SetPACDrawDistance(distance)
number = ENT:GetPACDrawDistance()

nil = ENT:SetShowPACPartsInEditor(boolean)
bool = ENT:GetShowPACPartsInEditor()

part = ENT:FindPACPart(outfit, part_name)
pos, ang = ENT:GetPACPartPosAng(outfit, part_name)

To see what these do see “lua\pac3\core\client\integration_tools.lua”

Example



if CLIENT then 
    local outfit = pac.luadata.ReadFile("pac3/mech.txt")

    pac.SetupENT(ENT) -- this can also be used in initialize using "self" instead of "ENT"

    function ENT:Initialize()
        self:AttachPACPart(outfit)
    end

    function ENT:OnRemove()
        self:RemovePACPart(outfit)
    end
end
The outfit table itself is used as a key. You also don't have to use pac.luadata.ReadFile You can also just copy the contents of mech.txt and paste it in a table like so:

local outfit = {*paste here*}
So the outfit data is stored inside the Lua file itself.¨

You can also use pac.SetupSWEP which makes it so the outfit owner is the player instead of the weapon entity itself.

Complete entity example
local outfit = {
-- start of outfit.txt
    [1] = {
    ["children"] = {
        [1] = {
            ["children"] = {
                [1] = {
                    ["children"] = {
                    },
                    ["self"] = {
                        ["ClassName"] = "proxy",
                        ["UniqueID"] = "3120004463",
                        ["Expression"] = "hsv_to_color(time()*100)",
                        ["GlobalID"] = "4180875644",
                        ["VariableName"] = "Color",
                    },
                },
            },
            ["self"] = {
                ["UniqueID"] = "884479784",
                ["GlobalID"] = "1864536752",
                ["Position"] = Vector(0, 0, 28),
                ["Size"] = 2.175,
                ["Color"] = Vector(255, 12, 0),
                ["EditorExpand"] = true,
                ["Model"] = "models/pac/default.mdl",
                ["ClassName"] = "model",
                ["Name"] = "ball",
            },
        },
    },
    ["self"] = {
        ["ClassName"] = "group",
        ["OwnerName"] = "self",
        ["EditorExpand"] = true,
        ["GlobalID"] = "3872319760",
        ["UniqueID"] = "3296086797",
        ["Name"] = "my outfit",
        ["Description"] = "add parts to me!",
    },
},
-- end of outfit.txt
}

local ENT = {}

ENT.Base = "base_anim"
ENT.Type = "anim"

ENT.ClassName = "pac_test"

if CLIENT then
    pac.SetupENT(ENT)

    function ENT:Draw()
        self:DrawModel()
    end

    function ENT:Think()
        -- manipualte it here!
        if self.ball then
            self.ball:SetSize(2 + math.sin(RealTime())) 
        end 
    end

    function ENT:Initialize()
        self:AttachPACPart(outfit)

        -- find the ball part
        self.ball = self:FindPACPart(outfit, "ball")        
    end

    function ENT:OnRemove()
        self:RemovePACPart(outfit)  
    end
end

if SERVER then
    function ENT:Initialize()
        self:SetModel("models/props_borealis/bluebarrel001.mdl")
        self:PhysicsInit(SOLID_VPHYSICS)
        self:SetMoveType(MOVETYPE_NONE)
    end
end

scripted_ents.Register(ENT, ENT.ClassName)

Awesome! Thanks I guess I should probably read over it more :stuck_out_tongue: At “npc_someone” what would I replace it with for players? player_default?

Not sure if it will help because I haven’t tested it but you could try,



if SERVER then

  util.AddNetworkString("test_pac_wear")
  util.AddNetworkString("test_pac_takeoff")

  local pl = FindMetaTable("Player")

  function pl:PAC_wear(outfitpath)
    net.Start("test_pac_wear")
      net.WriteInt(self:EntIndex(),16)
      net.WriteString(outfitpath)
    net.Broadcast()
  end

  function pl:PAC_takeoff(outfitpath)
    net.Start("test_pac_takeoff")
      net.WriteInt(self:EntIndex(),16)
      net.WriteString(outfitpath)
    net.BroadCast()
  end

else


  net.Receive("test_pac_wear",function()
    local pl = player.GetByID(net.ReadInt(16))
    local outfit = pac.luadata.ReadFile(net.ReadString())

    if not pl.AttachPACPart then pac.SetupENT(pl) end
    pl:AttachPACPart(outfit)
  end)

  net.Receive("test_pac_takeoff",function()
    local pl = player.GetByID(net.ReadInt(16))
    local outfit = pac.luadata.ReadFile(net.ReadString())

    if not pl.AttachPACPart then pac.SetupENT(pl) end
    pl:RemovePACPart(outfit)
  end)

end


then you can call ply:PAC_attach(“pac3/outfit.txt”) on the server and it should attach the part for all clients.

Thanks so much for helping me out and providing a example.

I’ve added the code(using PlayerSay just to test) and the outfit/parts still don’t seem to be applied to the player, let me know if I’ve done something wrong.

The autoload document is the outfit document in the garrysmod/data directory.


hook.Add( "PlayerSay", "PlayerSayExample", function( pl, text, team )
	pl:PAC_wear("data/autoload.txt")
end)

if SERVER then

  util.AddNetworkString("test_pac_wear")
  util.AddNetworkString("test_pac_takeoff")

  local pl = FindMetaTable("Player")

  function pl:PAC_wear(outfitpath)
    net.Start("test_pac_wear")
      net.WriteInt(self:EntIndex(),16)
      net.WriteString(outfitpath)
    net.Broadcast()
  end

  function pl:PAC_takeoff(outfitpath)
    net.Start("test_pac_takeoff")
      net.WriteInt(self:EntIndex(),16)
      net.WriteString(outfitpath)
    net.BroadCast()
  end

else


  net.Receive("test_pac_wear",function()
    local pl = player.GetByID(net.ReadInt(16))
    local outfit = pac.luadata.ReadFile(net.ReadString())

    if not pl.AttachPACPart then pac.SetupENT(pl) end
    pl:AttachPACPart(outfit)
  end)

  net.Receive("test_pac_takeoff",function()
    local pl = player.GetByID(net.ReadInt(16))
    local outfit = pac.luadata.ReadFile(net.ReadString())

    if not pl.AttachPACPart then pac.SetupENT(pl) end
    pl:RemovePACPart(outfit)
  end)

end

i managed to get this to work but unsure how to equip multiple items

Do you think you could share the code you used?

it is the exact code above but i fixed the BroadCast() error (changed it to Broadcast()) and also to get it to work make sure when you call the function PAC_wear to use the full file path like… PAC_wear(pac3/test.txt)

Awesome, Also to equip multiple items just add multiple items to the text file. Also the file path I used was complete “data/autoload.txt” Is fetching from the servers files “garrysmod/data/autoload.txt”

I can’t use multiple text files as I’m wanting them to stay separate for more customization, and if its in data folder just do PAC_wear(‘autoload.txt’)

Thanks for the path info, I see what you are wanting which is what I’d like too, I’ll spend a few days experimenting with it and if I advance on anything I will post back here.

Great!

[editline]16th March 2016[/editline]

I actually have a piece of code I believe will work, I’ll test it when I get home in about 8 hours

Can anyone send me a friendrequest on Steam?

Gonna pay for setting it up :v

Tried my code and didnt work sadly :frowning:

Bump anyone help?

if you’re gonna be a fucking money whore they might as well buy pointshop2

Bump

Where the code?

I used your original code just changed BroadCast to Broadcast

are there any errors?