Залив
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default"
|
||||
ATTACHMENT.Category = "Accessories"
|
||||
ATTACHMENT.CosmeticChange = true
|
||||
@@ -0,0 +1,5 @@
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default Ammo"
|
||||
ATTACHMENT.Category = "Ammo"
|
||||
function ATTACHMENT:OnImpact(weapon, dmgInfo, tr)
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default"
|
||||
ATTACHMENT.Category = "Arms"
|
||||
@@ -0,0 +1,3 @@
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default"
|
||||
ATTACHMENT.Category = "Arrows"
|
||||
@@ -0,0 +1,3 @@
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default Barrel"
|
||||
ATTACHMENT.Category = "Barrels"
|
||||
84
lua/weapons/mg_base/modules/attachmentss/base/att_base.lua
Normal file
84
lua/weapons/mg_base/modules/attachmentss/base/att_base.lua
Normal file
@@ -0,0 +1,84 @@
|
||||
ATTACHMENT.Name = "Attachment"
|
||||
ATTACHMENT.Category = "Attachments"
|
||||
ATTACHMENT.Icon = Material("mg/genericattachment")
|
||||
ATTACHMENT.RenderOverride = false
|
||||
ATTACHMENT.ShowOnWorldModel = true
|
||||
function ATTACHMENT:Render(weapon)
|
||||
if (self == weapon.bipod) then
|
||||
if (IsValid(self.m_Model)) then
|
||||
self.m_Model:SetPoseParameter("bipod", weapon:HasFlag("BipodDeployed") && 1 || 0)
|
||||
end
|
||||
|
||||
if (IsValid(self.m_TpModel)) then
|
||||
self.m_TpModel:SetPoseParameter("bipod", weapon:HasFlag("BipodDeployed") && 1 || 0)
|
||||
end
|
||||
end
|
||||
end
|
||||
function ATTACHMENT:Stats(weapon)
|
||||
end
|
||||
function ATTACHMENT:PostProcess(weapon)
|
||||
end
|
||||
function ATTACHMENT:Appearance(model, category)
|
||||
end
|
||||
function ATTACHMENT:Init(weapon)
|
||||
end
|
||||
function ATTACHMENT:PostInitModels(weapon)
|
||||
end
|
||||
function ATTACHMENT:OnRemove(weapon)
|
||||
if (CLIENT) then
|
||||
if (IsValid(self.m_Model)) then
|
||||
self.m_Model:Remove()
|
||||
end
|
||||
|
||||
if (IsValid(self.m_TpModel)) then
|
||||
self.m_TpModel:Remove()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
--new functionality to replace materials in model
|
||||
--if returned path + mat doesn't exist on disk, default material will be applied
|
||||
function ATTACHMENT:OverrideMaterial(path, mat)
|
||||
return path, mat
|
||||
end
|
||||
|
||||
--new functionality to replace materials in weapon (viewmodel / worldmodel)
|
||||
--if returned path + mat doesn't exist on disk, default material will be applied
|
||||
function ATTACHMENT:OverrideWeaponMaterial(path, mat)
|
||||
return path, mat
|
||||
end
|
||||
|
||||
--new functionality to replace materials in other attachments
|
||||
--if returned path + mat doesn't exist on disk, default material will be applied
|
||||
function ATTACHMENT:OverrideAttachmentsMaterial(path, mat)
|
||||
return path, mat
|
||||
end
|
||||
|
||||
--playermodel color support for attachment model!
|
||||
function ATTACHMENT:EnablePlayerColor(weapon)
|
||||
if (CLIENT) then
|
||||
if (IsValid(self.m_Model)) then
|
||||
self.m_Model.plyColor = Vector()
|
||||
|
||||
function self.m_Model:GetPlayerColor()
|
||||
if (IsValid(weapon) && IsValid(weapon:GetOwner()) && weapon:GetOwner().GetPlayerColor != nil) then
|
||||
self.plyColor = weapon:GetOwner():GetPlayerColor()
|
||||
end
|
||||
|
||||
return self.plyColor
|
||||
end
|
||||
end
|
||||
|
||||
if (IsValid(self.m_TpModel)) then
|
||||
self.m_TpModel.plyColor = Vector()
|
||||
|
||||
function self.m_TpModel:GetPlayerColor()
|
||||
if (IsValid(weapon) && IsValid(weapon:GetOwner()) && weapon:GetOwner().GetPlayerColor != nil) then
|
||||
self.plyColor = weapon:GetOwner():GetPlayerColor()
|
||||
end
|
||||
|
||||
return self.plyColor
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default"
|
||||
ATTACHMENT.Category = "Bolts"
|
||||
100
lua/weapons/mg_base/modules/attachmentss/base/att_conversion.lua
Normal file
100
lua/weapons/mg_base/modules/attachmentss/base/att_conversion.lua
Normal file
@@ -0,0 +1,100 @@
|
||||
require("mw_utils")
|
||||
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default"
|
||||
ATTACHMENT.Category = "Conversions"
|
||||
|
||||
--[[
|
||||
you likely noticed this is just a glorified attachment, so everything that works for other types works
|
||||
here as well (bodygroups, model, etc etc)
|
||||
structure of a typical conversion goes like this:
|
||||
|
||||
--
|
||||
with conversions you completely ditch the original gun's customization slot,
|
||||
which means you gotta provide a default attachment too (the first one)
|
||||
|
||||
ATTACHMENT.Conversion = {
|
||||
[2] = {"att_example1", "att_example2"},
|
||||
[4] = {"att_example3", "att_example4"},
|
||||
[5] = {} <- will remove slot 5
|
||||
}
|
||||
|
||||
! note how i skipped some slots (they are the same ones you use in injectors): if you wish to not replace a slot,
|
||||
you simply omit it !
|
||||
--
|
||||
|
||||
--
|
||||
with replacements you handpick some attachments that change with your conversion
|
||||
|
||||
ATTACHMENT.Replacements = {
|
||||
["att_original_from_swep1"] = "att_your_new_attachment1",
|
||||
["att_original_from_swep2"] = "att_your_new_attachment2"
|
||||
}
|
||||
--
|
||||
|
||||
in injectors, you don't need to specify a slot: base will check if you're trying to add a conversion to the gun.
|
||||
don't worry about it, just let it manage it for you
|
||||
this also means you don't have to inject the attachments you use above manually!! they will still show up
|
||||
if the conversion is trying to load an attachment the player hasn't downloaded it will not get added
|
||||
|
||||
later down the line i plan on adding their own ui to conversions, for now we can live with them just being
|
||||
an attachment button...
|
||||
|
||||
lastly, please remember the philosophy of our customization. are you sure your set needs to be a conversion?
|
||||
if you're able to, consider making it part of the gun instead; don't take customization away from the player.
|
||||
this sytem can easily throw everything out of the window if you're not careful.
|
||||
enjoy~!
|
||||
]]
|
||||
|
||||
local function getSlotAndIndex(cust, originalClass)
|
||||
for slot, atts in pairs(weapon.Customization) do
|
||||
for index, attClass in pairs(atts) do
|
||||
if (attClass == originalClass) then
|
||||
return slot, index
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return -1000, -1000
|
||||
end
|
||||
|
||||
local function stripUnknownAttachments(atts)
|
||||
for i = #atts, 1, -1 do
|
||||
if (MW_ATTS[atts[i]] == nil) then
|
||||
table.remove(atts, i)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local BaseClass = GetAttachmentBaseClass(ATTACHMENT.Base)
|
||||
function ATTACHMENT:Stats(weapon)
|
||||
BaseClass.Stats(self, weapon)
|
||||
|
||||
if (self.Conversion != nil) then
|
||||
for slot, atts in pairs(self.Conversion) do
|
||||
if (slot <= SLOT_CONVERSIONS) then
|
||||
continue
|
||||
end
|
||||
|
||||
if (table.IsEmpty(atts)) then
|
||||
weapon.Customization[slot] = nil
|
||||
continue
|
||||
end
|
||||
|
||||
local strippedAtts = table.Copy(atts)
|
||||
stripUnknownAttachments(strippedAtts)
|
||||
|
||||
weapon.Customization[slot] = strippedAtts
|
||||
end
|
||||
end
|
||||
|
||||
if (self.Replacements != nil) then
|
||||
for originalClass, newClass in pairs(self.Replacements) do
|
||||
local rSlot, rIndex = getSlotAndIndex(weapon.Customization, originalClass)
|
||||
|
||||
if (rSlot > SLOT_CONVERSIONS && rIndex > SLOT_CONVERSIONS && MW_ATTS[newClass] != nil) then
|
||||
weapon.Customization[rSlot][rIndex] = newClass
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default Forend"
|
||||
ATTACHMENT.Category = "Forends"
|
||||
@@ -0,0 +1,7 @@
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default"
|
||||
ATTACHMENT.Category = "Grips"
|
||||
|
||||
function ATTACHMENT:ChangeRecoil(var, mul)
|
||||
return var < 0 && var / mul || var * mul
|
||||
end
|
||||
14
lua/weapons/mg_base/modules/attachmentss/base/att_hybrid.lua
Normal file
14
lua/weapons/mg_base/modules/attachmentss/base/att_hybrid.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
ATTACHMENT.Base = "att_optic"
|
||||
|
||||
local BaseClass = GetAttachmentBaseClass(ATTACHMENT.Base)
|
||||
function ATTACHMENT:Render(weapon)
|
||||
if (weapon:GetAimModeDelta() > 0.3) then
|
||||
self.m_Model:SetBodygroup(
|
||||
self.m_Model:FindBodygroupByName(self.Optic.LensBodygroup),
|
||||
1
|
||||
)
|
||||
self:DoReticleStencil(self.m_Model, self.ReticleHybrid, weapon)
|
||||
else
|
||||
BaseClass.Render(self, weapon)
|
||||
end
|
||||
end
|
||||
154
lua/weapons/mg_base/modules/attachmentss/base/att_laser.lua
Normal file
154
lua/weapons/mg_base/modules/attachmentss/base/att_laser.lua
Normal file
@@ -0,0 +1,154 @@
|
||||
require("mw_math")
|
||||
require("mw_utils")
|
||||
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default"
|
||||
ATTACHMENT.Category = "Lasers"
|
||||
|
||||
local BaseClass = GetAttachmentBaseClass(ATTACHMENT.Base)
|
||||
|
||||
function ATTACHMENT:RemoveFlashlightStuffFromModel(flashModel)
|
||||
if (IsValid(flashModel)) then
|
||||
if (flashModel.mw_flashlightProjTexture != nil) then
|
||||
flashModel.mw_flashlightProjTexture:Remove()
|
||||
end
|
||||
|
||||
if (flashModel.mw_flashlightParticle != nil) then
|
||||
flashModel.mw_flashlightParticle:StopEmissionAndDestroyImmediately()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ATTACHMENT:DoLaserRender(weapon, laserModel)
|
||||
if (IsValid(GetViewEntity())) then
|
||||
if (CurTime() < GetViewEntity():GetNWFloat("MW19_EMPEffect", CurTime())) then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if (self.Laser == nil) then
|
||||
return
|
||||
end
|
||||
|
||||
local att = mw_utils.GetFastAttachment(laserModel, self.Laser.Attachment)
|
||||
|
||||
local tr = util.TraceLine({
|
||||
start = att.Pos + att.Ang:Forward() * -10,
|
||||
endpos = att.Pos + att.Ang:Forward() * 1000,
|
||||
filter = {weapon, weapon:GetOwner()},
|
||||
mask = MASK_SHOT
|
||||
})
|
||||
|
||||
if (laserModel.mw_laserTrailPos == nil) then
|
||||
laserModel.mw_laserTrailPos = tr.HitPos
|
||||
end
|
||||
|
||||
local distSq = tr.HitPos:DistToSqr(att.Pos)
|
||||
local beamDelta = math.Clamp(distSq / ((self.Laser.BeamSize * 5) * (self.Laser.BeamSize * 5)), 0, 1)
|
||||
|
||||
local color = self.Laser.Color
|
||||
|
||||
if (GetConVar("mgbase_fx_laser_weaponcolor", 0):GetBool()) then
|
||||
if (IsValid(weapon:GetOwner()) && weapon:GetOwner():IsPlayer()) then
|
||||
local c = weapon:GetOwner():GetWeaponColor()
|
||||
color = Color(c.x * 255, c.y * 255, c.z * 255, 255)
|
||||
end
|
||||
end
|
||||
|
||||
local pos = tr.HitPos * 1
|
||||
|
||||
if (weapon:GetSight() == nil || weapon:GetSight().ReticleHybrid == nil) then
|
||||
mw_math.SafeLerpVector((weapon:GetAimDelta() * 0.8) * weapon:GetAimModeDelta(), pos, EyePos() + EyeAngles():Forward() * 300)
|
||||
end
|
||||
|
||||
render.SetMaterial(self.Laser.BeamMaterial)
|
||||
render.DrawBeam(att.Pos, pos, self.Laser.BeamWidth * math.random(0.5, 1), 0, 1, color)
|
||||
|
||||
local normal = tr.HitNormal * 1
|
||||
mw_math.SafeLerpVector(weapon:GetAimDelta(), normal, (EyePos() - pos):GetNormalized())
|
||||
|
||||
local sens = Lerp(weapon:GetAimDelta(), 50, 150)
|
||||
mw_math.SafeLerpVector(math.min(sens * FrameTime(), 1), laserModel.mw_laserTrailPos, pos)
|
||||
|
||||
local bCanDrawDistance = tr.HitPos:DistToSqr(att.Pos) > (10 * 10)
|
||||
|
||||
if (!bCanDrawDistance) then
|
||||
return
|
||||
end
|
||||
|
||||
render.SetMaterial(self.Laser.DotMaterial)
|
||||
render.DrawQuadEasy(pos, normal, self.Laser.DotSize, self.Laser.DotSize, color, math.random(179, 180))
|
||||
render.DrawBeam(laserModel.mw_laserTrailPos, pos, self.Laser.DotSize * 0.8, 0, 0.5, color)
|
||||
end
|
||||
|
||||
function ATTACHMENT:DrawFlashlight(weapon, model)
|
||||
if (IsValid(GetViewEntity())) then
|
||||
if (CurTime() < GetViewEntity():GetNWFloat("MW19_EMPEffect", CurTime())) then
|
||||
self:RemoveFlashlightStuffFromModel(model)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
if (self.Flashlight == nil) then
|
||||
return
|
||||
end
|
||||
|
||||
if (!weapon:HasFlag("FlashlightOn") || weapon:GetOwner():FlashlightIsOn() || weapon:HasFlag("Holstering")) then
|
||||
self:RemoveFlashlightStuffFromModel(model)
|
||||
return
|
||||
end
|
||||
|
||||
local att = mw_utils.GetFastAttachment(model, self.Flashlight.Attachment)
|
||||
|
||||
if (!IsValid(model.mw_flashlightParticle)) then
|
||||
model.mw_flashlightParticle = CreateParticleSystem(model, "flashlight_mw19", PATTACH_POINT_FOLLOW, mw_utils.LookupAttachmentCached(model, self.Flashlight.Attachment))
|
||||
model.mw_flashlightParticle:StartEmission()
|
||||
model.mw_flashlightParticle:SetShouldDraw(false)
|
||||
model.mw_flashlightParticle:SetIsViewModelEffect(model == self.m_Model)
|
||||
end
|
||||
|
||||
local particle = model.mw_flashlightParticle
|
||||
particle:SetControlPoint(1, att.Pos)
|
||||
particle:SetControlPointOrientation(1, att.Ang:Forward(), att.Ang:Right(), att.Ang:Up())
|
||||
particle:Render()
|
||||
|
||||
if (!IsValid(model.mw_flashlightProjTexture)) then
|
||||
model.mw_flashlightProjTexture = ProjectedTexture()
|
||||
model.mw_flashlightProjTexture:SetFOV(50)
|
||||
model.mw_flashlightProjTexture:SetTexture(self.Flashlight.FlashlightMaterial:GetTexture("$basetexture"))
|
||||
end
|
||||
|
||||
local proj = model.mw_flashlightProjTexture
|
||||
proj:SetPos(att.Pos + att.Ang:Forward() * -3)
|
||||
proj:SetAngles(att.Ang)
|
||||
proj:Update()
|
||||
end
|
||||
|
||||
local bDrewViewModel = false
|
||||
|
||||
function ATTACHMENT:Render(weapon, model)
|
||||
BaseClass.Render(self, weapon)
|
||||
|
||||
self:DoLaserRender(weapon, model)
|
||||
|
||||
if (model == self.m_Model) then
|
||||
self:DrawFlashlight(weapon, model)
|
||||
bDrewViewModel = true
|
||||
end
|
||||
|
||||
if (model == self.m_TpModel) then
|
||||
if (!bDrewViewModel) then
|
||||
self:RemoveFlashlightStuffFromModel(self.m_Model)
|
||||
end
|
||||
bDrewViewModel = false
|
||||
end
|
||||
end
|
||||
|
||||
function ATTACHMENT:OnRemove(weapon)
|
||||
if (CLIENT) then
|
||||
self:RemoveFlashlightStuffFromModel(self.m_Model)
|
||||
self:RemoveFlashlightStuffFromModel(self.m_TpModel)
|
||||
end
|
||||
|
||||
BaseClass.OnRemove(self, weapon)
|
||||
end
|
||||
127
lua/weapons/mg_base/modules/attachmentss/base/att_magazine.lua
Normal file
127
lua/weapons/mg_base/modules/attachmentss/base/att_magazine.lua
Normal file
@@ -0,0 +1,127 @@
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default Magazine"
|
||||
ATTACHMENT.Category = "Magazines"
|
||||
|
||||
--for gameplay mag
|
||||
ATTACHMENT.BulletList = {}
|
||||
|
||||
--for animation mag (offhand)
|
||||
ATTACHMENT.ReserveBulletList = {}
|
||||
|
||||
ATTACHMENT.PoseParameter = "bullets_offset" --the spring
|
||||
|
||||
local small = Vector()
|
||||
local normal = Vector(1, 1, 1)
|
||||
|
||||
local BaseClass = GetAttachmentBaseClass(ATTACHMENT.Base)
|
||||
|
||||
function ATTACHMENT:SetMagFollowerPoseParam(weapon, val)
|
||||
local ppid = self.m_Model:LookupPoseParameter(self.PoseParameter)
|
||||
if (ppid >= 0) then
|
||||
local min, max = self.m_Model:GetPoseParameterRange(ppid)
|
||||
self.m_Model:SetPoseParameter(self.PoseParameter, math.Clamp(val, min, max))
|
||||
--self.m_Model:InvalidateBoneCache()
|
||||
end
|
||||
end
|
||||
|
||||
function ATTACHMENT:Render(weapon)
|
||||
BaseClass.Render(self, weapon)
|
||||
|
||||
if (!weapon:IsCarriedByLocalPlayer()) then
|
||||
return
|
||||
end
|
||||
|
||||
if (!weapon:HasFlag("Reloading")) then
|
||||
self.m_Model._clip = weapon:Clip1()
|
||||
self.m_Model._ammo = weapon:Ammo1()
|
||||
self:SetMagFollowerPoseParam(weapon, weapon:GetMaxClip1() - weapon:Clip1())
|
||||
end
|
||||
end
|
||||
|
||||
local function cacheBones(model, bones)
|
||||
for _, name in pairs(bones) do
|
||||
model.cachedBones[name] = {id = model:LookupBone(name), remove = false}
|
||||
end
|
||||
end
|
||||
|
||||
function ATTACHMENT:PostInitModels(weapon)
|
||||
BaseClass.PostInitModels(self, weapon)
|
||||
|
||||
if (SERVER) then
|
||||
return
|
||||
end
|
||||
|
||||
if (table.IsEmpty(self.BulletList) && table.IsEmpty(self.ReserveBulletList)) then
|
||||
return
|
||||
end
|
||||
|
||||
self.m_Model._requestedReset = false
|
||||
self.m_Model._clip = -1
|
||||
self.m_Model._lastClip = -1
|
||||
self.m_Model._ammo = -1
|
||||
self.m_Model._lastAmmo = -1
|
||||
self.m_Model.BulletList = table.Copy(self.BulletList)
|
||||
self.m_Model.ReserveBulletList = table.Copy(self.ReserveBulletList)
|
||||
|
||||
self.m_Model:SetupBones()
|
||||
self.m_Model.cachedBones = {}
|
||||
for _, bones in pairs(self.m_Model.BulletList) do
|
||||
cacheBones(self.m_Model, bones)
|
||||
end
|
||||
|
||||
for _, bones in pairs(self.m_Model.ReserveBulletList) do
|
||||
cacheBones(self.m_Model, bones)
|
||||
end
|
||||
|
||||
self.m_Model:AddCallback("BuildBonePositions", function(ent, numbones)
|
||||
local function scaleBones(ent, bones, bRemove)
|
||||
for i, bone in pairs(bones) do
|
||||
ent.cachedBones[bone].remove = bRemove
|
||||
end
|
||||
end
|
||||
|
||||
if (ent._lastClip != ent._clip) then
|
||||
for i, bones in pairs(ent.BulletList) do
|
||||
scaleBones(ent, bones, ent._clip <= i)
|
||||
end
|
||||
|
||||
ent._lastClip = ent._clip
|
||||
end
|
||||
|
||||
if (ent._lastAmmo != ent._ammo + ent._clip) then
|
||||
for i, bones in pairs(ent.ReserveBulletList) do
|
||||
scaleBones(ent, bones, weapon:Clip1() + weapon:Ammo1() < i)
|
||||
end
|
||||
|
||||
ent._lastAmmo = ent._ammo + ent._clip
|
||||
end
|
||||
|
||||
if (ent._requestedReset) then
|
||||
for i, bones in pairs(ent.BulletList) do
|
||||
scaleBones(ent, bones, weapon:Clip1() + weapon:Ammo1() < i)
|
||||
end
|
||||
|
||||
ent._requestedReset = false
|
||||
end
|
||||
|
||||
for name, boneStuff in pairs(ent.cachedBones) do
|
||||
if (!boneStuff.remove) then
|
||||
continue
|
||||
end
|
||||
|
||||
local mat = ent:GetBoneMatrix(boneStuff.id)
|
||||
|
||||
if (mat == nil) then
|
||||
continue
|
||||
end
|
||||
|
||||
mat:SetScale(small)
|
||||
ent:SetBoneMatrix(boneStuff.id, mat)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
function ATTACHMENT:ResetBullets(weapon)
|
||||
self.m_Model._requestedReset = true
|
||||
self:SetMagFollowerPoseParam(weapon, weapon:GetMaxClip1() - (weapon:Clip1() + weapon:Ammo1()))
|
||||
end
|
||||
@@ -0,0 +1,55 @@
|
||||
--Class for VElements that have two magazines in their animations
|
||||
require("mw_utils")
|
||||
ATTACHMENT.Base = "att_magazine"
|
||||
|
||||
ATTACHMENT.VElement2 = {
|
||||
Bone = "j_mag2",
|
||||
Position = Vector(),
|
||||
Angles = Angle(),
|
||||
Offsets = {}
|
||||
}
|
||||
|
||||
local BaseClass = GetAttachmentBaseClass(ATTACHMENT.Base)
|
||||
|
||||
function ATTACHMENT:Init(weapon)
|
||||
BaseClass.Init(self, weapon)
|
||||
|
||||
if (CLIENT) then
|
||||
self.m_Model2 = ClientsideModel(self.Model, weapon.RenderGroup)
|
||||
self.m_Model2:SetRenderMode(weapon.RenderMode)
|
||||
self.m_Model2:SetMoveType(MOVETYPE_NONE)
|
||||
self.m_Model2:SetOwner(weapon:GetViewModel())
|
||||
self.m_Model2.bAttachmentRenderOverride = self.RenderOverride
|
||||
|
||||
self.m_Model2:FollowBone(weapon:GetViewModel(), mw_utils.LookupBoneCached(weapon:GetViewModel(), self.VElement2.Bone))
|
||||
|
||||
--hack to move element
|
||||
local oldve = table.Copy(self.VElement)
|
||||
local oldModel = self.m_Model
|
||||
|
||||
self.VElement = table.Copy(self.VElement2)
|
||||
self.m_Model = self.m_Model2
|
||||
weapon:MoveVElement(weapon:GetViewModel(), self)
|
||||
|
||||
self.VElement = oldve
|
||||
self.m_Model = oldModel
|
||||
end
|
||||
end
|
||||
|
||||
function ATTACHMENT:OnRemove(weapon)
|
||||
BaseClass.OnRemove(self, weapon)
|
||||
|
||||
if (CLIENT) then
|
||||
if (IsValid(self.m_Model2)) then
|
||||
self.m_Model2:Remove()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function ATTACHMENT:Render(weapon)
|
||||
BaseClass.Render(self, weapon)
|
||||
|
||||
if (IsValid(self.m_Model2)) then
|
||||
-- self.m_Model2:DrawModel()
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,4 @@
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default"
|
||||
ATTACHMENT.Category = "Misc"
|
||||
ATTACHMENT.CosmeticChange = true
|
||||
@@ -0,0 +1,3 @@
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default"
|
||||
ATTACHMENT.Category = "Muzzle Devices"
|
||||
269
lua/weapons/mg_base/modules/attachmentss/base/att_optic.lua
Normal file
269
lua/weapons/mg_base/modules/attachmentss/base/att_optic.lua
Normal file
@@ -0,0 +1,269 @@
|
||||
require("mw_utils")
|
||||
ATTACHMENT.Base = "att_sight_reticle"
|
||||
|
||||
if (SERVER) then
|
||||
return
|
||||
end
|
||||
|
||||
ATTACHMENT._RTTexture = GetRenderTarget("mw19_rt", 512, 512)
|
||||
|
||||
local BaseClass = GetAttachmentBaseClass(ATTACHMENT.Base)
|
||||
local ParallaxMaterial = Material("mw19_parallax.vmt")
|
||||
local RefractMaterial = Material("mw19_scoperefract.vmt")
|
||||
local RefractTintMaterial = Material("mw19_refracttint.vmt")
|
||||
local FishEyeMaterial = Material("mw_fisheyelens")
|
||||
|
||||
local function util_NormalizeAngles(a)
|
||||
a.p = math.NormalizeAngle(a.p)
|
||||
a.y = math.NormalizeAngle(a.y)
|
||||
a.r = math.NormalizeAngle(a.r)
|
||||
return a
|
||||
end
|
||||
|
||||
function ATTACHMENT:Init(weapon)
|
||||
BaseClass.Init(self, weapon)
|
||||
|
||||
self.hideModel = ClientsideModel(self.Optic.HideModel, weapon.RenderGroup)
|
||||
self.hideModel:SetMoveType(MOVETYPE_NONE)
|
||||
self.hideModel:SetNoDraw(true)
|
||||
end
|
||||
|
||||
function ATTACHMENT:OnRemove(weapon)
|
||||
BaseClass.OnRemove(self, weapon)
|
||||
|
||||
if (IsValid(self.hideModel)) then
|
||||
self.hideModel:Remove()
|
||||
end
|
||||
end
|
||||
|
||||
--https://github.com/Lexicality/stencil-tutorial/blob/master/lua/stencil_tutorial/06_cutting_holes_in_props.lua
|
||||
function ATTACHMENT:Render(weapon, model)
|
||||
|
||||
local bCanRemoveBodygroup = weapon:GetAimModeDelta() < 0.5 && weapon:GetAimDelta() > 0.9
|
||||
|
||||
self.m_Model:SetBodygroup(
|
||||
self.m_Model:FindBodygroupByName(self.Optic.LensBodygroup),
|
||||
bCanRemoveBodygroup && 0 || 1
|
||||
)
|
||||
|
||||
if (!bCanRemoveBodygroup) then
|
||||
self.m_Model:DrawModel()
|
||||
|
||||
if (!self.m_bRemovedRT) then
|
||||
render.PushRenderTarget(self._RTTexture, 0, 0, 1024, 1024)
|
||||
render.PopRenderTarget()
|
||||
self.Optic.LensHideMaterial:SetTexture("$basetexture", self._RTTexture)
|
||||
self.m_bRemovedRT = true
|
||||
end
|
||||
|
||||
return
|
||||
end
|
||||
|
||||
self.m_bRemovedRT = false
|
||||
|
||||
render.SetStencilWriteMask(0xFF)
|
||||
render.SetStencilTestMask(0xFF)
|
||||
render.SetStencilReferenceValue(0)
|
||||
render.SetStencilPassOperation(STENCIL_KEEP)
|
||||
render.SetStencilZFailOperation(STENCIL_KEEP)
|
||||
render.ClearStencil()
|
||||
render.SetStencilEnable(true)
|
||||
render.SetStencilReferenceValue(MWBASE_STENCIL_REFVALUE + 2)
|
||||
render.SetStencilCompareFunction(STENCIL_NEVER)
|
||||
render.SetStencilFailOperation(STENCIL_REPLACE)
|
||||
|
||||
--dirty and quick way to make it work with velements and bonemerged
|
||||
self.m_Model:SetupBones()
|
||||
self.m_Model:InvalidateBoneCache()
|
||||
local matrix = self.m_Model:GetBoneMatrix(0)
|
||||
|
||||
self.hideModel:SetPos(matrix:GetTranslation())
|
||||
self.hideModel:SetAngles(matrix:GetAngles())
|
||||
|
||||
self.hideModel:DrawModel()
|
||||
|
||||
render.SetStencilCompareFunction(STENCIL_NOTEQUAL)
|
||||
render.SetStencilFailOperation(STENCIL_KEEP)
|
||||
|
||||
self.m_Model:DrawModel()
|
||||
|
||||
render.SetStencilCompareFunction(STENCIL_EQUAL)
|
||||
render.SetStencilFailOperation(STENCIL_KEEP)
|
||||
|
||||
if (self.Optic.Thermal) then
|
||||
self:DrawThermal(weapon)
|
||||
end
|
||||
|
||||
render.SetStencilEnable(false)
|
||||
render.ClearStencil()
|
||||
|
||||
------------------------------
|
||||
|
||||
self:DoReticleStencil(self.hideModel, self.Reticle, weapon)
|
||||
|
||||
------------------------------
|
||||
|
||||
local att = mw_utils.GetFastAttachment(self.m_Model, self.Reticle.Attachment)
|
||||
|
||||
render.PushRenderTarget(self._RTTexture, 0, 0, 1024, 1024)
|
||||
cam.Start2D()
|
||||
render.Clear(0, 0, 0, 0)
|
||||
--REFTINT:
|
||||
local tintSize = 400
|
||||
surface.SetMaterial(RefractTintMaterial)
|
||||
surface.SetDrawColor(0, 0, 0, 255)
|
||||
--for i = 1, 2, 1 do
|
||||
surface.DrawTexturedRect(tintSize * -0.5, tintSize * -0.5, ScrW() + tintSize, ScrH() + tintSize)
|
||||
--end
|
||||
--[[render.SetMaterial(FishEyeMaterial)
|
||||
render.UpdateScreenEffectTexture()
|
||||
render.DrawScreenQuad()]]
|
||||
|
||||
----
|
||||
if (!self.Optic.Thermal) then
|
||||
self:DrawParallax(weapon, att.Ang)
|
||||
end
|
||||
cam.End2D()
|
||||
render.PopRenderTarget()
|
||||
self.Optic.LensHideMaterial:SetTexture("$basetexture", self._RTTexture)
|
||||
end
|
||||
|
||||
local thermalCC = {
|
||||
[ "$pp_colour_addr" ] = 0,
|
||||
[ "$pp_colour_addg" ] = 0,
|
||||
[ "$pp_colour_addb" ] = 0,
|
||||
[ "$pp_colour_brightness" ] = 1.54,
|
||||
[ "$pp_colour_contrast" ] = 0.1,
|
||||
[ "$pp_colour_colour" ] = 0,
|
||||
[ "$pp_colour_mulr" ] = 0,
|
||||
[ "$pp_colour_mulg" ] = 0,
|
||||
[ "$pp_colour_mulb" ] = 0
|
||||
}
|
||||
|
||||
local ThermalNoiseMaterial = Material("mw19_thermalnoise.vmt")
|
||||
local sunMaterial = Material("mg/cursorglow")
|
||||
|
||||
local function drawEnt(ent)
|
||||
if (ent:GetNoDraw()) then
|
||||
return
|
||||
end
|
||||
|
||||
ent:DrawModel()
|
||||
end
|
||||
|
||||
function ATTACHMENT:DrawThermal(weapon)
|
||||
--DrawColorModify(thermalCC)
|
||||
|
||||
local backgroundColor = self.Optic.ThermalBackgroundColor || Color(50, 50, 50, 240)
|
||||
local bodyColor = self.Optic.ThermalBodiesColor || Color(255, 255, 255, 150)
|
||||
|
||||
cam.Start2D()
|
||||
surface.SetDrawColor(backgroundColor.r, backgroundColor.g, backgroundColor.b, backgroundColor.a)
|
||||
surface.DrawRect(0, 0, ScrW(), ScrH())
|
||||
|
||||
local sun = util.GetSunInfo()
|
||||
|
||||
if (sun != nil && sun.obstruction > 0) then
|
||||
local pos = EyePos() + sun.direction * 4096
|
||||
pos = pos:ToScreen()
|
||||
local alpha = 255 * sun.obstruction
|
||||
local sunSize = 1024
|
||||
|
||||
surface.SetMaterial(sunMaterial)
|
||||
surface.SetDrawColor(bodyColor.r, bodyColor.g, bodyColor.b, alpha)
|
||||
surface.DrawTexturedRect(pos.x - (sunSize * 0.5), pos.y - (sunSize * 0.5), sunSize, sunSize)
|
||||
end
|
||||
|
||||
surface.SetMaterial(ThermalNoiseMaterial)
|
||||
surface.SetDrawColor(255, 255, 255, 255)
|
||||
surface.DrawTexturedRect(ScrW() * 0.25, ScrH() * 0.25, ScrW() * 0.5, ScrH() * 0.5)
|
||||
cam.End2D()
|
||||
|
||||
render.SetStencilPassOperation(STENCILOPERATION_INCR)
|
||||
|
||||
render.SetBlend(0)
|
||||
if (IsValid(weapon:GetViewModel().m_CHands)) then
|
||||
drawEnt(weapon:GetViewModel().m_CHands)
|
||||
end
|
||||
|
||||
if (IsValid(weapon:GetViewModel().m_Gloves)) then
|
||||
drawEnt(weapon:GetViewModel().m_Gloves)
|
||||
end
|
||||
|
||||
cam.Start3D()
|
||||
for i, e in pairs(ents.GetAll()) do
|
||||
if (e:IsNPC() || e:IsPlayer() || e:IsNextBot()) then
|
||||
if (e:Health() <= 0) then
|
||||
continue
|
||||
end
|
||||
|
||||
drawEnt(e)
|
||||
end
|
||||
end
|
||||
cam.End3D()
|
||||
render.SetBlend(1)
|
||||
|
||||
render.SetStencilCompareFunction(STENCIL_LESS)
|
||||
|
||||
cam.Start2D()
|
||||
surface.SetDrawColor(bodyColor.r, bodyColor.g, bodyColor.b, bodyColor.a)
|
||||
surface.DrawRect(0, 0, ScrW(), ScrH())
|
||||
cam.End2D()
|
||||
|
||||
render.SetStencilEnable(false)
|
||||
render.ClearStencil()
|
||||
end
|
||||
|
||||
function ATTACHMENT:DrawParallax(weapon, ang)
|
||||
ang:Sub(EyeAngles())
|
||||
local angDif = util_NormalizeAngles(ang) * 100
|
||||
render.SetStencilWriteMask(0xFF)
|
||||
render.SetStencilTestMask(0xFF)
|
||||
render.SetStencilReferenceValue(0)
|
||||
render.SetStencilCompareFunction(STENCIL_ALWAYS)
|
||||
render.SetStencilPassOperation(STENCIL_REPLACE)
|
||||
render.SetStencilFailOperation(STENCIL_KEEP)
|
||||
render.SetStencilZFailOperation(STENCIL_KEEP)
|
||||
render.SetStencilEnable(true)
|
||||
render.SetStencilReferenceValue(MWBASE_STENCIL_REFVALUE + 2)
|
||||
|
||||
local pSize = self.Optic.ParallaxSize - (weapon.Camera.Shake * 200)
|
||||
surface.SetMaterial(ParallaxMaterial)
|
||||
surface.SetDrawColor(0, 0, 0, 255)
|
||||
surface.DrawTexturedRect(ScrW() * -0.5 - pSize * 0.5 - angDif.y, ScrH() * -0.5 - pSize * 0.5 + angDif.p, ScrW() * 2 + pSize, ScrH() * 2 + pSize)
|
||||
|
||||
render.SetStencilCompareFunction(STENCIL_NOTEQUAL)
|
||||
|
||||
surface.SetDrawColor(0, 0, 0, 255)
|
||||
surface.DrawRect(0, 0, ScrW(), ScrH())
|
||||
|
||||
render.SetStencilEnable(false)
|
||||
render.ClearStencil()
|
||||
end
|
||||
|
||||
local glintMaterial = Material("sprites/glow04_noz")
|
||||
|
||||
function ATTACHMENT:WorldModelRender(weapon)
|
||||
if (weapon:IsCarriedByLocalPlayer()) then
|
||||
return
|
||||
end
|
||||
|
||||
local pos, ang = self.m_TpModel:GetBonePosition(0)
|
||||
local dot = ang:Forward():Dot(EyeAngles():Forward())
|
||||
|
||||
if (dot > 0) then
|
||||
return
|
||||
end
|
||||
|
||||
local dist = EyePos():Distance(pos)
|
||||
|
||||
if (dist < 1024) then
|
||||
return
|
||||
end
|
||||
|
||||
local sizeFactor = (dist * 0.01)
|
||||
local scale = 6 * (0.5 - weapon.Zoom.FovMultiplier) * sizeFactor
|
||||
local randomSize = math.Rand(0, 2) * sizeFactor
|
||||
render.SetMaterial(glintMaterial)
|
||||
render.DrawSprite(pos + ang:Forward() * 10 + ang:Up() * 2, scale + (randomSize * 2), (scale * 0.5) + randomSize, Color(255, 255, 255, 255))
|
||||
end
|
||||
16
lua/weapons/mg_base/modules/attachmentss/base/att_perk.lua
Normal file
16
lua/weapons/mg_base/modules/attachmentss/base/att_perk.lua
Normal file
@@ -0,0 +1,16 @@
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default"
|
||||
ATTACHMENT.Category = "Perks"
|
||||
|
||||
local BaseClass = GetAttachmentBaseClass(ATTACHMENT.Base)
|
||||
|
||||
function ATTACHMENT:Stats(weapon)
|
||||
BaseClass.Stats(self, weapon)
|
||||
|
||||
if (weapon.Bullet != nil) then
|
||||
weapon.Bullet.Ricochet = false
|
||||
end
|
||||
|
||||
weapon.Zoom.MovementMultiplier = 1
|
||||
weapon.Zoom.BreathingMultiplier = 1
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default Pistol Grip"
|
||||
ATTACHMENT.Category = "Pistol Grips"
|
||||
@@ -0,0 +1,3 @@
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default Pump"
|
||||
ATTACHMENT.Category = "Pumps"
|
||||
@@ -0,0 +1,3 @@
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default Rail"
|
||||
ATTACHMENT.Category = "Rails"
|
||||
@@ -0,0 +1,3 @@
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default Receiver"
|
||||
ATTACHMENT.Category = "Receivers"
|
||||
@@ -0,0 +1,4 @@
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default Sight"
|
||||
ATTACHMENT.Category = "Sights"
|
||||
ATTACHMENT.BonemergeToCategory = {"Receivers"}
|
||||
@@ -0,0 +1,51 @@
|
||||
require("mw_utils")
|
||||
ATTACHMENT.Base = "att_sight"
|
||||
ATTACHMENT.RenderOverride = true --allows you to control when to draw att's model
|
||||
|
||||
local BaseClass = GetAttachmentBaseClass(ATTACHMENT.Base)
|
||||
|
||||
function ATTACHMENT:Render(weapon)
|
||||
BaseClass.Render(self, weapon)
|
||||
self:DoReticleStencil(self.m_Model, self.Reticle, weapon)
|
||||
end
|
||||
|
||||
function ATTACHMENT:DoReticleStencil(model, ret, weapon)
|
||||
if (IsValid(GetViewEntity())) then
|
||||
if (CurTime() < GetViewEntity():GetNWFloat("MW19_EMPEffect", CurTime())) then
|
||||
model:DrawModel()
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
render.SetStencilWriteMask(0xFF)
|
||||
render.SetStencilTestMask(0xFF)
|
||||
render.SetStencilReferenceValue(0)
|
||||
render.SetStencilCompareFunction(STENCIL_ALWAYS)
|
||||
render.SetStencilPassOperation(STENCIL_REPLACE)
|
||||
render.SetStencilFailOperation(STENCIL_KEEP)
|
||||
render.SetStencilZFailOperation(STENCIL_KEEP)
|
||||
render.SetStencilEnable(true)
|
||||
render.SetStencilReferenceValue(MWBASE_STENCIL_REFVALUE + 1)
|
||||
model:DrawModel()
|
||||
render.SetStencilCompareFunction(STENCIL_EQUAL)
|
||||
|
||||
local att = mw_utils.GetFastAttachment(self.m_Model, ret.Attachment)
|
||||
|
||||
local size = ret.Size
|
||||
local color = ret.Color
|
||||
render.SetMaterial(ret.Material)
|
||||
--i don't know which one is faster, but the second one has a roll option
|
||||
--render.DrawSprite(att.Pos + att.Ang:Forward() * 100, size * 0.01, size * 0.01, color)
|
||||
|
||||
local offset = att.Ang:Forward() * 100
|
||||
|
||||
if (ret.Offset != nil) then
|
||||
offset = offset + att.Ang:Right() * ret.Offset.x
|
||||
offset = offset + att.Ang:Up() * ret.Offset.y
|
||||
end
|
||||
|
||||
render.DrawQuadEasy(att.Pos + offset, att.Ang:Forward():GetNegated(), size * 0.01, size * 0.01, color, -att.Ang.r + 180)
|
||||
|
||||
render.SetStencilEnable(false)
|
||||
render.ClearStencil()
|
||||
end
|
||||
@@ -0,0 +1,3 @@
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default Stock"
|
||||
ATTACHMENT.Category = "Stocks"
|
||||
@@ -0,0 +1,2 @@
|
||||
ATTACHMENT.Base = "att_muzzle"
|
||||
ATTACHMENT.Name = "Default Suppressor"
|
||||
@@ -0,0 +1,3 @@
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default Toprail"
|
||||
ATTACHMENT.Category = "Toprails"
|
||||
@@ -0,0 +1,3 @@
|
||||
ATTACHMENT.Base = "att_base"
|
||||
ATTACHMENT.Name = "Default"
|
||||
ATTACHMENT.Category = "Cables"
|
||||
Reference in New Issue
Block a user