mirror of
https://github.com/lifestorm/wnsrc.git
synced 2025-12-18 06:03:47 +03:00
Upload
This commit is contained in:
262
lua/pac3/core/client/parts/model/entity.lua
Normal file
262
lua/pac3/core/client/parts/model/entity.lua
Normal file
@@ -0,0 +1,262 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local pac = pac
|
||||
local Vector = Vector
|
||||
local Angle = Angle
|
||||
|
||||
local BUILDER, PART = pac.PartTemplate("model2")
|
||||
|
||||
PART.FriendlyName = "entity"
|
||||
PART.ClassName = "entity2"
|
||||
PART.Category = "entity"
|
||||
PART.ManualDraw = true
|
||||
PART.HandleModifiersManually = true
|
||||
PART.Icon = 'icon16/brick.png'
|
||||
PART.Group = "entity"
|
||||
PART.is_entity_part = true
|
||||
|
||||
BUILDER:StartStorableVars()
|
||||
:SetPropertyGroup("generic")
|
||||
:PropertyOrder("Name")
|
||||
:PropertyOrder("Hide")
|
||||
:PropertyOrder("ParentName")
|
||||
:SetPropertyGroup("appearance")
|
||||
:GetSet("NoDraw", false)
|
||||
:GetSet("DrawShadow", true)
|
||||
:GetSet("InverseKinematics", true)
|
||||
|
||||
:SetPropertyGroup("hull")
|
||||
:GetSet("StandingHullHeight", 72, {editor_panel = "hull"})
|
||||
:GetSet("CrouchingHullHeight", 36, {editor_panel = "hull", crouch = true})
|
||||
:GetSet("HullWidth", 32, {editor_panel = "hull"})
|
||||
:EndStorableVars()
|
||||
|
||||
BUILDER:RemoveProperty("BoneMerge")
|
||||
BUILDER:RemoveProperty("Bone")
|
||||
BUILDER:RemoveProperty("EyeAngles")
|
||||
BUILDER:RemoveProperty("AimPartName")
|
||||
BUILDER:RemoveProperty("ForceObjUrl")
|
||||
|
||||
function PART:SetDrawShadow(b)
|
||||
self.DrawShadow = b
|
||||
|
||||
local ent = self:GetOwner()
|
||||
if not ent:IsValid() then return end
|
||||
|
||||
ent:DrawShadow(b)
|
||||
ent:MarkShadowAsDirty()
|
||||
end
|
||||
|
||||
function PART:SetStandingHullHeight(val)
|
||||
self.StandingHullHeight = val
|
||||
self:ApplyMatrix()
|
||||
end
|
||||
function PART:SetCrouchingHullHeight(val)
|
||||
self.CrouchingHullHeight = val
|
||||
self:ApplyMatrix()
|
||||
end
|
||||
function PART:SetHullWidth(val)
|
||||
self.HullWidth = val
|
||||
self:ApplyMatrix()
|
||||
end
|
||||
|
||||
function PART:GetNiceName()
|
||||
local str = pac.PrettifyName(("/" .. self:GetModel()):match(".+/(.-)%.")) or self:GetModel()
|
||||
|
||||
local class_name = "NULL"
|
||||
local ent = self:GetOwner()
|
||||
|
||||
if ent:IsValid() then
|
||||
class_name = ent:GetClass()
|
||||
end
|
||||
|
||||
return (str and str:gsub("%d", "") or "error") .. " " .. class_name .. " model"
|
||||
end
|
||||
|
||||
function PART:SetPosition(pos)
|
||||
self.Position = pos
|
||||
self:ApplyMatrix()
|
||||
end
|
||||
|
||||
function PART:SetAngles(ang)
|
||||
self.Angles = ang
|
||||
self:ApplyMatrix()
|
||||
end
|
||||
|
||||
function PART:SetPositionOffset(pos)
|
||||
self.PositionOffset = pos
|
||||
self:ApplyMatrix()
|
||||
end
|
||||
|
||||
function PART:SetAngleOffset(ang)
|
||||
self.AngleOffset = ang
|
||||
self:ApplyMatrix()
|
||||
end
|
||||
|
||||
function PART:GetBonePosition()
|
||||
local ent = self:GetParentOwner()
|
||||
if not ent:IsValid() then return Vector(), Angle() end
|
||||
local ang = ent:GetAngles()
|
||||
if ent:IsPlayer() then
|
||||
ang.p = 0
|
||||
end
|
||||
return ent:GetPos(), ang
|
||||
end
|
||||
|
||||
-- this also implicitly overrides parent init to not create a custom owner
|
||||
function PART:Initialize()
|
||||
self.material_count = 0
|
||||
end
|
||||
|
||||
function PART:OnDraw()
|
||||
local ent = self:GetOwner()
|
||||
local pos, ang = self:GetDrawPosition()
|
||||
self:PreEntityDraw(ent, pos, ang)
|
||||
self:DrawModel(ent, pos, ang)
|
||||
self:PostEntityDraw(ent, pos, ang)
|
||||
end
|
||||
|
||||
local temp_mat = Material( "models/error/new light1" )
|
||||
|
||||
function PART:RenderOverride(ent)
|
||||
-- if the draw call is not from pac don't bother
|
||||
if not ent.pac_drawing_model then
|
||||
if not ent.pac_is_drawing and ent ~= pac.LocalPlayer and ent.pac_ragdoll_owner ~= pac.LocalPlayer then
|
||||
ent.RenderOverride = nil
|
||||
ent:DisableMatrix("RenderMultiply")
|
||||
ent:SetSkin(0)
|
||||
ent:SetLOD(-1)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
if self:IsValid() and self:GetParentOwner():IsValid() then
|
||||
if ent.pac_bonemerged then
|
||||
for _, e in ipairs(ent.pac_bonemerged) do
|
||||
if e.pac_drawing_model then return end
|
||||
end
|
||||
end
|
||||
|
||||
-- so eyes work
|
||||
if self.NoDraw then
|
||||
if ent == pac.LocalViewModel or ent == pac.LocalHands then return end
|
||||
render.SetBlend(0)
|
||||
render.ModelMaterialOverride(temp_mat)
|
||||
ent.pac_drawing_model = true
|
||||
ent:DrawModel()
|
||||
ent.pac_drawing_model = false
|
||||
render.SetBlend(1)
|
||||
render.ModelMaterialOverride()
|
||||
return
|
||||
end
|
||||
|
||||
ent:SetSkin(self:GetSkin())
|
||||
self:Draw(self.Translucent and "translucent" or "opaque")
|
||||
else
|
||||
ent.RenderOverride = nil
|
||||
end
|
||||
end
|
||||
|
||||
function PART:OnShow()
|
||||
local ent = self:GetOwner()
|
||||
|
||||
if not ent:IsValid() then return end
|
||||
|
||||
function ent.RenderOverride()
|
||||
if self:IsValid() then
|
||||
self:RenderOverride(ent)
|
||||
else
|
||||
ent.RenderOverride = nil
|
||||
end
|
||||
end
|
||||
|
||||
if not self.real_model then
|
||||
self.real_model = ent:GetModel()
|
||||
end
|
||||
|
||||
if not (self.old_model == self:GetModel()) or
|
||||
(pac.LocalHands:IsValid() and ent == pac.LocalHands
|
||||
and not (self.real_model == pac.LocalHands:GetModel())) then
|
||||
self.old_model = self:GetModel()
|
||||
self:SetModel(self:GetModel())
|
||||
end
|
||||
|
||||
self:SetDrawShadow(self:GetDrawShadow())
|
||||
self:RefreshModel()
|
||||
self:ApplyMatrix()
|
||||
end
|
||||
|
||||
function PART:OnHide()
|
||||
local ent = self:GetParentOwner()
|
||||
|
||||
if ent:IsValid() then
|
||||
ent.RenderOverride = nil
|
||||
ent:DisableMatrix("RenderMultiply")
|
||||
ent:SetSkin(0)
|
||||
ent:SetLOD(-1)
|
||||
end
|
||||
end
|
||||
|
||||
function PART:RealSetModel(path)
|
||||
local ent = self:GetOwner()
|
||||
if not ent:IsValid() then return end
|
||||
|
||||
ent:SetModel(path)
|
||||
self.real_model = path
|
||||
self:RefreshModel()
|
||||
end
|
||||
|
||||
function PART:OnRemove()
|
||||
local ent = self:GetOwner()
|
||||
if not ent:IsValid() then return end
|
||||
|
||||
local player_owner = self:GetPlayerOwner()
|
||||
|
||||
pac.emut.RestoreMutations(player_owner, "model", ent)
|
||||
|
||||
if ent:IsPlayer() or ent:IsNPC() then
|
||||
pac.emut.RestoreMutations(player_owner, "size", ent)
|
||||
end
|
||||
|
||||
ent:DisableMatrix("RenderMultiply")
|
||||
end
|
||||
|
||||
function PART:SetInverseKinematics(b)
|
||||
self.InverseKinematics = b
|
||||
|
||||
local ent = self:GetParentOwner()
|
||||
|
||||
if ent:IsValid() then
|
||||
ent.pac_enable_ik = b
|
||||
self:ApplyMatrix()
|
||||
end
|
||||
end
|
||||
|
||||
function PART:OnThink()
|
||||
self:CheckBoneMerge()
|
||||
|
||||
local ent = self:GetOwner()
|
||||
|
||||
if ent:IsValid() then
|
||||
local model = ent:GetModel()
|
||||
local bone_count = ent:GetBoneCount()
|
||||
if
|
||||
self.last_model ~= model or
|
||||
self.last_bone_count ~= bone_count
|
||||
then
|
||||
self:RefreshModel()
|
||||
self.last_model = model
|
||||
self.last_bone_count = bone_count
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
BUILDER:Register()
|
||||
171
lua/pac3/core/client/parts/model/weapon.lua
Normal file
171
lua/pac3/core/client/parts/model/weapon.lua
Normal file
@@ -0,0 +1,171 @@
|
||||
--[[
|
||||
| This file was obtained through the combined efforts
|
||||
| of Madbluntz & Plymouth Antiquarian Society.
|
||||
|
|
||||
| Credits: lifestorm, Gregory Wayne Rossel JR.,
|
||||
| Maloy, DrPepper10 @ RIP, Atle!
|
||||
|
|
||||
| Visit for more: https://plymouth.thetwilightzone.ru/
|
||||
--]]
|
||||
|
||||
local pac = pac
|
||||
local NULL = NULL
|
||||
|
||||
local BUILDER, PART = pac.PartTemplate("model2")
|
||||
|
||||
PART.ClassName = "weapon"
|
||||
PART.FriendlyName = "weapon"
|
||||
PART.Category = "entity"
|
||||
PART.ManualDraw = true
|
||||
PART.HandleModifiersManually = true
|
||||
PART.Icon = 'icon16/brick.png'
|
||||
PART.Group = "entity"
|
||||
PART.is_model_part = false
|
||||
|
||||
BUILDER:StartStorableVars()
|
||||
:SetPropertyGroup("generic")
|
||||
:PropertyOrder("Name")
|
||||
:PropertyOrder("Hide")
|
||||
:PropertyOrder("ParentName")
|
||||
:GetSet("OverridePosition", false)
|
||||
:GetSet("Class", "all", {enums = function()
|
||||
local out = {
|
||||
["physgun"] = "weapon_physgun",
|
||||
["357"] = "weapon_357",
|
||||
["alyxgun"] = "weapon_alyxgun",
|
||||
["annabelle"] = "weapon_annabelle",
|
||||
["ar2"] = "weapon_ar2",
|
||||
["brickbat"] = "weapon_brickbat",
|
||||
["bugbait"] = "weapon_bugbait",
|
||||
["crossbow"] = "weapon_crossbow",
|
||||
["crowbar"] = "weapon_crowbar",
|
||||
["frag"] = "weapon_frag",
|
||||
["physcannon"] = "weapon_physcannon",
|
||||
["pistol"] = "weapon_pistol",
|
||||
["rpg"] = "weapon_rpg",
|
||||
["shotgun"] = "weapon_shotgun",
|
||||
["smg1"] = "weapon_smg1",
|
||||
["striderbuster"] = "weapon_striderbuster",
|
||||
["stunstick"] = "weapon_stunstick",
|
||||
}
|
||||
for _, tbl in pairs(weapons.GetList()) do
|
||||
if not tbl.ClassName:StartWith("ai_") then
|
||||
local friendly = tbl.ClassName:match("weapon_(.+)") or tbl.ClassName
|
||||
out[friendly] = tbl.ClassName
|
||||
end
|
||||
end
|
||||
return out
|
||||
end})
|
||||
:SetPropertyGroup("appearance")
|
||||
:GetSet("NoDraw", false)
|
||||
:GetSet("DrawShadow", true)
|
||||
:SetPropertyGroup("orientation")
|
||||
:GetSet("Bone", "right hand")
|
||||
:EndStorableVars()
|
||||
|
||||
BUILDER:RemoveProperty("Model")
|
||||
BUILDER:RemoveProperty("ForceObjUrl")
|
||||
|
||||
function PART:SetDrawShadow(b)
|
||||
self.DrawShadow = b
|
||||
|
||||
local ent = self:GetOwner()
|
||||
if not ent:IsValid() then return end
|
||||
|
||||
ent:DrawShadow(b)
|
||||
ent:MarkShadowAsDirty()
|
||||
end
|
||||
|
||||
function PART:GetNiceName()
|
||||
if self.Class ~= "all" then
|
||||
return self.Class
|
||||
end
|
||||
return self.ClassName
|
||||
end
|
||||
|
||||
function PART:Initialize()
|
||||
self.material_count = 0
|
||||
end
|
||||
function PART:OnDraw()
|
||||
local ent = self:GetOwner()
|
||||
if not ent:IsValid() then return end
|
||||
local pos, ang = self:GetDrawPosition()
|
||||
|
||||
local old
|
||||
if self.OverridePosition then
|
||||
old = ent:GetParent()
|
||||
ent:SetParent(NULL)
|
||||
ent:SetPos(pos)
|
||||
ent:SetAngles(ang)
|
||||
pac.SetupBones(ent)
|
||||
end
|
||||
ent.pac_render = true
|
||||
|
||||
self:PreEntityDraw(ent, pos, ang)
|
||||
self:DrawModel(ent, pos, ang)
|
||||
self:PostEntityDraw(ent, pos, ang)
|
||||
pac.ResetBones(ent)
|
||||
|
||||
if self.OverridePosition then
|
||||
ent:MarkShadowAsDirty()
|
||||
ent:SetParent(old)
|
||||
end
|
||||
ent.pac_render = nil
|
||||
end
|
||||
|
||||
PART.AlwaysThink = true
|
||||
|
||||
function PART:OnThink()
|
||||
local ent = self:GetRootPart():GetOwner()
|
||||
if ent:IsValid() and ent.GetActiveWeapon then
|
||||
local wep = ent:GetActiveWeapon()
|
||||
if wep:IsValid() then
|
||||
if wep ~= self.Owner then
|
||||
if self.Class == "all" or (self.Class:lower() == wep:GetClass():lower()) then
|
||||
self:OnHide()
|
||||
self.Owner = wep
|
||||
self:SetEventTrigger(self, false)
|
||||
wep.RenderOverride = function()
|
||||
if self:IsHiddenCached() then
|
||||
wep.RenderOverride = nil
|
||||
return
|
||||
end
|
||||
if wep.pac_render then
|
||||
if not self.NoDraw then
|
||||
if self.DrawShadow then
|
||||
wep:CreateShadow()
|
||||
end
|
||||
wep:DrawModel()
|
||||
end
|
||||
end
|
||||
end
|
||||
wep.pac_weapon_part = self
|
||||
self:SetDrawShadow(self:GetDrawShadow())
|
||||
else
|
||||
self:SetEventTrigger(self, true)
|
||||
self:OnHide()
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function PART:OnShow(from_rendering)
|
||||
self.Owner = NULL
|
||||
end
|
||||
|
||||
function PART:OnHide()
|
||||
local ent = self:GetRootPart():GetOwner()
|
||||
|
||||
if ent:IsValid() and ent.GetActiveWeapon then
|
||||
for _, wep in pairs(ent:GetWeapons()) do
|
||||
if wep.pac_weapon_part == self then
|
||||
wep.RenderOverride = nil
|
||||
wep:SetParent(ent)
|
||||
end
|
||||
end
|
||||
self.Owner = NULL
|
||||
end
|
||||
end
|
||||
|
||||
BUILDER:Register()
|
||||
Reference in New Issue
Block a user