Skip to content
CapsAdmin edited this page Jan 16, 2014 · 18 revisions

How do I prevent players from loading their own outfits?

Getting rid of the editor will fix this. See the below.

How get rid of the editor?

To get rid of the editor remove these files:

addons/pac3/lua/editor/*

addons/pac3/lua/autorun/pac_editor_init.lua

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)