This commit is contained in:
TW1STaL1CKY 2024-07-13 19:32:23 +01:00
parent 33555dc03a
commit 2694f7a124
19 changed files with 592 additions and 427 deletions

View File

@ -15,6 +15,10 @@ local table = table
local Color = Color
local NULL = NULL
local classname_event = "event"
local prefix_get = "Get"
local prefix_set = "Set"
local pac_editor_scale = GetConVar("pac_editor_scale")
local pac_popups_preferred_location = GetConVar("pac_popups_preferred_location")
@ -232,7 +236,7 @@ do -- owner
local parent = parents[i]
-- legacy behavior
if parent.ClassName == "event" and not parent.RootOwner then
if parent.ClassName == classname_event and not parent.RootOwner then
local parent = parent:GetParent()
if parent:IsValid() then
local parent = parent:GetParent()
@ -272,7 +276,7 @@ do -- scene graph
-- this will handle cases like if a part is removed and added again
for _, key in pairs(self.PartReferenceKeys) do
if self[key] and self[key].UniqueID == part.UniqueID then
self["Set" .. key](self, part)
self[prefix_set .. key](self, part)
end
end
@ -284,7 +288,7 @@ do -- scene graph
if not keys then return end
for _, key in pairs(keys) do
self["Set" .. key](self, part)
self[prefix_set .. key](self, part)
end
end
end
@ -486,6 +490,7 @@ do -- scene graph
function PART:CallRecursive(func, a, b, c)
assert(c == nil, "EXTEND ME")
if self[func] then
self[func](self, a, b, c)
end
@ -500,8 +505,9 @@ do -- scene graph
end
end
function PART:CallRecursiveOnClassName(class_name, func, a,b,c)
function PART:CallRecursiveOnClassName(class_name, func, a, b, c)
assert(c == nil, "EXTEND ME")
if self[func] and self.ClassName == class_name then
self[func](self, a,b,c)
end
@ -510,7 +516,7 @@ do -- scene graph
for i = 1, #children do
local child = children[i]
if child[func] and self.ClassName == class_name then
if child[func] and child.ClassName == class_name then
child[func](child, a,b,c)
end
end
@ -599,7 +605,7 @@ do -- scene graph
end
function PART:SetSmallIcon(str)
if str == "event" then str = "icon16/clock_red.png" end
if str == classname_event then str = "icon16/clock_red.png" end
if self.pace_tree_node then
if self.pace_tree_node.Icon then
@ -893,7 +899,7 @@ do -- serializing
do
function PART:GetProperty(name)
local val = self["Get" .. name]
local val = self[prefix_get .. name]
if val == nil then
if self.GetDynamicProperties then
@ -908,9 +914,11 @@ do -- serializing
end
function PART:SetProperty(key, val)
if self["Set" .. key] ~= nil then
if self["Get" .. key](self) ~= val then
self["Set" .. key](self, val)
local setFunc = self[prefix_set .. key]
if setFunc ~= nil then
if self[prefix_get .. key](self) ~= val then
setFunc(self, val)
end
elseif self.GetDynamicProperties then
local info = self:GetDynamicProperties()[key]
@ -930,8 +938,8 @@ do -- serializing
table_insert(out, {
key = key,
set = function(v) self["Set" .. key](self, v) end,
get = function() return self["Get" .. key](self) end,
set = function(v) self[prefix_set .. key](self, v) end,
get = function() return self[prefix_get .. key](self) end,
udata = pac.GetPropertyUserdata(self, key) or {},
})
@ -1014,12 +1022,14 @@ do -- serializing
for key, value in next, tbl.self do
if key == "UniqueID" then goto CONTINUE end
local setFunc = self[prefix_set .. key]
if self["Set" .. key] then
if setFunc then
if key == "Material" then
table_insert(self.delayed_variables, {key = key, val = value})
end
self["Set" .. key](self, value)
setFunc(self, value)
elseif key ~= "ClassName" then
pac.dprint("settable: unhandled key [%q] = %q", key, tostring(value))
end
@ -1089,7 +1099,7 @@ do -- serializing
local tbl = {self = {ClassName = self.ClassName}, children = {}}
for _, key in pairs(self:GetStorableVars()) do
local var = self[key] and self["Get" .. key](self) or self[key]
local var = self[key] and self[prefix_get .. key](self) or self[key]
var = pac.CopyValue(var) or var
if make_copy_name and var ~= "" and (key == "UniqueID" or key:sub(-3) == "UID") then
@ -1122,7 +1132,7 @@ do -- serializing
local tbl = {self = {ClassName = self.ClassName}, children = {}}
for _, key in pairs(self:GetStorableVars()) do
local var = self[key] and self["Get" .. key](self) or self[key]
local var = self[key] and self[prefix_get .. key](self) or self[key]
var = pac.CopyValue(var) or var
if key == "Name" and self[key] == "" then
@ -1153,12 +1163,14 @@ do -- serializing
for key, value in pairs(tbl.self) do
if key == "UniqueID" then goto CONTINUE end
local setFunc = self[prefix_set .. key]
if self["Set" .. key] then
if setFunc then
if key == "Material" then
table_insert(self.delayed_variables, {key = key, val = value})
end
self["Set" .. key](self, value)
setFunc(self, value)
elseif key ~= "ClassName" then
pac.dprint("settable: unhandled key [%q] = %q", key, tostring(value))
end
@ -1192,7 +1204,7 @@ do -- serializing
goto CONTINUE
end
tbl.self[key] = pac.CopyValue(self["Get" .. key](self))
tbl.self[key] = pac.CopyValue(self[prefix_get .. key](self))
::CONTINUE::
end
@ -1249,11 +1261,13 @@ do
return
end
if self.delayed_variables then
for i = 1, #self.delayed_variables do
local data = self.delayed_variables[i]
local delayedVars = self.delayed_variables
self["Set" .. data.key](self, data.val)
if delayedVars then
for i = 1, #delayedVars do
local data = delayedVars[i]
self[prefix_set .. data.key](self, data.val)
end
self.delayed_variables = nil
@ -1272,6 +1286,7 @@ end
--the popup system
function PART:SetupEditorPopup(str, force_open, tbl)
local legacy_help_popup_hack = false
if not tbl then
legacy_help_popup_hack = false
elseif tbl.from_legacy then
@ -1293,9 +1308,11 @@ function PART:SetupEditorPopup(str, force_open, tbl)
local default_state = str == nil or str == ""
local info_string
if self.ClassName == "event" and default_state then
if self.ClassName == classname_event and default_state then
info_string = self:GetEventTutorialText()
end
info_string = info_string or str or self.ClassName .. "\nno special information available"
if default_state and pace then

View File

