PAC in gamemodes - CapsAdmin/pac3 GitHub Wiki
How can I restrict PAC to donators only?
hook.Add("PrePACConfigApply", "donators only", function(ply, outfit_data)
if not ply:IsDonator() then
return false, "give us money!"
end
end)
the code should be in garrysmod/addons/pac_for_donators_only/lua/autorun/server/pac_for_donators_only.lua
if the files or folders don't exist, create them
How can I restrict PAC to certain ranks?
-- add/change rank names here in the same format
local ranks = {
["moderators"] = true,
["vip"] = true,
["owner"] = true,
["admins"] = true,
["superadmin"] = true,
["vipadmin"] = true,
}
hook.Add("PrePACConfigApply", "PACRankRestrict", function(ply)
if not ranks[ply:GetUserGroup()] then
return false,"Insufficient rank to use PAC."
end
end)
Make sure to add a hook for PrePACEditorOpen
if you also need the editor restricted. Keep in mind PrePACEditorOpen
is a clientside hook. (just copy the hook portion and replace PrePACConfigApply
with PrePACEditorOpen
)
How can I restrict camera movement?
set pac_restrictions on the server to 1 this wont stop cheaters though!
How do I get rid of the editor?
Remove these files:
addons/pac3/lua/editor/*
addons/pac3/lua/autorun/pac_editor_init.lua
this will also get rid of features such as being able to wear outfits on the server
How do I prevent the editor from being opened?
You can do this using the PrePACEditorOpen hook. Example:
hook.Add( "PrePACEditorOpen", "RestrictToSuperadmin", function( ply )
if not ply:IsSuperAdmin( ) then
return false
end
end )
This example allows only superadmins to open the editor. This should be put in lua/autorun. Note that this does not prevent additional editor features, such as wearing on server which can be done through console commands.
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)