@ -1,18 +1,19 @@
local pac = pac
local pairs = pairs
local IsValid = IsValid
local unpack = unpack
local IsValid = IsValid
local LocalToWorld = LocalToWorld
local math_sin = math.sin
local RealTime = RealTime
local Entity = Entity
local ipairs = ipairs
local NULL = NULL
local LerpVector = LerpVector
local LerpAngle = LerpAngle
local Angle = Angle
local Vector = Vector
local NULL = NULL
local math_sin = math.sin
local util_QuickTrace = util.QuickTrace
local pac = pac
local pac_isCameraAllowed = pac.CreateClientConVarFast("pac_enable_camera_as_bone", "1", true, "boolean")
pac.BoneNameReplacements =
@ -35,7 +36,9 @@ pac.BoneNameReplacements =
}
function pac.GetAllBones(ent)
ent = ent or NULL
if not ent then
ent = NULL
end
local tbl = {}
@ -45,12 +48,15 @@ function pac.GetAllBones(ent)
local count = ent:GetBoneCount() or 0
local boneNameReplacements = pac.BoneNameReplacements
for bone = 0, count do
local name = ent:GetBoneName(bone)
local friendly = name
if name then
for _, value in pairs(pac.BoneNameReplacements) do
for i = 1, #boneNameReplacements do
local value = boneNameReplacements[i]
friendly = friendly:gsub(value[1], value[2])
end
@ -77,11 +83,14 @@ function pac.GetAllBones(ent)
local attachments = ent:GetAttachments()
if attachments then
for _, data in pairs(attachments) do
for i = 1, #attachments do
local data = attachments[i]
local parent_i = ent:GetParentAttachment(data.id)
if parent_i == -1 then
parent_i = nil
end
local friendly = data.name or "????"
friendly = friendly
@ -207,15 +216,14 @@ local function GetBonePosition(ent, id)
return pos, ang
end
local angle_origin = Angle(0,0,0)
local UP = Vector(0,0,1):Angle()
local angle_origin = Angle(0, 0, 0)
local UP = Vector(0, 0, 1):Angle()
function pac.GetBonePosAng(ent, id, parent)
if not ent:IsValid() then return Vector(), Angle() end
if id == "physgun_beam_endpos" then
if ent.pac_drawphysgun_event then
local ply, wep, enabled, target, bone, hitpos = unpack(ent.pac_drawphysgun_event)
local endpos
@ -236,7 +244,7 @@ function pac.GetBonePosAng(ent, id, parent)
endpos = target:LocalToWorld(hitpos)
end
else
endpos = ply.pac_traceres and ply.pac_traceres.HitPos or util_QuickTrace(ply:EyePos(), ply:EyeAngles():Forward() * 16000, {ply, ply:GetParent()}).HitPos
endpos = ply.pac_traceres and ply.pac_traceres.HitPos or util_QuickTrace(ply:EyePos(), ply:GetAimVector() * 16000, {ply, ply:GetParent()}).HitPos
end
end
@ -250,7 +258,8 @@ function pac.GetBonePosAng(ent, id, parent)
end
elseif id == "player_eyes" then
local oldEnt = ent -- Track reference to the original entity in case we aren't allowed to draw here
local ent = ent.pac_traceres and ent.pac_traceres.Entity or util_QuickTrace(ent:EyePos(), ent:EyeAngles():Forward() * 16000, {ent, ent:GetParent()}).Entity
local ent = ent.pac_traceres and ent.pac_traceres.Entity or util_QuickTrace(ent:EyePos(), ent:GetAimVector() * 16000, {ent, ent:GetParent()}).Entity
local allowed = pac_isCameraAllowed()
if ent:IsValid() and (allowed or ent ~= pac.LocalPlayer) then -- Make sure we don't draw on viewer's screen if we aren't allowed to
@ -273,17 +282,17 @@ function pac.GetBonePosAng(ent, id, parent)
elseif id == "eyepos_ang" then
return ent:EyePos(), ent:GetAngles()
elseif id == "hitpos_world_props" then
local res = util_QuickTrace(ent:EyePos(), ent:EyeAngles():Forward() * 16000, function(ent)
local res = util_QuickTrace(ent:EyePos(), ent:GetAimVector() * 16000, function(ent)
return ent:GetClass() == "prop_physics"
end)
return res.HitPos, res.HitNormal:Angle()
elseif id == "hitpos_world" then
local res = util_QuickTrace(ent:EyePos(), ent:EyeAngles():Forward() * 16000, function(ent)
local res = util_QuickTrace(ent:EyePos(), ent:GetAimVector() * 16000, function(ent)
return ent:IsWorld()
end)
return res.HitPos, res.HitNormal:Angle()
elseif id == "hitpos_world_noang" then
local res = util_QuickTrace(ent:EyePos(), ent:EyeAngles():Forward() * 16000, function(ent)
local res = util_QuickTrace(ent:EyePos(), ent:GetAimVector() * 16000, function(ent)
return ent:IsWorld()
end)
return res.HitPos, angle_origin
@ -291,7 +300,7 @@ function pac.GetBonePosAng(ent, id, parent)
if ent.pac_traceres then
return ent.pac_traceres.HitPos, ent.pac_traceres.HitNormal:Angle()
else
local res = util_QuickTrace(ent:EyePos(), ent:EyeAngles():Forward() * 16000, {ent, ent:GetOwner()})
local res = util_QuickTrace(ent:EyePos(), ent:GetAimVector() * 16000, {ent, ent:GetOwner()})
return res.HitPos, res.HitNormal:Angle()
end
@ -299,7 +308,7 @@ function pac.GetBonePosAng(ent, id, parent)
if ent.pac_traceres then
return ent.pac_traceres.HitPos, ent:EyeAngles()
else
local res = util_QuickTrace(ent:EyePos(), ent:EyeAngles():Forward() * 16000, {ent, ent:GetOwner()})
local res = util_QuickTrace(ent:EyePos(), ent:GetAimVector() * 16000, {ent, ent:GetOwner()})
return res.HitPos, ent:EyeAngles()
end
@ -309,7 +318,7 @@ function pac.GetBonePosAng(ent, id, parent)
ang.p = 0
return ent.pac_traceres.HitPos, ang
else
local res = util_QuickTrace(ent:EyePos(), ent:EyeAngles():Forward() * 16000, {ent, ent:GetOwner()})
local res = util_QuickTrace(ent:EyePos(), ent:GetAimVector() * 16000, {ent, ent:GetOwner()})
return res.HitPos, ent:EyeAngles()
end
@ -398,6 +407,9 @@ do -- bone manipulation for boneanimlib
local ManipulateBonePosition = entmeta.ManipulateBonePosition
local ManipulateBoneAngles = entmeta.ManipulateBoneAngles
local ManipulateBoneJiggle = entmeta.ManipulateBoneJiggle
local SetFlexScale = entmeta.SetFlexScale
local SetFlexWeight = entmeta.SetFlexWeight
local GetFlexWeight = entmeta.GetFlexWeight
function pac.ResetBones(ent)
ent.pac_bones_once = true
@ -430,18 +442,15 @@ do -- bone manipulation for boneanimlib
if ent.pac_touching_flexes then
local reset_scale = false
for id, time in pairs(ent.pac_touching_flexes) do
if not reset_scale then
ent:SetFlexScale(1)
SetFlexScale(ent, 1)
reset_scale = true
end
if time < pac.RealTime then
ent:SetFlexWeight(id, 0)
else
if ent:GetFlexWeight(id) == 0 then
ent.pac_touching_flexes[id] = nil
end
SetFlexWeight(ent, id, 0)
elseif GetFlexWeight(ent, id) == 0 then
ent.pac_touching_flexes[id] = nil
end
end
end
@ -449,35 +458,54 @@ do -- bone manipulation for boneanimlib
hook.Call("PAC3ResetBones", nil, ent)
end
function pac.SetEntityBoneMatrix(ent, i, matrix)
pac.ManipulateBonePosition(ent, i, matrix:GetTranslation())
pac.ManipulateBoneAngles(ent, i, matrix:GetAngles())
end
local function pacManipulateBonePosition(ent, entTbl, id, var)
if not entTbl.pac_boneanim then
entTbl.pac_boneanim = {positions = {}, angles = {}}
end
entTbl.pac_boneanim.positions[id] = var
function pac.ResetEntityBoneMatrix(ent, i)
pac.ManipulateBoneAngles(ent, i, angle_zero)
pac.ManipulateBonePosition(ent, i, vector_origin)
end
function pac.ManipulateBonePosition(ply, id, var)
ply.pac_boneanim = ply.pac_boneanim or {positions = {}, angles = {}}
ply.pac_boneanim.positions[id] = var
if not ply.pac_has_parts then
ply:ManipulateBonePosition(id, var)
if not entTbl.pac_has_parts then
ManipulateBonePosition(ent, id, var)
end
end
function pac.ManipulateBoneAngles(ply, id, var)
ply.pac_boneanim = ply.pac_boneanim or {positions = {}, angles = {}}
ply.pac_boneanim.angles[id] = var
if not ply.pac_has_parts then
ply:ManipulateBoneAngles(id, var)
local function pacManipulateBoneAngles(ent, entTbl, id, var)
if not entTbl.pac_boneanim then
entTbl.pac_boneanim = {positions = {}, angles = {}}
end
entTbl.pac_boneanim.angles[id] = var
if not entTbl.pac_has_parts then
ManipulateBoneAngles(ent, id, var)
end
end
function pac.SetEntityBoneMatrix(ent, i, matrix, entTbl)
if not entTbl then
entTbl = ent:GetTable()
end
if not entTbl.pac_boneanim then
entTbl.pac_boneanim = {positions = {}, angles = {}}
end
pacManipulateBonePosition(ent, entTbl, i, matrix:GetTranslation())
pacManipulateBoneAngles(ent, entTbl, i, matrix:GetAngles())
end
function pac.ResetEntityBoneMatrix(ent, i, entTbl)
if not entTbl then
entTbl = ent:GetTable()
end
if not entTbl.pac_boneanim then
entTbl.pac_boneanim = {positions = {}, angles = {}}
end
pacManipulateBonePosition(ent, entTbl, i, vector_origin)
pacManipulateBoneAngles(ent, entTbl, i, angle_zero)
end
end

View File

@ -1,13 +1,16 @@
local ipairs = ipairs
local table_insert = table.insert
local isnumber = isnumber
local tonumber = tonumber
local isstring = isstring
local tostring = tostring
local table_Merge = table.Merge
local istable = istable
local pac = pac
local isnumber = isnumber
local istable = istable
local isstring = isstring
local tonumber = tonumber
local tostring = tostring
local setmetatable = setmetatable
local table_insert = table.insert
local table_Merge = table.Merge
local prefix_get = "Get"
local prefix_set = "Set"
local suffix_uid = "UID"
pac.PartTemplates = pac.PartTemplates or {}
pac.VariableOrder = {}
@ -57,8 +60,8 @@ do
end
local function insert_key(tbl, key)
for _, k in ipairs(tbl) do
if k == key then
for i = 1, #tbl do
if tbl[i] == key then
return
end
end
@ -67,7 +70,6 @@ do
end
function META:SetPropertyGroup(name)
local tbl = self.PART
self.group = name
@ -102,15 +104,18 @@ do
pac.VariableOrder[tbl.ClassName] = pac.VariableOrder[tbl.ClassName] or {}
insert_key(pac.VariableOrder[tbl.ClassName], key)
local setKey = prefix_set .. key
local getKey = prefix_get .. key
if isnumber(def) then
tbl["Set" .. key] = tbl["Set" .. key] or function(self, var) self[key] = tonumber(var) end
tbl["Get" .. key] = tbl["Get" .. key] or function(self) return tonumber(self[key]) end
tbl[setKey] = tbl[setKey] or function(self, var) self[key] = tonumber(var) end
tbl[getKey] = tbl[getKey] or function(self) return tonumber(self[key]) end
elseif isstring(def) then
tbl["Set" .. key] = tbl["Set" .. key] or function(self, var) self[key] = tostring(var) end
tbl["Get" .. key] = tbl["Get" .. key] or function(self) return tostring(self[key]) end
tbl[setKey] = tbl[setKey] or function(self, var) self[key] = tostring(var) end
tbl[getKey] = tbl[getKey] or function(self) return tostring(self[key]) end
else
tbl["Set" .. key] = tbl["Set" .. key] or function(self, var) self[key] = var end
tbl["Get" .. key] = tbl["Get" .. key] or function(self) return self[key] end
tbl[setKey] = tbl[setKey] or function(self, var) self[key] = var end
tbl[getKey] = tbl[getKey] or function(self) return self[key] end
end
tbl[key] = def
@ -137,12 +142,16 @@ do
local PART = self.PART
self:GetSet(key .. "UID", "", udata)
local setKey = prefix_set .. key
local getKey = prefix_get .. key
local uidKey = key .. suffix_uid
PART["Set" .. key .. "UID"] = function(self, uid)
self:GetSet(uidKey, "", udata)
PART[setKey .. suffix_uid] = function(self, uid)
if uid == "" or not uid then
self["Set" .. key](self, NULL)
self[key.."UID"] = ""
self[setKey](self, NULL)
self[uidKey] = ""
return
end
@ -150,7 +159,7 @@ do
uid = uid.UniqueID
end
self[key.."UID"] = uid
self[uidKey] = uid
local owner_id = self:GetPlayerOwnerId()
local part = pac.GetPartFromUniqueID(owner_id, uid)
@ -158,10 +167,10 @@ do
if part:IsValid() then
if part == self then
part = NULL
self[key.."UID"] = ""
self[uidKey] = ""
end
self["Set" .. key](self, part)
self[setKey](self, part)
elseif uid ~= "" then
self.unresolved_uid_parts = self.unresolved_uid_parts or {}
self.unresolved_uid_parts[owner_id] = self.unresolved_uid_parts[owner_id] or {}
@ -170,15 +179,15 @@ do
end
end
PART["Set" .. key] = PART["Set" .. key] or function(self, var)
PART[setKey] = PART[setKey] or function(self, var)
self[key] = var
if var and var:IsValid() then
self[key.."UID"] = var:GetUniqueID()
self[uidKey] = var:GetUniqueID()
else
self[key.."UID"] = ""
self[uidKey] = ""
end
end
PART["Get" .. key] = PART["Get" .. key] or function(self) return self[key] end
PART[getKey] = PART[getKey] or function(self) return self[key] end
PART[key] = NULL
PART.PartReferenceKeys = PART.PartReferenceKeys or {}
@ -188,8 +197,8 @@ do
end
function META:RemoveProperty(key)
self.PART["Set" .. key] = nil
self.PART["Get" .. key] = nil
self.PART[prefix_set .. key] = nil
self.PART[prefix_get .. key] = nil
self.PART["Is" .. key] = nil
self.PART[key] = nil

View File

@ -1,6 +1,14 @@
local pairs = pairs
local IsEntity = IsEntity
local MOVETYPE_NOCLIP = MOVETYPE_NOCLIP
local next = next
local IsEntity = IsEntity
local entMeta = FindMetaTable("Entity")
local IsEntValid = entMeta.IsValid
local GetTable = entMeta.GetTable
local SetCycle = entMeta.SetCycle
local SetPoseParameter = entMeta.SetPoseParameter
local classname_prisoner_pod = "prop_vehicle_prisoner_pod"
pac.AddHook("RenderScene", "eyeangles_eyepos", function(pos, ang)
pac.EyePos = pos
@ -8,7 +16,6 @@ pac.AddHook("RenderScene", "eyeangles_eyepos", function(pos, ang)
end)
pac.AddHook("DrawPhysgunBeam", "physgun_event", function(ply, wep, enabled, target, bone, hitpos)
if enabled then
ply.pac_drawphysgun_event = {ply, wep, enabled, target, bone, hitpos}
else
@ -17,7 +24,7 @@ pac.AddHook("DrawPhysgunBeam", "physgun_event", function(ply, wep, enabled, targ
local pac_drawphysgun_event_part = ply.pac_drawphysgun_event_part
if pac_drawphysgun_event_part then
for event in pairs(pac_drawphysgun_event_part) do
for event in next, pac_drawphysgun_event_part do
if event:IsValid() then
event:OnThink()
else
@ -26,7 +33,6 @@ pac.AddHook("DrawPhysgunBeam", "physgun_event", function(ply, wep, enabled, targ
end
end
if ply.pac_hide_physgun_beam then
return false
end
@ -34,65 +40,66 @@ end)
do
pac.AddHook("UpdateAnimation", "event_part", function(ply)
if not IsEntity(ply) or not ply:IsValid() then return end
if not IsEntity(ply) or not IsEntValid(ply) then return end
local plyTbl = GetTable(ply)
if ply.pac_death_physics_parts and ply:Alive() and ply.pac_physics_died then
if plyTbl.pac_death_physics_parts and ply:Alive() and plyTbl.pac_physics_died then
pac.CallRecursiveOnOwnedParts(ply, "OnBecomePhysics")
ply.pac_physics_died = false
plyTbl.pac_physics_died = false
end
do
local tbl = ply.pac_pose_params
local tbl = plyTbl.pac_pose_params
if tbl then
for _, data in pairs(tbl) do
ply:SetPoseParameter(data.key, data.val)
for _, data in next, tbl do
SetPoseParameter(ply, data.key, data.val)
end
end
end
local animrate = 1
if ply.pac_global_animation_rate and ply.pac_global_animation_rate ~= 1 then
if ply.pac_global_animation_rate == 0 then
if plyTbl.pac_global_animation_rate and plyTbl.pac_global_animation_rate ~= 1 then
if plyTbl.pac_global_animation_rate == 0 then
animrate = ply:GetModelScale() * 2
elseif ply.pac_global_animation_rate ~= 1 then
ply:SetCycle((pac.RealTime * ply.pac_global_animation_rate)%1)
animrate = ply.pac_global_animation_rate
elseif plyTbl.pac_global_animation_rate ~= 1 then
SetCycle(ply, (pac.RealTime * plyTbl.pac_global_animation_rate) % 1)
animrate = plyTbl.pac_global_animation_rate
end
end
if ply.pac_animation_sequences then
local part, thing = next(ply.pac_animation_sequences)
if plyTbl.pac_animation_sequences then
local part, thing = next(plyTbl.pac_animation_sequences)
if part and part:IsValid() then
if part.OwnerCycle then
if part.Rate == 0 then
animrate = 1
ply:SetCycle(part.Offset % 1)
SetCycle(ply, part.Offset % 1)
else
animrate = animrate * part.Rate
end
end
elseif part and not part:IsValid() then
ply.pac_animation_sequences[part] = nil
plyTbl.pac_animation_sequences[part] = nil
end
end
if animrate ~= 1 then
ply:SetCycle((pac.RealTime * animrate) % 1)
SetCycle(ply, (pac.RealTime * animrate) % 1)
return true
end
if ply.pac_holdtype_alternative_animation_rate then
local length = ply:GetVelocity():Dot(ply:EyeAngles():Forward()) > 0 and 1 or -1
if plyTbl.pac_holdtype_alternative_animation_rate then
local length = ply:GetVelocity():Dot(ply:GetAimVector()) > 0 and 1 or -1
local scale = ply:GetModelScale() * 2
if scale ~= 0 then
ply:SetCycle(pac.RealTime / scale * length)
SetCycle(ply, pac.RealTime / scale * length)
else
ply:SetCycle(0)
SetCycle(ply, 0)
end
return true
@ -100,65 +107,64 @@ do
local vehicle = ply:GetVehicle()
if ply.pac_last_vehicle ~= vehicle then
if ply.pac_last_vehicle ~= nil then
if plyTbl.pac_last_vehicle ~= vehicle then
if plyTbl.pac_last_vehicle ~= nil then
pac.CallRecursiveOnAllParts("OnVehicleChanged", ply, vehicle)
end
ply.pac_last_vehicle = vehicle
plyTbl.pac_last_vehicle = vehicle
end
end)
end
local MOVETYPE_NOCLIP = MOVETYPE_NOCLIP
pac.AddHook("TranslateActivity", "events", function(ply, act)
if IsEntity(ply) and ply:IsValid() then
if not IsEntity(ply) or not IsEntValid(ply) then return end
local plyTbl = GetTable(ply)
-- animation part
if ply.pac_animation_sequences and next(ply.pac_animation_sequences) then
-- dont do any holdtype stuff if theres a sequence
return
end
-- animation part
if plyTbl.pac_animation_sequences and next(plyTbl.pac_animation_sequences) then
-- dont do any holdtype stuff if theres a sequence
return
end
if ply.pac_animation_holdtypes then
local key, val = next(ply.pac_animation_holdtypes)
if key then
if not val.part:IsValid() then
ply.pac_animation_holdtypes[key] = nil
else
return val[act]
end
if plyTbl.pac_animation_holdtypes then
local key, val = next(plyTbl.pac_animation_holdtypes)
if key then
if not val.part:IsValid() then
plyTbl.pac_animation_holdtypes[key] = nil
else
return val[act]
end
end
end
-- holdtype part
if ply.pac_holdtypes then
local key, act_table = next(ply.pac_holdtypes)
-- holdtype part
if plyTbl.pac_holdtypes then
local key, act_table = next(plyTbl.pac_holdtypes)
if key then
if not act_table.part:IsValid() then
ply.pac_holdtypes[key] = nil
else
if key then
if not act_table.part:IsValid() then
plyTbl.pac_holdtypes[key] = nil
else
if act_table[act] and act_table[act] ~= -1 then
return act_table[act]
end
if act_table[act] and act_table[act] ~= -1 then
return act_table[act]
end
local vehicle = ply:GetVehicle()
if ply:GetVehicle():IsValid() and ply:GetVehicle():GetClass() == "prop_vehicle_prisoner_pod" then
return act_table.sitting
end
if IsEntValid(vehicle) and vehicle:GetClass() == classname_prisoner_pod then
return act_table.sitting
end
if act_table.noclip ~= -1 and ply:GetMoveType() == MOVETYPE_NOCLIP then
return act_table.noclip
end
if act_table.noclip ~= -1 and ply:GetMoveType() == MOVETYPE_NOCLIP then
return act_table.noclip
end
if act_table.air ~= -1 and ply:GetMoveType() ~= MOVETYPE_NOCLIP and not ply:IsOnGround() then
return act_table.air
end
if act_table.air ~= -1 and ply:GetMoveType() ~= MOVETYPE_NOCLIP and not ply:IsOnGround() then
return act_table.air
end
if act_table.fallback ~= -1 then
return act_table.fallback
end
if act_table.fallback ~= -1 then
return act_table.fallback
end
end
end
@ -166,13 +172,16 @@ pac.AddHook("TranslateActivity", "events", function(ply, act)
end)
pac.AddHook("CalcMainActivity", "events", function(ply, act)
if IsEntity(ply) and ply:IsValid() and ply.pac_animation_sequences then
local key, val = next(ply.pac_animation_sequences)
if not IsEntity(ply) or not IsEntValid(ply) then return end
local plyTbl = GetTable(ply)
if plyTbl.pac_animation_sequences then
local key, val = next(plyTbl.pac_animation_sequences)
if not key then return end
if not val.part:IsValid() then
ply.pac_animation_sequences[key] = nil
plyTbl.pac_animation_sequences[key] = nil
return
end
@ -184,7 +193,7 @@ pac.AddHook("pac_PlayerFootstep", "events", function(ply, pos, snd, vol)
ply.pac_last_footstep_pos = pos
if ply.pac_footstep_override then
for _, part in pairs(ply.pac_footstep_override) do
for _, part in next, ply.pac_footstep_override do
if not part:IsHidden() then
part:PlaySound(snd, vol)
end

View File

@ -2,23 +2,24 @@ local SysTime = SysTime
local pairs = pairs
local Color = Color
local tostring = tostring
local Vector = Vector
local EyePos = EyePos
local ScrW = ScrW
local ScrH = ScrH
local cam_Start2D = cam.Start2D
local cam_IgnoreZ = cam.IgnoreZ
local Vector = Vector
local cam_End2D = cam.End2D
local math_Clamp = math.Clamp
local EyePos = EyePos
local surface_SetFont = surface.SetFont
local surface_GetTextSize = surface.GetTextSize
local draw_DrawText = draw.DrawText
local string_format = string.format
local input_GetCursorPos = input.GetCursorPos
local vgui_CursorVisible = vgui.CursorVisible
local ScrW = ScrW
local ScrH = ScrH
local input_LookupBinding = input.LookupBinding
local LocalPlayer = LocalPlayer
local input_IsMouseDown = input.IsMouseDown
local cam_End2D = cam.End2D
local vgui_CursorVisible = vgui.CursorVisible
local white = Color(255, 255, 255) --its alpha will be temporarily tampered with, don't risk breaking color_white
local max_render_time_cvar = CreateClientConVar("pac_max_render_time", 0)
@ -70,6 +71,8 @@ function pac.DrawRenderTimeExceeded(ent)
surface_SetFont("ChatFont")
local _, h = surface_GetTextSize("|")
white.a = alpha * 255
draw_DrawText(
string_format(
"pac3 outfit took %.2f/%i ms to render",
@ -79,9 +82,10 @@ function pac.DrawRenderTimeExceeded(ent)
"ChatFont",
pos_2d.x,
pos_2d.y,
Color(255,255,255,alpha * 255),
white,
1
)
local x, y = pos_2d.x, pos_2d.y + h
local mx, my = input_GetCursorPos()
@ -93,9 +97,12 @@ function pac.DrawRenderTimeExceeded(ent)
local hovering = mx > x - dist and mx < x + dist and my > y - dist and my < y + dist
local button = vgui_CursorVisible() and "click" or ("press " .. input_LookupBinding("+use"))
draw_DrawText(button .. " here to try again", "ChatFont", x, y, Color(255,255,255,alpha * (hovering and 255 or 100) ), 1)
if hovering and LocalPlayer():KeyDown(IN_USE) or (vgui_CursorVisible() and input_IsMouseDown(MOUSE_LEFT)) then
white.a = alpha * (hovering and 255 or 100)
draw_DrawText(button .. " here to try again", "ChatFont", x, y, white, 1)
if hovering and pac.LocalPlayer:KeyDown(IN_USE) or (vgui_CursorVisible() and input_IsMouseDown(MOUSE_LEFT)) then
ent.pac_render_time_exceeded = nil
end
end

View File

@ -16,9 +16,12 @@ local IsValid = entMeta.IsValid
local IsPlayer = entMeta.IsPlayer
local IsDormant = entMeta.IsDormant
local GetEyePos = entMeta.EyePos
local GetTable = entMeta.GetTable
local Alive = plyMeta.Alive
local GetViewModel = plyMeta.GetViewModel
local GetHands = plyMeta.GetHands
local GetRagdollEntity = plyMeta.GetRagdollEntity
local ShouldDrawLocalPlayer = plyMeta.ShouldDrawLocalPlayer
local force_rendering = false
local forced_rendering = false
@ -257,32 +260,34 @@ end
pac.AddHook("Think", "events", function()
for _, ply in player.Iterator() do
if not ent_parts[ply] then continue end
if pac.IsEntityIgnored(ply) then continue end
if not ent_parts[ply] or pac.IsEntityIgnored(ply) then continue end
local plyTbl = GetTable(ply)
if Alive(ply) then
if ply.pac_revert_ragdoll then
ply.pac_revert_ragdoll()
ply.pac_revert_ragdoll = nil
if plyTbl.pac_revert_ragdoll then
plyTbl.pac_revert_ragdoll()
plyTbl.pac_revert_ragdoll = nil
end
continue
end
local rag = ply:GetRagdollEntity()
local rag = GetRagdollEntity(ply)
if not IsValid(rag) then
pac.HideEntityParts(ply)
continue
end
-- so it only runs once
if ply.pac_ragdoll == rag then continue end
ply.pac_ragdoll = rag
if plyTbl.pac_ragdoll == rag then continue end
plyTbl.pac_ragdoll = rag
rag.pac_ragdoll_owner = ply
rag = hook.Run("PACChooseDeathRagdoll", ply, rag) or rag
if ply.pac_death_physics_parts then
if ply.pac_physics_died then return end
if plyTbl.pac_death_physics_parts then
if plyTbl.pac_physics_died then return end
for _, part in next, parts_from_uid(pac.Hash(ply)) do
if part.is_model_part then
@ -316,8 +321,8 @@ pac.AddHook("Think", "events", function()
end
end
end
ply.pac_physics_died = true
elseif ply.pac_death_ragdollize or ply.pac_death_ragdollize == nil then
plyTbl.pac_physics_died = true
elseif plyTbl.pac_death_ragdollize or plyTbl.pac_death_ragdollize == nil then
pac.HideEntityParts(ply)
for _, part in next, ent_parts[ply] do
@ -327,7 +332,7 @@ pac.AddHook("Think", "events", function()
rag:SetOwner(ply)
pac.ShowEntityParts(rag)
ply.pac_revert_ragdoll = function()
plyTbl.pac_revert_ragdoll = function()
ply.pac_ragdoll = nil
if not ent_parts[ply] then return end
@ -749,7 +754,9 @@ do -- drawing
local pac_sv_draw_distance
pac.AddHook("Think", "update_parts", function()
localplayer = localplayer or LocalPlayer() -- LocalPlayer never changes once its valid, right?
if not localplayer then
localplayer = LocalPlayer() -- LocalPlayer never changes once its valid, right?
end
-- commonly used variables
pac.LocalPlayer = localplayer
@ -758,7 +765,9 @@ do -- drawing
pac.RealTime = RealTime()
pac.FrameNumber = pac.FrameNumber + 1
pac_sv_draw_distance = pac_sv_draw_distance or GetConVar("pac_sv_draw_distance")
if not pac_sv_draw_distance then
pac_sv_draw_distance = GetConVar("pac_sv_draw_distance")
end
draw_dist = cvar_distance:GetInt()
sv_draw_dist = pac_sv_draw_distance:GetFloat()
@ -819,13 +828,13 @@ do -- drawing
local cond = ent.IsPACWorldEntity
-- if the entity is the hands, check if we should not draw the localplayer
if (ent == pac.LocalHands or ent == pac.LocalViewModel) and not localplayer:ShouldDrawLocalPlayer() then
if (ent == pac.LocalHands or ent == pac.LocalViewModel) and not ShouldDrawLocalPlayer(localplayer) then
cond = true
end
-- if it's a player, draw if we can see them
if not cond and ent == localplayer then
cond = ent:ShouldDrawLocalPlayer()
cond = ShouldDrawLocalPlayer(ent)
end
-- if the entity has a camera part, draw if it's valid

View File

@ -2481,8 +2481,6 @@ do
--outsource the part pool operations
pac.UpdateButtonEvents(ply, key, down)
end)
PART.OldEvents.button = {
@ -2511,7 +2509,6 @@ do
return self:GetOperator() .. " \"" .. button .. "\"" .. " in (" .. active .. ")"
end,
callback = function(self, ent, button, holdtime, toggle)
local holdtime = holdtime or 0
local toggle = toggle or false
@ -2526,13 +2523,10 @@ do
self.toggleimpulsekey[button] = false
end
--print(button, "hold" ,self.holdtime)
local ply = self:GetPlayerOwner()
self.pac_broadcasted_buttons_holduntil = self.pac_broadcasted_buttons_holduntil or {}
if ply == pac.LocalPlayer then
ply.pac_broadcast_buttons = ply.pac_broadcast_buttons or {}
if not ply.pac_broadcast_buttons[button] then
@ -2544,19 +2538,13 @@ do
end
ply.pac_broadcast_buttons[button] = true
end
--print(button, ply.pac_broadcasted_buttons_holduntil[button], ply.pac_broadcast_buttons[button])
--PrintTable(ply.pac_broadcast_buttons)
--PrintTable(self.pac_broadcasted_buttons_holduntil)
end
local buttons = ply.pac_buttons
self.pac_broadcasted_buttons_holduntil[button] = self.pac_broadcasted_buttons_holduntil[button] or SysTime()
--print(button, self.toggle, self.togglestate)
--print(button,"until",self.pac_broadcasted_buttons_holduntil[button])
if buttons then
--print("trying to compare " .. SysTime() .. " > " .. self.pac_broadcasted_buttons_holduntil[button] - 0.05)
if self.toggle then
return self.togglestate
elseif self.holdtime > 0 then
@ -2564,11 +2552,9 @@ do
else
return buttons[button]
end
end
end,
end
}
end
do

View File

@ -1,15 +1,16 @@
local FrameTime = FrameTime
local physenv_GetGravity = physenv.GetGravity
local util_QuickTrace = util.QuickTrace
local math_AngleDifference = math.AngleDifference
local FrameTime = FrameTime
local VectorRand = VectorRand
local Vector = Vector
local Angle = Angle
local physenv_GetGravity = physenv.GetGravity
local BUILDER, PART = pac.PartTemplate("base_drawable")
PART.ClassName = "jiggle"
PART.Group = 'model'
PART.Icon = 'icon16/chart_line.png'
PART.Group = "model"
PART.Icon = "icon16/chart_line.png"
BUILDER:StartStorableVars()
BUILDER:GetSet("Strain", 0.5, {editor_onchange = function(self, num)
@ -37,8 +38,6 @@ BUILDER:StartStorableVars()
BUILDER:GetSet("ResetOnHide", false)
BUILDER:EndStorableVars()
local math_AngleDifference = math.AngleDifference
function PART:Reset()
local pos, ang = self:GetDrawPosition()
@ -83,17 +82,21 @@ function PART:OnDraw()
self.first_time_reset = false
end
local delta = FrameTime()
local speed = self.Speed * delta
if not self.pos then
self.pos = pos * 1
end
self.vel = self.vel or VectorRand()
self.pos = self.pos or pos * 1
if self.StopRadius ~= 0 and self.pos and self.pos:DistToSqr(pos) < (self.StopRadius * self.StopRadius) then
if self.StopRadius ~= 0 and self.pos:DistToSqr(pos) < (self.StopRadius ^ 2) then
self.vel = Vector()
return
end
if not self.vel then
self.vel = VectorRand()
end
local speed = self.Speed * FrameTime()
if self.JigglePosition then
if not self.ConstrainX then
self.vel.x = self.vel.x + (pos.x - self.pos.x)
@ -148,9 +151,9 @@ function PART:OnDraw()
end
if self.ConstrainSphere > 0 then
local len = math.min(self.pos:Distance(pos), self.ConstrainSphere)
local diff = self.pos - pos
self.pos = pos + (self.pos - pos):GetNormalized() * len
self.pos = pos + (diff:GetNormalized() * math.min(diff:Length(), self.ConstrainSphere))
end
if self.JiggleAngle then

View File

@ -1,6 +1,20 @@
local NULL = NULL
local pairs = pairs
local entMeta = FindMetaTable("Entity")
local IsEntValid = entMeta.IsValid
local GetTable = entMeta.GetTable
local GetBoneCount = entMeta.GetBoneCount
local GetBoneMatrix = entMeta.GetBoneMatrix
local SetBoneMatrix = entMeta.SetBoneMatrix
local ManipulateBonePosition = entMeta.ManipulateBonePosition
local ManipulateBoneAngles = entMeta.ManipulateBoneAngles
local ManipulateBoneScale = entMeta.ManipulateBoneScale
local ManipulateBoneJiggle = entMeta.ManipulateBoneJiggle
local GetManipulateBonePosition = entMeta.GetManipulateBonePosition
local GetManipulateBoneAngles = entMeta.GetManipulateBoneAngles
local GetManipulateBoneScale = entMeta.GetManipulateBoneScale
for _, v in ents.Iterator() do
v.pac_bone_setup_data = nil
end
@ -67,7 +81,7 @@ PART.OnParent = PART.OnShow
function PART:OnThink()
-- this is to setup the cached values
if not self.first_getbpos and self:GetOwner():IsValid() then
if not self.first_getbpos and IsEntValid(self:GetOwner()) then
self:GetBonePosition()
self.first_getbpos = true
end
@ -76,7 +90,7 @@ end
function PART:OnHide()
local owner = self:GetOwner()
if owner:IsValid() then
if IsEntValid(owner) then
owner.pac_bone_setup_data = owner.pac_bone_setup_data or {}
owner.pac_bone_setup_data[self.UniqueID] = nil
end
@ -91,46 +105,45 @@ function PART:GetBonePosition()
return pos, ang
end
local function manpos(ent, id, pos, part)
local function manpos(ent, entTbl, id, pos, part)
if part.AlternativeBones then
ent.pac_bone_setup_data[part.UniqueID].pos = part.Position + part.PositionOffset
entTbl.pac_bone_setup_data[part.UniqueID].pos = part.Position + part.PositionOffset
else
ent:ManipulateBonePosition(id, ent:GetManipulateBonePosition(id) + pos)
ManipulateBonePosition(ent, id, GetManipulateBonePosition(ent, id) + pos)
part.modified_bones = true
end
end
local function manang(ent, id, ang, part)
local function manang(ent, entTbl, id, ang, part)
if part.AlternativeBones then
ent.pac_bone_setup_data[part.UniqueID].ang = part.Angles + part.AngleOffset
entTbl.pac_bone_setup_data[part.UniqueID].ang = part.Angles + part.AngleOffset
else
ent:ManipulateBoneAngles(id, ent:GetManipulateBoneAngles(id) + ang)
ManipulateBoneAngles(ent, id, GetManipulateBoneAngles(ent, id) + ang)
part.modified_bones = true
end
end
local inf_scale = Vector(math.huge, math.huge, math.huge)
local inf_scale_tempcrashfix = Vector(1,1,1)*0.001
local inf_scale_tempcrashfix = Vector(1, 1, 1) * 0.001
local function manscale(ent, id, scale, part)
local function manscale(ent, entTbl, id, scale, part)
if part.AlternativeBones then
ent.pac_bone_setup_data[part.UniqueID].scale = scale
entTbl.pac_bone_setup_data[part.UniqueID].scale = scale
else
ent:ManipulateBoneScale(id, ent:GetManipulateBoneScale(id) * scale)
ManipulateBoneScale(ent, id, GetManipulateBoneScale(ent, id) * scale)
part.modified_bones = true
end
end
local function scale_children(owner, id, scale, origin, ownerScale)
local count = owner:GetBoneCount()
ownerScale = ownerScale or owner.pac3_Scale or 1
local count = GetBoneCount(owner)
if count == 0 or count < id then return end
for i = 0, count - 1 do
if owner:GetBoneParent(i) ~= id then goto CONTINUE end
local mat = owner:GetBoneMatrix(i)
local mat = GetBoneMatrix(owner, i)
if mat then
if origin then
@ -138,7 +151,8 @@ local function scale_children(owner, id, scale, origin, ownerScale)
end
mat:Scale(mat:GetScale() * scale / ownerScale)
owner:SetBoneMatrix(i, mat)
SetBoneMatrix(owner, i, mat)
end
scale_children(owner, i, scale, origin, ownerScale)
@ -149,17 +163,22 @@ local in_build = false
function pac.build_bone_callback(ent)
if in_build then return end
local entTbl = GetTable(ent)
in_build = true
if ent.pac_matrixhack then
if entTbl.pac_matrixhack then
pac.LegacyScale(ent)
end
if ent.pac_bone_setup_data then
for uid, data in pairs(ent.pac_bone_setup_data) do
if entTbl.pac_bone_setup_data then
local entScale = entTbl.pac3_Scale or 1
for uid, data in pairs(entTbl.pac_bone_setup_data) do
local part = data.part or NULL
if part:IsValid() then
local mat = ent:GetBoneMatrix(data.bone)
local mat = GetBoneMatrix(ent, data.bone)
if mat then
if part.FollowPart:IsValid() and part.FollowPart.GetWorldAngles and part.FollowPart.GetWorldPosition then
if part.FollowAnglesOnly then
@ -185,24 +204,25 @@ function pac.build_bone_callback(ent)
end
if part.ScaleChildren then
local scale = part.Scale * part.Size
scale_children(ent, data.bone, scale, data.origin)
scale_children(ent, data.bone, part.Scale * part.Size, data.origin, entScale)
end
ent:SetBoneMatrix(data.bone, mat)
SetBoneMatrix(ent, data.bone, mat)
end
else
ent.pac_bone_setup_data[uid] = nil
entTbl.pac_bone_setup_data[uid] = nil
end
end
end
in_build = false
end
function PART:OnBuildBonePositions()
local owner = self:GetOwner()
if not IsEntValid(owner) then return end
if not owner:IsValid() then return end
local ownerTbl = GetTable(owner)
local index = self:GetModelBoneIndex()
@ -210,26 +230,34 @@ function PART:OnBuildBonePositions()
index = 0
end
owner.pac_bone_setup_data = owner.pac_bone_setup_data or {}
if not ownerTbl.pac_bone_setup_data then
ownerTbl.pac_bone_setup_data = {}
end
if self.AlternativeBones or self.ScaleChildren or self.FollowPart:IsValid() then
owner.pac_bone_setup_data[self.UniqueID] = owner.pac_bone_setup_data[self.UniqueID] or {}
owner.pac_bone_setup_data[self.UniqueID].bone = index
owner.pac_bone_setup_data[self.UniqueID].part = self
if not ownerTbl.pac_bone_setup_data[self.UniqueID] then
ownerTbl.pac_bone_setup_data[self.UniqueID] = {}
end
ownerTbl.pac_bone_setup_data[self.UniqueID].bone = index
ownerTbl.pac_bone_setup_data[self.UniqueID].part = self
else
owner.pac_bone_setup_data[self.UniqueID] = nil
ownerTbl.pac_bone_setup_data[self.UniqueID] = nil
end
local ang = self:CalcAngles(self.Angles) or self.Angles
if not owner.pac_follow_bones_function then
owner.pac_follow_bones_function = pac.build_bone_callback
if not ownerTbl.pac_follow_bones_function then
ownerTbl.pac_follow_bones_function = pac.build_bone_callback
local id
id = owner:AddCallback("BuildBonePositions", function(ent)
if not self:IsValid() then
owner:RemoveCallback("BuildBonePositions", id)
return
end
pac.build_bone_callback(ent)
end)
end
@ -240,48 +268,48 @@ function PART:OnBuildBonePositions()
ang.y = -ang.p
end
manpos(owner, index, self.Position + self.PositionOffset, self)
manang(owner, index, ang + self.AngleOffset, self)
manpos(owner, ownerTbl, index, self.Position + self.PositionOffset, self)
manang(owner, ownerTbl, index, ang + self.AngleOffset, self)
end
if owner.pac_bone_setup_data[self.UniqueID] then
if ownerTbl.pac_bone_setup_data[self.UniqueID] then
if self.MoveChildrenToOrigin then
owner.pac_bone_setup_data[self.UniqueID].origin = self:GetBonePosition()
ownerTbl.pac_bone_setup_data[self.UniqueID].origin = self:GetBonePosition()
else
owner.pac_bone_setup_data[self.UniqueID].origin = nil
ownerTbl.pac_bone_setup_data[self.UniqueID].origin = nil
end
end
owner:ManipulateBoneJiggle(index, isnumber(self.Jiggle) and self.Jiggle or (self.Jiggle and 1 or 0)) -- afaik anything but 1 is not doing anything at all
-- afaik anything but 1 is not doing anything at all
ManipulateBoneJiggle(owner, index, isnumber(self.Jiggle) and self.Jiggle or (self.Jiggle and 1 or 0))
local scale
if self.HideMesh then
scale = inf_scale
owner.pac_inf_scale = true
ownerTbl.pac_inf_scale = true
if self.InvertHideMesh then
local count = owner:GetBoneCount()
local count = GetBoneCount(owner)
for i = 0, count - 1 do
if i ~= index then
manscale(owner, i, inf_scale, self)
manscale(owner, ownerTbl, i, inf_scale, self)
end
end
return
end
else
owner.pac_inf_scale = false
ownerTbl.pac_inf_scale = false
scale = self.Scale * self.Size
end
manscale(owner, index, scale, self)
manscale(owner, ownerTbl, index, scale, self)
owner.needs_setupbones_from_legacy_bone_parts = true
ownerTbl.needs_setupbones_from_legacy_bone_parts = true
end
BUILDER:Register()

View File

@ -350,7 +350,7 @@ function PART:OnShow()
local ply_pos = self:GetPlayerOwner():GetPos()
local pos = self:GetWorldPosition()
if pos:DistToSqr(ply_pos) > (self.Radius * self.Radius) then
if pos:DistToSqr(ply_pos) > (self.Radius ^ 2) then
local clamped_pos = ply_pos + (pos - ply_pos):GetNormalized() * self.Radius
teleport_pos_final = clamped_pos
end

View File

@ -1,20 +1,12 @@
CreateConVar( "pac_model_max_scales", "10000", FCVAR_ARCHIVE, "Maximum scales model can have")
local pac = pac
local cam = cam
local cam_PopModelMatrix = cam.PopModelMatrix
local cam_PushModelMatrix = cam.PushModelMatrix
local Color = Color
local EF_BONEMERGE = EF_BONEMERGE
local MATERIAL_CULLMODE_CCW = MATERIAL_CULLMODE_CCW
local MATERIAL_CULLMODE_CW = MATERIAL_CULLMODE_CW
local Matrix = Matrix
local NULL = NULL
local render = render
local cam = cam
local surface = surface
local cam_PopModelMatrix = cam.PopModelMatrix
local cam_PushModelMatrix = cam.PushModelMatrix
local render_CullMode = render.CullMode
local render_MaterialOverride = render.ModelMaterialOverride
local render_MaterialOverrideByIndex = render.MaterialOverrideByIndex
@ -22,9 +14,19 @@ local render_RenderFlashlights = render.RenderFlashlights
local render_SetBlend = render.SetBlend
local render_SetColorModulation = render.SetColorModulation
local render_SuppressEngineLighting = render.SuppressEngineLighting
local surface = surface
local math_abs = math.abs
local math_Clamp = math.Clamp
local Color = Color
local Vector = Vector
local Matrix = Matrix
local ProtectedCall = ProtectedCall
local vector_origin = vector_origin
local NULL = NULL
local entMeta = FindMetaTable("Entity")
local IsEntValid = entMeta.IsValid
local IsPlayer = entMeta.IsPlayer
local GetBoneCount = entMeta.GetBoneCount
local BUILDER, PART = pac.PartTemplate("base_drawable")
@ -62,12 +64,14 @@ BUILDER:StartStorableVars()
:GetSet("ModelModifiers", "", {hidden = true})
:GetSet("Material", "", {editor_panel = "material"})
:GetSet("Materials", "", {hidden = true})
:GetSet("Skin", 0, {editor_onchange = function(self, num) return math.Round(math.Clamp(tonumber(num), 0, pace.current_part:GetOwner():SkinCount())) end})
:GetSet("Skin", 0, {editor_onchange = function(self, num) return math.Round(math_Clamp(tonumber(num), 0, pace.current_part:GetOwner():SkinCount())) end})
:GetSet("LevelOfDetail", 0, {editor_clamp = {-1, 8}, editor_round = true})
:GetSetPart("EyeTarget")
:EndStorableVars()
local model_max_scales = CreateConVar("pac_model_max_scales", "10000", FCVAR_ARCHIVE, "Maximum scales model can have")
PART.Owner = NULL
function PART:GetNiceName()
@ -78,7 +82,7 @@ end
function PART:GetDynamicProperties()
local ent = self:GetOwner()
if not ent:IsValid() or not ent:GetBodyGroups() then return end
if not IsEntValid(ent) or not ent:GetBodyGroups() then return end
local tbl = {}
@ -93,7 +97,7 @@ function PART:GetDynamicProperties()
get = function()
return self:ModelModifiersToTable(self:GetModelModifiers()).skin
end,
udata = {editor_onchange = function(self, num) return math.Clamp(math.Round(num), 0, ent:SkinCount() - 1) end},
udata = {editor_onchange = function(self, num) return math_Clamp(math.Round(num), 0, ent:SkinCount() - 1) end},
}
end
@ -109,13 +113,15 @@ function PART:GetDynamicProperties()
get = function()
return self:ModelModifiersToTable(self:GetModelModifiers())[info.name] or 0
end,
udata = {editor_onchange = function(self, num) return math.Clamp(math.Round(num), 0, info.num - 1) end, group = "bodygroups"},
udata = {editor_onchange = function(self, num) return math_Clamp(math.Round(num), 0, info.num - 1) end, group = "bodygroups"},
}
end
end
if ent:GetMaterials() and #ent:GetMaterials() > 1 then
for i, name in ipairs(ent:GetMaterials()) do
local materials = ent:GetMaterials()
if materials[2] then -- more than 1
for i, name in ipairs(materials) do
name = name:match(".+/(.+)") or name
tbl[name] = {
key = name,
@ -127,7 +133,7 @@ function PART:GetDynamicProperties()
local tbl = self.Materials:Split(";")
tbl[i] = val
for i, name in ipairs(ent:GetMaterials()) do
for i, name in ipairs(materials) do
tbl[i] = tbl[i] or ""
end
@ -143,18 +149,21 @@ end
function PART:SetLevelOfDetail(val)
self.LevelOfDetail = val
local ent = self:GetOwner()
if ent:IsValid() then
if IsEntValid(ent) then
ent:SetLOD(val)
end
end
function PART:SetSkin(var)
self.Skin = var
local owner = self:GetOwner()
function PART:SetSkin(val)
self.Skin = val
if owner:IsValid() then
owner:SetSkin(var)
local ent = self:GetOwner()
if IsEntValid(ent) then
ent:SetSkin(val)
end
end
@ -177,17 +186,19 @@ end
function PART:ModelModifiersToString(tbl)
local str = ""
for k, v in pairs(tbl) do
str = str .. k .. "=" .. v .. ";"
end
return str
end
function PART:SetModelModifiers(str)
self.ModelModifiers = str
local owner = self:GetOwner()
local ent = self:GetOwner()
if not owner:IsValid() then return end
if not IsEntValid(ent) then return end
local tbl = self:ModelModifiersToTable(str)
@ -196,12 +207,13 @@ function PART:SetModelModifiers(str)
tbl.skin = nil
end
if not owner:GetBodyGroups() then return end
self.draw_bodygroups = {}
for i, info in ipairs(owner:GetBodyGroups()) do
local bodygroups = ent:GetBodyGroups()
for i = 1, #bodygroups do
local info = bodygroups[i]
local val = tbl[info.name]
if val then
table.insert(self.draw_bodygroups, {info.id, val})
end
@ -234,7 +246,9 @@ end
function PART:SetMaterials(str)
self.Materials = str
local materials = self:GetOwner():IsValid() and self:GetOwner():GetMaterials()
local ent = self:GetOwner()
local materials = IsEntValid(ent) and ent:GetMaterials()
if not materials then return end
@ -266,17 +280,20 @@ end
function PART:Reset()
self:Initialize()
for _, key in pairs(self:GetStorableVars()) do
if PART[key] then
self["Set" .. key](self, self["Get" .. key](self))
end
end
self.cached_dynamic_props = nil
end
function PART:OnBecomePhysics()
local ent = self:GetOwner()
if not ent:IsValid() then return end
if not IsEntValid(ent) then return end
ent:PhysicsInit(SOLID_NONE)
ent:SetMoveType(MOVETYPE_NONE)
ent:SetNoDraw(true)
@ -293,10 +310,10 @@ function PART:Initialize()
end
function PART:OnShow()
local owner = self:GetParentOwner()
local ent = self:GetOwner()
local owner = self:GetParentOwner()
if ent:IsValid() and owner:IsValid() and owner ~= ent then
if IsEntValid(ent) and IsEntValid(owner) and owner ~= ent then
ent:SetPos(owner:EyePos())
ent:SetLegacyTransform(self.LegacyTransform)
self:SetBone(self:GetBone())
@ -327,9 +344,9 @@ function PART:BindMaterials(ent)
local mat = materials[i]
if mat then
render_MaterialOverrideByIndex(i-1, mat)
render_MaterialOverrideByIndex(i - 1, mat)
else
render_MaterialOverrideByIndex(i-1, nil)
render_MaterialOverrideByIndex(i - 1, nil)
end
end
elseif self.material_override then
@ -344,9 +361,9 @@ function PART:BindMaterials(ent)
local mat = stack[1]
if mat then
render_MaterialOverrideByIndex(i-1, mat:GetRawMaterial())
render_MaterialOverrideByIndex(i - 1, mat:GetRawMaterial())
else
render_MaterialOverrideByIndex(i-1, nil)
render_MaterialOverrideByIndex(i - 1, nil)
end
end
end
@ -360,7 +377,7 @@ function PART:BindMaterials(ent)
end
function PART:PreEntityDraw(ent, pos, ang)
if not ent:IsPlayer() and pos and ang then
if not IsPlayer(ent) and pos and ang then
if not self.skip_orient then
ent:SetPos(pos)
ent:SetAngles(ang)
@ -374,7 +391,8 @@ function PART:PreEntityDraw(ent, pos, ang)
local brightness = self.Brightness
-- render.SetColorModulation and render.SetAlpha set the material $color and $alpha.
render_SetColorModulation(r*brightness, g*brightness, b*brightness)
render_SetColorModulation(r * brightness, g * brightness, b * brightness)
if not pac.drawing_motionblur_alpha then
render_SetBlend(self.Alpha)
end
@ -412,7 +430,7 @@ end
function PART:OnDraw()
local ent = self:GetOwner()
if not ent:IsValid() then
if not IsEntValid(ent) then
self:Reset()
ent = self:GetOwner()
end
@ -424,7 +442,6 @@ function PART:OnDraw()
return
end
self:PreEntityDraw(ent, pos, ang)
self:DrawModel(ent, pos, ang)
self:PostEntityDraw(ent, pos, ang)
@ -465,10 +482,11 @@ end
function PART:DrawModel(ent, pos, ang)
if self.loading then
self:DrawLoadingText(ent, pos)
if not self.obj_mesh then return end
end
if self.Alpha == 0 or self.Size == 0 then return end
if self.loading and not self.obj_mesh then return end
if self.NoCulling or self.Invert then
render_CullMode(MATERIAL_CULLMODE_CW)
@ -543,7 +561,7 @@ function PART:RefreshModel()
local ent = self:GetOwner()
if ent:IsValid() then
if IsEntValid(ent) then
pac.ResetBoneCache(ent)
end
@ -600,7 +618,8 @@ end
function PART:ProcessModelChange()
local owner = self:GetOwner()
if not owner:IsValid() then return end
if not IsEntValid(owner) then return end
local path = self.Model
if path:find("://", nil, true) then
@ -610,7 +629,6 @@ function PART:ProcessModelChange()
pac.urlobj.GetObjFromURL(path, false, false,
function(meshes, err)
local function set_mesh(part, mesh)
local owner = part:GetOwner()
part.obj_mesh = mesh
@ -714,28 +732,29 @@ function PART:SetModel(path)
self.Model = path
local owner = self:GetOwner()
if not owner:IsValid() then return end
if not IsEntValid(owner) then return end
self.old_model = path
self:ProcessModelChange()
end
local NORMAL = Vector(1, 1, 1)
local vec_one = Vector(1, 1, 1)
function PART:CheckScale()
local owner = self:GetOwner()
if not owner:IsValid() then return end
-- RenderMultiply doesn't work with this..
if self.BoneMerge and owner:GetBoneCount() and owner:GetBoneCount() > 1 then
if self.Scale * self.Size ~= NORMAL then
if not self.requires_bone_model_scale then
self.requires_bone_model_scale = true
end
return true
end
if self.BoneMerge then
local owner = self:GetOwner()
self.requires_bone_model_scale = false
if IsEntValid(owner) and GetBoneCount(owner) > 1 then
if self.Scale * self.Size ~= vec_one then
if not self.requires_bone_model_scale then
self.requires_bone_model_scale = true
end
return true
end
self.requires_bone_model_scale = false
end
end
end
@ -745,16 +764,24 @@ function PART:SetAlternativeScaling(b)
end
function PART:SetScale(vec)
local max_scale = GetConVar("pac_model_max_scales"):GetFloat()
local largest_scale = math.max(math.abs(vec.x), math.abs(vec.y), math.abs(vec.z))
local max_scale = model_max_scales:GetFloat()
local largest_scale = math.max(math_abs(vec.x), math_abs(vec.y), math_abs(vec.z))
if vec and max_scale > 0 and (LocalPlayer() ~= self:GetPlayerOwner()) then --clamp for other players if they have pac_model_max_scales convar more than 0
vec = Vector(math.Clamp(vec.x, -max_scale, max_scale), math.Clamp(vec.y, -max_scale, max_scale), math.Clamp(vec.z, -max_scale, max_scale))
if vec and max_scale > 0 and pac.LocalPlayer ~= self:GetPlayerOwner() then --clamp for other players if they have pac_model_max_scales convar more than 0
vec = Vector(math_Clamp(vec.x, -max_scale, max_scale), math_Clamp(vec.y, -max_scale, max_scale), math_Clamp(vec.z, -max_scale, max_scale))
end
if largest_scale > 10000 then --warn about the default max scale
if largest_scale > 10000 then
--warn about the default max scale
self:SetError("Scale is being limited due to having an excessive component. Default maximum values are 10000")
else self:SetError() end --if ok, clear the warning
vec = vec or Vector(1, 1, 1)
else
--if ok, clear the warning
self:SetError()
end
if not vec then
vec = Vector(1, 1, 1)
end
self.Scale = vec
@ -763,11 +790,9 @@ function PART:SetScale(vec)
end
end
local vec_one = Vector(1, 1, 1)
function PART:ApplyMatrix()
local ent = self:GetOwner()
if not ent:IsValid() then return end
if not IsEntValid(ent) then return end
local mat = Matrix()
@ -776,7 +801,7 @@ function PART:ApplyMatrix()
mat:Rotate(self.Angles + self.AngleOffset)
end
if ent:IsPlayer() or ent:IsNPC() then
if IsPlayer(ent) or ent:IsNPC() then
pac.emut.MutateEntity(self:GetPlayerOwner(), "size", ent, self.Size, {
StandingHullHeight = self.StandingHullHeight,
CrouchingHullHeight = self.CrouchingHullHeight,
@ -820,13 +845,16 @@ function PART:SetSize(var)
end
function PART:CheckBoneMerge()
local ent = self:GetOwner()
if ent == pac.LocalHands or ent == pac.LocalViewModel then return end
if self.skip_orient then return end
if ent:IsValid() and not ent:IsPlayer() and ent:GetModel() then
local ent = self:GetOwner()
if ent ~= pac.LocalViewModel
and ent ~= pac.LocalHands
and IsEntValid(ent)
and not IsPlayer(ent)
and ent:GetModel()
then
if self.BoneMerge then
local owner = self:GetParentOwner()
@ -835,8 +863,10 @@ function PART:CheckBoneMerge()
if not ent:IsEffectActive(EF_BONEMERGE) then
ent:AddEffects(EF_BONEMERGE)
owner.pac_bonemerged = owner.pac_bonemerged or {}
table.insert(owner.pac_bonemerged, ent)
ent.RenderOverride = function()
ent.pac_drawing_model = true
ent:DrawModel()
@ -845,21 +875,21 @@ function PART:CheckBoneMerge()
end
end
else
if ent:GetParent():IsValid() then
local owner = ent:GetParent()
local owner = ent:GetParent()
if IsEntValid(owner) then
ent:SetParent(NULL)
if ent:IsEffectActive(EF_BONEMERGE) then
ent:RemoveEffects(EF_BONEMERGE)
ent.RenderOverride = nil
if owner:IsValid() then
owner.pac_bonemerged = owner.pac_bonemerged or {}
for i, v in ipairs(owner.pac_bonemerged) do
if v == ent then
table.remove(owner.pac_bonemerged, i)
break
end
owner.pac_bonemerged = owner.pac_bonemerged or {}
for i = 1, #owner.pac_bonemerged do
if owner.pac_bonemerged[i] == ent then
table.remove(owner.pac_bonemerged, i)
break
end
end
end
@ -871,21 +901,23 @@ function PART:CheckBoneMerge()
end
function PART:OnBuildBonePositions()
if self.AlternativeScaling then return end
if not self.AlternativeScaling and self.requires_bone_model_scale then
local ent = self:GetOwner()
local ent = self:GetOwner()
local owner = self:GetParentOwner()
if not IsEntValid(ent)
or GetBoneCount(ent) < 1
or not IsEntValid(self:GetParentOwner())
then
return
end
if not ent:IsValid() or not owner:IsValid() or not ent:GetBoneCount() or ent:GetBoneCount() < 1 then return end
if self.requires_bone_model_scale then
local scale = self.Scale * self.Size
for i = 0, ent:GetBoneCount() - 1 do
for i = 0, GetBoneCount(ent) - 1 do
if i == 0 then
ent:ManipulateBoneScale(i, ent:GetManipulateBoneScale(i) * Vector(scale.x ^ 0.25, scale.y ^ 0.25, scale.z ^ 0.25))
else
ent:ManipulateBonePosition(i, ent:GetManipulateBonePosition(i) + Vector((scale.x-1) ^ 4, 0, 0))
ent:ManipulateBonePosition(i, ent:GetManipulateBonePosition(i) + Vector((scale.x - 1) ^ 4, 0, 0))
ent:ManipulateBoneScale(i, ent:GetManipulateBoneScale(i) * scale)
end
end

View File

@ -225,7 +225,7 @@ function PART:OnThink()
end
-- this is nicer i think
if self.ConstrainSphere ~= 0 and phys:GetPos():DistToSqr(self.Parent:GetWorldPosition()) > (self.ConstrainSphere * self.ConstrainSphere) then
if self.ConstrainSphere ~= 0 and phys:GetPos():DistToSqr(self.Parent:GetWorldPosition()) > (self.ConstrainSphere ^ 2) then
if not self.PushFollow then
phys:SetPos(self.Parent:GetWorldPosition() + (self.Parent:GetWorldPosition() - phys:GetPos()):GetNormalized() * -self.ConstrainSphere)
--new push mode

View File

@ -5,9 +5,8 @@ local BUILDER, PART = pac.PartTemplate("base_movable")
PART.FriendlyName = "web sound"
PART.ClassName = "sound2"
PART.Icon = 'icon16/music.png'
PART.Group = 'effects'
PART.Icon = "icon16/music.png"
PART.Group = "effects"
BUILDER:StartStorableVars()
BUILDER:SetPropertyGroup("generic")

View File

@ -28,7 +28,7 @@ function pac.DrawTrail(self, len, spc, pos, ang, mat, scr,scg,scb,sca, ecr,ecg,e
local time = RealTime()
if not points[1] or points[#points].pos:DistToSqr(pos) > (spc * spc) then
if not points[1] or points[#points].pos:DistToSqr(pos) > (spc ^ 2) then
table_insert(points, {pos = pos * 1, life_time = time + len})
end

View File

@ -1,4 +1,3 @@
util.AddNetworkString("pac_proxy")
util.AddNetworkString("pac_event")
util.AddNetworkString("pac_event_set_sequence")
@ -6,11 +5,18 @@ util.AddNetworkString("pac_event_set_sequence")
net.Receive("pac_event_set_sequence", function(len, ply)
local event = net.ReadString()
local num = net.ReadUInt(8)
ply.pac_command_events = ply.pac_command_events or {}
for i=1,100,1 do
ply.pac_command_events[event..i] = nil
local plyTbl = ply:GetTable()
if not plyTbl.pac_command_events then
plyTbl.pac_command_events = {}
else
for i = 1, 100 do
plyTbl.pac_command_events[event .. i] = nil
end
end
ply.pac_command_events[event..num] = {name = event, time = pac.RealTime, on = 1}
plyTbl.pac_command_events[event .. num] = {name = event, time = pac.RealTime, on = 1}
end)
-- event
@ -20,11 +26,16 @@ concommand.Add("pac_event", function(ply, _, args)
local event = args[1]
local extra = tonumber(args[2]) or 0
if extra == 2 or args[2] == "toggle" then
ply.pac_event_toggles = ply.pac_event_toggles or {}
ply.pac_event_toggles[event] = not ply.pac_event_toggles[event]
local plyTbl = ply:GetTable()
extra = ply.pac_event_toggles[event] and 1 or 0
if extra == 2 or args[2] == "toggle" then
if not plyTbl.pac_event_toggles then
plyTbl.pac_event_toggles = {}
end
plyTbl.pac_event_toggles[event] = not plyTbl.pac_event_toggles[event]
extra = plyTbl.pac_event_toggles[event] and 1 or 0
end
net.Start("pac_event", true)
@ -32,9 +43,12 @@ concommand.Add("pac_event", function(ply, _, args)
net.WriteString(event)
net.WriteInt(extra, 8)
net.Broadcast()
ply.pac_command_events = ply.pac_command_events or {}
ply.pac_command_events[event] = ply.pac_command_events[event] or {}
ply.pac_command_events[event] = {name = event, time = pac.RealTime, on = extra}
if not plyTbl.pac_command_events then
plyTbl.pac_command_events = {}
end
plyTbl.pac_command_events[event] = {name = event, time = pac.RealTime, on = extra}
end)
concommand.Add("+pac_event", function(ply, _, args)
@ -42,8 +56,14 @@ concommand.Add("+pac_event", function(ply, _, args)
if args[2] == "2" or args[2] == "toggle" then
local event = args[1]
ply.pac_event_toggles = ply.pac_event_toggles or {}
ply.pac_event_toggles[event] = true
local plyTbl = ply:GetTable()
if not plyTbl.pac_event_toggles then
plyTbl.pac_event_toggles = {}
end
plyTbl.pac_event_toggles[event] = true
net.Start("pac_event", true)
net.WritePlayer(ply)
@ -63,8 +83,15 @@ concommand.Add("-pac_event", function(ply, _, args)
if args[2] == "2" or args[2] == "toggle" then
local event = args[1]
ply.pac_event_toggles = ply.pac_event_toggles or {}
ply.pac_event_toggles[event] = false
local plyTbl = ply:GetTable()
if not plyTbl.pac_event_toggles then
plyTbl.pac_event_toggles = {}
end
plyTbl.pac_event_toggles[event] = false
net.Start("pac_event", true)
net.WritePlayer(ply)
net.WriteString(event)
@ -82,30 +109,38 @@ end)
concommand.Add("pac_proxy", function(ply, _, args)
str = args[1]
if ply:IsValid() then
ply.pac_proxy_events = ply.pac_proxy_events or {}
local plyTbl = ply:GetTable()
if not plyTbl.pac_proxy_events then
plyTbl.pac_proxy_events = {}
end
local x
local y
local z
if ply.pac_proxy_events[str] ~= nil then
local x, y, z
if plyTbl.pac_proxy_events[str] ~= nil then
if args[2] then
if string.sub(args[2],1,2) == "++" or string.sub(args[2],1,2) == "--" then
x = ply.pac_proxy_events[str].x + tonumber(string.sub(args[2],2,#args[2]))
else x = tonumber(args[2]) or ply.pac_proxy_events[str].x or 0 end
if string.sub(args[2], 1, 2) == "++" or string.sub(args[2], 1, 2) == "--" then
x = plyTbl.pac_proxy_events[str].x + tonumber(string.sub(args[2], 2, #args[2]))
else
x = tonumber(args[2]) or plyTbl.pac_proxy_events[str].x or 0
end
end
if args[3] then
if string.sub(args[3],1,2) == "++" or string.sub(args[3],1,2) == "--" then
y = ply.pac_proxy_events[str].y + tonumber(string.sub(args[3],2,#args[3]))
else y = tonumber(args[3]) or ply.pac_proxy_events[str].y or 0 end
if string.sub(args[3], 1, 2) == "++" or string.sub(args[3], 1, 2) == "--" then
y = plyTbl.pac_proxy_events[str].y + tonumber(string.sub(args[3], 2, #args[3]))
else
y = tonumber(args[3]) or plyTbl.pac_proxy_events[str].y or 0
end
end
if not args[3] then y = 0 end
if args[4] then
if string.sub(args[4],1,2) == "++" or string.sub(args[4],1,2) == "--" then
z = ply.pac_proxy_events[str].z + tonumber(string.sub(args[4],2,#args[4]))
else z = tonumber(args[4]) or ply.pac_proxy_events[str].z or 0 end
if string.sub(args[4], 1, 2) == "++" or string.sub(args[4], 1, 2) == "--" then
z = plyTbl.pac_proxy_events[str].z + tonumber(string.sub(args[4], 2, #args[4]))
else
z = tonumber(args[4]) or plyTbl.pac_proxy_events[str].z or 0
end
end
if not args[4] then z = 0 end
else
@ -113,7 +148,8 @@ concommand.Add("pac_proxy", function(ply, _, args)
y = tonumber(args[3]) or 0
z = tonumber(args[4]) or 0
end
ply.pac_proxy_events[str] = {name = str, x = x, y = y, z = z}
plyTbl.pac_proxy_events[str] = {name = str, x = x, y = y, z = z}
net.Start("pac_proxy", true)
net.WritePlayer(ply)
@ -123,6 +159,4 @@ concommand.Add("pac_proxy", function(ply, _, args)
net.WriteFloat(y or 0)
net.WriteFloat(z or 0)
net.Broadcast()
--PrintTable(ply.pac_proxy_events[str])
end)

View File

@ -46,8 +46,7 @@ timer.Create("pac_render_times", 0.1, 0, function()
end
end)
local maxDist = 100
maxDist = maxDist * maxDist
local maxDist = 100 ^ 2
pac.AddHook("HUDPaint", "pac_show_render_times", function()
if not pace.IsActive() or not pace.IsFocused() or not enable:GetBool() then return end

View File

@ -104,9 +104,9 @@ end
CreateClientConVar("pac_limit_sounds_draw_distance", 20000, true, false, "Overall multiplier for PAC3 sounds")
cvars.AddChangeCallback("pac_limit_sounds_draw_distance", function(_,_,val)
if not isnumber(val) then val = 0 end
pac.sounds_draw_dist_sqr = val * val
pac.sounds_draw_dist_sqr = val ^ 2
end)
pac.sounds_draw_dist_sqr = math.pow(GetConVar("pac_limit_sounds_draw_distance"):GetInt(), 2)
pac.sounds_draw_dist_sqr = GetConVar("pac_limit_sounds_draw_distance"):GetInt() ^ 2
CreateClientConVar("pac_volume", 1, true, false, "Overall multiplier for PAC3 sounds",0,1)
cvars.AddChangeCallback("pac_volume", function(_,_,val)

View File

@ -570,9 +570,7 @@ if SERVER then
part.Bounce = net.ReadInt(8) / 100
local radius_limit = 2000
local radius_limit_scaled_sqr = radius_limit * ply:GetModelScale()
radius_limit_scaled_sqr = radius_limit_scaled_sqr * radius_limit_scaled_sqr
local radius_limit_scaled_sqr = (radius_limit * ply:GetModelScale()) ^ 2
if pos:DistToSqr(ply:EyePos()) > radius_limit_scaled_sqr then
local ok = false

View File

@ -1,3 +1,5 @@
local ipairs = ipairs
local animations = pac.animations or {}
animations.playing = {}
@ -310,7 +312,11 @@ local function GetFrameBoneInfo(ent, tGestureTable, iFrame, iBoneID)
end
local function ProcessAnimations(ent)
for name, tbl in pairs(ent.pac_animations) do
local entTbl = ent:GetTable()
if not entTbl.pac_animations then return end
for name, tbl in pairs(entTbl.pac_animations) do
local frame = tbl.Frame
local frame_data = tbl.FrameData[frame]
local frame_delta = tbl.FrameDelta
@ -344,11 +350,11 @@ local function ProcessAnimations(ent)
animations.ResetEntityBoneMatrix(ent)
if not ent.pac_animations then return end
if not entTbl.pac_animations then return end
local tBuffer = {}
for _, tbl in pairs(ent.pac_animations) do
for _, tbl in pairs(entTbl.pac_animations) do
local iCurFrame = tbl.Frame
local tFrameData = tbl.FrameData[iCurFrame]
local fFrameDelta = tbl.FrameDelta
@ -444,14 +450,17 @@ local function ProcessAnimations(ent)
end
for iBoneID, mMatrix in pairs(tBuffer) do
pac.SetEntityBoneMatrix(ent, iBoneID, mMatrix)
pac.SetEntityBoneMatrix(ent, iBoneID, mMatrix, entTbl)
end
end
function animations.ResetEntityBoneMatrix(ent, entTbl)
if not entTbl then
entTbl = ent:GetTable()
end
function animations.ResetEntityBoneMatrix(ent)
for i=0, ent:GetBoneCount() - 1 do
pac.ResetEntityBoneMatrix(ent, i)
for i = 0, ent:GetBoneCount() - 1 do
pac.ResetEntityBoneMatrix(ent, i, entTbl)
end
end
@ -654,10 +663,8 @@ function animations.StopAllEntityAnimations(ent, time)
end
hook.Add("Think", "pac_custom_animations", function()
for i,v in ipairs(animations.playing) do
if v.pac_animations then
ProcessAnimations(v)
end
for _, v in ipairs(animations.playing) do
ProcessAnimations(v)
end
end)