Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- koyper
- --]]
- if (CLIENT) then
- SWEP.Slot = 0;
- SWEP.SlotPos = 5;
- SWEP.DrawAmmo = false;
- SWEP.PrintName = "Battery Charger";
- SWEP.DrawCrosshair = true;
- end
- SWEP.Instructions = "Primary Fire: Charge";
- SWEP.Purpose = "Charging batteries manually.";
- SWEP.Contact = "";
- SWEP.Author = "kipder";
- SWEP.HoldType = "fist"
- SWEP.ViewModelFOV = 70
- SWEP.ViewModelFlip = true
- SWEP.ViewModel = "models/weapons/v_pist_glock18.mdl"
- SWEP.WorldModel = "models/weapons/w_pistol.mdl"
- SWEP.ShowViewModel = true
- SWEP.ShowWorldModel = false
- SWEP.ViewModelBoneMods = {
- ["v_weapon.Glock_Parent"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) },
- ["v_weapon.Right_Pinky01"] = { scale = Vector(1, 1, 1), pos = Vector(0, 0, 0), angle = Angle(0, -35.264, 0) },
- ["v_weapon.Right_Index01"] = { scale = Vector(1, 1, 1), pos = Vector(0, 0, 0), angle = Angle(-4.757, -79.5, 0) },
- ["v_weapon.Right_Ring02"] = { scale = Vector(1, 1, 1), pos = Vector(-0.494, 0, 0), angle = Angle(-7.369, -18.987, 0) },
- ["v_weapon.Left_Hand"] = { scale = Vector(1, 1, 1), pos = Vector(0, 0, 1.85), angle = Angle(0, 0, 15.911) },
- ["v_weapon.Right_Pinky02"] = { scale = Vector(1, 1, 1), pos = Vector(0, 0, 0), angle = Angle(-6.35, -15.146, 0) },
- ["v_weapon.Right_Ring01"] = { scale = Vector(1, 1, 1), pos = Vector(0, 0, 0), angle = Angle(-6.094, -55.3, 1.531) },
- ["v_weapon.Right_Thumb02"] = { scale = Vector(1, 1, 1), pos = Vector(0.079, 0, -0.201), angle = Angle(4.33, 2.151, -48.145) },
- ["v_weapon.Right_Middle01"] = { scale = Vector(1, 1, 1), pos = Vector(0, 0, 0), angle = Angle(3.404, -67.04, -9.65) },
- ["v_weapon.Glock_Clip"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) },
- ["v_weapon.Right_Index02"] = { scale = Vector(1, 1, 1), pos = Vector(0, 0, 0), angle = Angle(-9.577, -34.646, 0) },
- ["v_weapon.Right_Arm"] = { scale = Vector(1, 1, 1), pos = Vector(-3.656, 12.932, -0.552), angle = Angle(0, 9, -110) },
- ["v_weapon.Right_Pinky03"] = { scale = Vector(1, 1, 1), pos = Vector(0, 0, 0), angle = Angle(3.085, -31.75, 0) },
- ["v_weapon.Right_Thumb03"] = { scale = Vector(1, 1, 1), pos = Vector(0, -0.269, 0), angle = Angle(4.931, 9.793, 20.325) },
- ["v_weapon.Right_Thumb01"] = { scale = Vector(1, 1, 1), pos = Vector(0, 0, 0), angle = Angle(22.731, -6.481, 15.105) },
- ["v_weapon.Left_Thumb01"] = { scale = Vector(1, 1, 1), pos = Vector(-0.065, 0.368, 0), angle = Angle(-30.889, 9.63, 19.75) },
- ["v_weapon.Left_Middle03"] = { scale = Vector(1, 1, 1), pos = Vector(0, 0, -0.26), angle = Angle(0, 0, 0) }
- }
- SWEP.VElements = {
- ["some_unique_name"] = { type = "Model", model = "models/avoxgaming/mrp/jake/props/universal_charger.mdl", bone = "v_weapon.Glock_Parent", rel = "", pos = Vector(-0.9, 3.555, -4.206), angle = Angle(195, 90, 93), size = Vector(1, 1, 1), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
- }
- SWEP.WElements = {
- ["some_unique_name1"] = { type = "Model", model = "models/avoxgaming/mrp/jake/props/universal_charger.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(6.124, 1.973, -1.183), angle = Angle(-11.125, 20.381, 208), size = Vector(0.699, 0.699, 0.699), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
- }
- SWEP.AdminSpawnable = true;
- SWEP.Spawnable = true;
- SWEP.Primary.DefaultClip = 0;
- SWEP.Primary.Automatic = false;
- SWEP.Primary.ClipSize = -1;
- SWEP.Primary.Damage = 8;
- SWEP.Primary.Delay = 2;
- SWEP.Primary.Ammo = "";
- SWEP.Secondary.NeverRaised = true;
- SWEP.Secondary.DefaultClip = 0;
- SWEP.Secondary.Automatic = false;
- SWEP.Secondary.ClipSize = -1;
- SWEP.Secondary.Delay = 1;
- SWEP.Secondary.Ammo = "";
- SWEP.NoIronSightFovChange = true;
- SWEP.NoIronSightAttack = true;
- SWEP.IronSightPos = Vector(0, 0, 0);
- SWEP.IronSightAng = Vector(0, 0, 0);
- SWEP.chargeSounds = {
- "avoxgaming/charger/charger_pump_1.wav",
- "avoxgaming/charger/charger_pump_2.wav",
- "avoxgaming/charger/charger_pump_3.wav"
- };
- -- Called when the SWEP is deployed.
- function SWEP:Deploy()
- self:SendWeaponAnim(ACT_VM_DRAW);
- end;
- -- Called when the SWEP is holstered.
- function SWEP:Holster(switchingTo)
- self:SendWeaponAnim(ACT_VM_HOLSTER);
- return true;
- end;
- -- Called when the SWEP is initialized.
- function SWEP:Initialize()
- self:SetWeaponHoldType(self.HoldType);
- if CLIENT then
- // Create a new table for every weapon instance
- self.VElements = table.FullCopy( self.VElements )
- self.WElements = table.FullCopy( self.WElements )
- self.ViewModelBoneMods = table.FullCopy( self.ViewModelBoneMods )
- self:CreateModels(self.VElements) // create viewmodels
- self:CreateModels(self.WElements) // create worldmodels
- // init view model bone build function
- self.BuildViewModelBones = function( s )
- if LocalPlayer():GetActiveWeapon() == self and self.ViewModelBoneMods then
- for k, v in pairs( self.ViewModelBoneMods ) do
- local bone = s:LookupBone(k)
- if (!bone) then continue end
- local m = s:GetBoneMatrix(bone)
- if (!m) then continue end
- m:Scale(v.scale)
- m:Rotate(v.angle)
- m:Translate(v.pos)
- s:SetBoneMatrix(bone, m)
- end
- end
- end
- end
- end
- if CLIENT then
- SWEP.vRenderOrder = nil
- function SWEP:ViewModelDrawn()
- local vm = self.Owner:GetViewModel()
- if !ValidEntity(vm) then return end
- if (!self.VElements) then return end
- if vm.BuildBonePositions != self.BuildViewModelBones then
- vm.BuildBonePositions = self.BuildViewModelBones
- end
- if (self.ShowViewModel == nil or self.ShowViewModel) then
- vm:SetColor(255,255,255,255)
- else
- // we set the alpha to 1 instead of 0 because else ViewModelDrawn stops being called
- vm:SetColor(255,255,255,1)
- end
- if (!self.vRenderOrder) then
- // we build a render order because sprites need to be drawn after models
- self.vRenderOrder = {}
- for k, v in pairs( self.VElements ) do
- if (v.type == "Model") then
- table.insert(self.vRenderOrder, 1, k)
- elseif (v.type == "Sprite" or v.type == "Quad") then
- table.insert(self.vRenderOrder, k)
- end
- end
- end
- for k, name in ipairs( self.vRenderOrder ) do
- local v = self.VElements[name]
- if (!v) then self.vRenderOrder = nil break end
- local model = v.modelEnt
- local sprite = v.spriteMaterial
- if (!v.bone) then continue end
- local pos, ang = self:GetBoneOrientation( self.VElements, v, vm )
- if (!pos) then continue end
- if (v.type == "Model" and ValidEntity(model)) then
- model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
- ang:RotateAroundAxis(ang:Up(), v.angle.y)
- ang:RotateAroundAxis(ang:Right(), v.angle.p)
- ang:RotateAroundAxis(ang:Forward(), v.angle.r)
- model:SetAngles(ang)
- model:SetModelScale(v.size)
- if (v.material == "") then
- model:SetMaterial("")
- elseif (model:GetMaterial() != v.material) then
- model:SetMaterial( v.material )
- end
- if (v.skin and v.skin != model:GetSkin()) then
- model:SetSkin(v.skin)
- end
- if (v.bodygroup) then
- for k, v in pairs( v.bodygroup ) do
- if (model:GetBodygroup(k) != v) then
- model:SetBodygroup(k, v)
- end
- end
- end
- if (v.surpresslightning) then
- render.SuppressEngineLighting(true)
- end
- render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
- render.SetBlend(v.color.a/255)
- model:DrawModel()
- render.SetBlend(1)
- render.SetColorModulation(1, 1, 1)
- if (v.surpresslightning) then
- render.SuppressEngineLighting(false)
- end
- elseif (v.type == "Sprite" and sprite) then
- local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
- render.SetMaterial(sprite)
- render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
- elseif (v.type == "Quad" and v.draw_func) then
- local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
- ang:RotateAroundAxis(ang:Up(), v.angle.y)
- ang:RotateAroundAxis(ang:Right(), v.angle.p)
- ang:RotateAroundAxis(ang:Forward(), v.angle.r)
- cam.Start3D2D(drawpos, ang, v.size)
- v.draw_func( self )
- cam.End3D2D()
- end
- end
- end
- SWEP.wRenderOrder = nil
- function SWEP:DrawWorldModel()
- if (self.ShowWorldModel == nil or self.ShowWorldModel) then
- self:DrawModel()
- end
- if (!self.WElements) then return end
- if (!self.wRenderOrder) then
- self.wRenderOrder = {}
- for k, v in pairs( self.WElements ) do
- if (v.type == "Model") then
- table.insert(self.wRenderOrder, 1, k)
- elseif (v.type == "Sprite" or v.type == "Quad") then
- table.insert(self.wRenderOrder, k)
- end
- end
- end
- if (ValidEntity(self.Owner)) then
- bone_ent = self.Owner
- else
- // when the weapon is dropped
- bone_ent = self
- end
- for k, name in pairs( self.wRenderOrder ) do
- local v = self.WElements[name]
- if (!v) then self.wRenderOrder = nil break end
- local pos, ang
- if (v.bone) then
- pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent )
- else
- pos, ang = self:GetBoneOrientation( self.WElements, v, bone_ent, "ValveBiped.Bip01_R_Hand" )
- end
- if (!pos) then continue end
- local model = v.modelEnt
- local sprite = v.spriteMaterial
- if (v.type == "Model" and ValidEntity(model)) then
- model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
- ang:RotateAroundAxis(ang:Up(), v.angle.y)
- ang:RotateAroundAxis(ang:Right(), v.angle.p)
- ang:RotateAroundAxis(ang:Forward(), v.angle.r)
- model:SetAngles(ang)
- model:SetModelScale(v.size)
- if (v.material == "") then
- model:SetMaterial("")
- elseif (model:GetMaterial() != v.material) then
- model:SetMaterial( v.material )
- end
- if (v.skin and v.skin != model:GetSkin()) then
- model:SetSkin(v.skin)
- end
- if (v.bodygroup) then
- for k, v in pairs( v.bodygroup ) do
- if (model:GetBodygroup(k) != v) then
- model:SetBodygroup(k, v)
- end
- end
- end
- if (v.surpresslightning) then
- render.SuppressEngineLighting(true)
- end
- render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
- render.SetBlend(v.color.a/255)
- model:DrawModel()
- render.SetBlend(1)
- render.SetColorModulation(1, 1, 1)
- if (v.surpresslightning) then
- render.SuppressEngineLighting(false)
- end
- elseif (v.type == "Sprite" and sprite) then
- local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
- render.SetMaterial(sprite)
- render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
- elseif (v.type == "Quad" and v.draw_func) then
- local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
- ang:RotateAroundAxis(ang:Up(), v.angle.y)
- ang:RotateAroundAxis(ang:Right(), v.angle.p)
- ang:RotateAroundAxis(ang:Forward(), v.angle.r)
- cam.Start3D2D(drawpos, ang, v.size)
- v.draw_func( self )
- cam.End3D2D()
- end
- end
- end
- function SWEP:GetBoneOrientation( basetab, tab, ent, bone_override )
- local bone, pos, ang
- if (tab.rel and tab.rel != "") then
- local v = basetab[tab.rel]
- if (!v) then return end
- // Technically, if there exists an element with the same name as a bone
- // you can get in an infinite loop. Let's just hope nobody's that stupid.
- pos, ang = self:GetBoneOrientation( basetab, v, ent )
- if (!pos) then return end
- pos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
- ang:RotateAroundAxis(ang:Up(), v.angle.y)
- ang:RotateAroundAxis(ang:Right(), v.angle.p)
- ang:RotateAroundAxis(ang:Forward(), v.angle.r)
- else
- bone = ent:LookupBone(bone_override or tab.bone)
- if (!bone) then return end
- pos, ang = Vector(0,0,0), Angle(0,0,0)
- local m = ent:GetBoneMatrix(bone)
- if (m) then
- pos, ang = m:GetTranslation(), m:GetAngle()
- end
- if (ValidEntity(self.Owner) and self.Owner:IsPlayer() and
- ent == self.Owner:GetViewModel() and self.ViewModelFlip) then
- ang.r = -ang.r // Fixes mirrored models
- end
- end
- return pos, ang
- end
- function SWEP:CreateModels( tab )
- if (!tab) then return end
- // Create the clientside models here because Garry says we can't do it in the render hook
- for k, v in pairs( tab ) do
- if (v.type == "Model" and v.model and v.model != "" and (!ValidEntity(v.modelEnt) or v.createdModel != v.model) and
- string.find(v.model, ".mdl") and file.Exists ("../"..v.model) ) then
- v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
- if (ValidEntity(v.modelEnt)) then
- v.modelEnt:SetPos(self:GetPos())
- v.modelEnt:SetAngles(self:GetAngles())
- v.modelEnt:SetParent(self)
- v.modelEnt:SetNoDraw(true)
- v.createdModel = v.model
- else
- v.modelEnt = nil
- end
- elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
- and file.Exists ("../materials/"..v.sprite..".vmt")) then
- local name = v.sprite.."-"
- local params = { ["$basetexture"] = v.sprite }
- // make sure we create a unique name based on the selected options
- local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
- for i, j in pairs( tocheck ) do
- if (v[j]) then
- params["$"..j] = 1
- name = name.."1"
- else
- name = name.."0"
- end
- end
- v.createdSprite = v.sprite
- v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)
- end
- end
- end
- /**************************
- Global utility code
- **************************/
- // Fully copies the table, meaning all tables inside this table are copied too and so on (normal table.Copy copies only their reference).
- // Does not copy entities of course, only copies their reference.
- // WARNING: do not use on tables that contain themselves somewhere down the line or you'll get an infinite loop
- function table.FullCopy( tab )
- if (!tab) then return nil end
- local res = {}
- for k, v in pairs( tab ) do
- if (type(v) == "table") then
- res[k] = table.FullCopy(v) // recursion ho!
- elseif (type(v) == "Vector") then
- res[k] = Vector(v.x, v.y, v.z)
- elseif (type(v) == "Angle") then
- res[k] = Angle(v.p, v.y, v.r)
- else
- res[k] = v
- end
- end
- return res
- end
- end-- A function to do the SWEP's hit effects.
- function SWEP:DoHitEffects()
- end;
- -- A function to do the SWEP's animations.
- function SWEP:DoAnimations(idle)
- if (!idle) then
- self.Owner:SetAnimation(PLAYER_ATTACK1);
- end;
- end;
- function SWEP:PrimaryAttack()
- if ( not self.Owner.lastCharge or self.Owner.lastCharge < CurTime() ) then
- self.Owner.lastCharge = CurTime() + 1;
- local battery = self.Owner:GetCharacterData("battery");
- if ( battery <= 80 ) then
- self.Owner:SetCharacterData("battery", battery + 20 );
- self.Owner:EmitSound( table.Random( self.chargeSounds), 50, 100 );
- end;
- end;
- end;
- -- Called when the player attempts to secondary fire.
- function SWEP:SecondaryAttack() end;
- function SWEP:OnRemove()
- // other onremove code goes here
- if CLIENT then
- self:RemoveModels()
- end
- end
- if CLIENT then
- SWEP.vRenderOrder = nil
- function SWEP:ViewModelDrawn()
- local vm = self.Owner:GetViewModel()
- if !ValidEntity(vm) then return end
- if (!self.VElements) then return end
- if vm.BuildBonePositions ~= self.BuildViewModelBones then
- vm.BuildBonePositions = self.BuildViewModelBones
- end
- if (self.ShowViewModel == nil or self.ShowViewModel) then
- vm:SetColor(255,255,255,255)
- else
- // we set the alpha to 1 instead of 0 because else ViewModelDrawn stops being called
- vm:SetColor(255,255,255,1)
- end
- if (!self.vRenderOrder) then
- // we build a render order because sprites need to be drawn after models
- self.vRenderOrder = {}
- for k, v in pairs( self.VElements ) do
- if (v.type == "Model") then
- table.insert(self.vRenderOrder, 1, k)
- elseif (v.type == "Sprite" or v.type == "Quad") then
- table.insert(self.vRenderOrder, k)
- end
- end
- end
- for k, name in ipairs( self.vRenderOrder ) do
- local v = self.VElements[name]
- if (!v) then self.vRenderOrder = nil break end
- local model = v.modelEnt
- local sprite = v.spriteMaterial
- if (!v.bone) then continue end
- local bone = vm:LookupBone(v.bone)
- if (!bone) then continue end
- local pos, ang = Vector(0,0,0), Angle(0,0,0)
- local m = vm:GetBoneMatrix(bone)
- if (m) then
- pos, ang = m:GetTranslation(), m:GetAngle()
- end
- if (self.ViewModelFlip) then
- ang.r = -ang.r // Fixes mirrored models
- end
- if (v.type == "Model" and ValidEntity(model)) then
- model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
- ang:RotateAroundAxis(ang:Up(), v.angle.y)
- ang:RotateAroundAxis(ang:Right(), v.angle.p)
- ang:RotateAroundAxis(ang:Forward(), v.angle.r)
- model:SetAngles(ang)
- model:SetModelScale(v.size)
- if (v.material == "") then
- model:SetMaterial("")
- elseif (model:GetMaterial() != v.material) then
- model:SetMaterial( v.material )
- end
- if (v.skin and v.skin != model:GetSkin()) then
- model:SetSkin(v.skin)
- end
- if (v.bodygroup) then
- for k, v in pairs( v.bodygroup ) do
- if (model:GetBodygroup(k) != v) then
- model:SetBodygroup(k, v)
- end
- end
- end
- if (v.surpresslightning) then
- render.SuppressEngineLighting(true)
- end
- render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
- render.SetBlend(v.color.a/255)
- model:DrawModel()
- render.SetBlend(1)
- render.SetColorModulation(1, 1, 1)
- if (v.surpresslightning) then
- render.SuppressEngineLighting(false)
- end
- elseif (v.type == "Sprite" and sprite) then
- local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
- render.SetMaterial(sprite)
- render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
- elseif (v.type == "Quad" and v.draw_func) then
- local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
- ang:RotateAroundAxis(ang:Up(), v.angle.y)
- ang:RotateAroundAxis(ang:Right(), v.angle.p)
- ang:RotateAroundAxis(ang:Forward(), v.angle.r)
- cam.Start3D2D(drawpos, ang, v.size)
- v.draw_func( self )
- cam.End3D2D()
- end
- end
- end
- SWEP.wRenderOrder = nil
- function SWEP:DrawWorldModel()
- if (self.ShowWorldModel == nil or self.ShowWorldModel) then
- self:DrawModel()
- end
- if (!self.WElements) then return end
- if (!self.wRenderOrder) then
- self.wRenderOrder = {}
- for k, v in pairs( self.WElements ) do
- if (v.type == "Model") then
- table.insert(self.wRenderOrder, 1, k)
- elseif (v.type == "Sprite" or v.type == "Quad") then
- table.insert(self.wRenderOrder, k)
- end
- end
- end
- local opos, oang = self:GetPos(), self:GetAngles()
- local bone_ent
- if (ValidEntity(self.Owner)) then
- bone_ent = self.Owner
- else
- // when the weapon is dropped
- bone_ent = self
- end
- for k, name in pairs( self.wRenderOrder ) do
- local v = self.WElements[name]
- if (!v) then self.wRenderOrder = nil break end
- if (v.bone) then
- bone = bone_ent:LookupBone(v.bone)
- else
- bone = bone_ent:LookupBone("ValveBiped.Bip01_R_Hand")
- end
- if (bone) then
- local m = bone_ent:GetBoneMatrix(bone)
- if (m) then
- opos, oang = m:GetTranslation(), m:GetAngle()
- end
- else
- continue
- end
- local model = v.modelEnt
- local sprite = v.spriteMaterial
- local pos, ang = Vector(opos.x, opos.y, opos.z), Angle(oang.p, oang.y, oang.r)
- if (v.type == "Model" and ValidEntity(model)) then
- model:SetPos(pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z )
- ang:RotateAroundAxis(ang:Up(), v.angle.y)
- ang:RotateAroundAxis(ang:Right(), v.angle.p)
- ang:RotateAroundAxis(ang:Forward(), v.angle.r)
- model:SetAngles(ang)
- model:SetModelScale(v.size)
- if (v.material == "") then
- model:SetMaterial("")
- elseif (model:GetMaterial() != v.material) then
- model:SetMaterial( v.material )
- end
- if (v.skin and v.skin != model:GetSkin()) then
- model:SetSkin(v.skin)
- end
- if (v.bodygroup) then
- for k, v in pairs( v.bodygroup ) do
- if (model:GetBodygroup(k) != v) then
- model:SetBodygroup(k, v)
- end
- end
- end
- if (v.surpresslightning) then
- render.SuppressEngineLighting(true)
- end
- render.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
- render.SetBlend(v.color.a/255)
- model:DrawModel()
- render.SetBlend(1)
- render.SetColorModulation(1, 1, 1)
- if (v.surpresslightning) then
- render.SuppressEngineLighting(false)
- end
- elseif (v.type == "Sprite" and sprite) then
- local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
- render.SetMaterial(sprite)
- render.DrawSprite(drawpos, v.size.x, v.size.y, v.color)
- elseif (v.type == "Quad" and v.draw_func) then
- local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
- ang:RotateAroundAxis(ang:Up(), v.angle.y)
- ang:RotateAroundAxis(ang:Right(), v.angle.p)
- ang:RotateAroundAxis(ang:Forward(), v.angle.r)
- cam.Start3D2D(drawpos, ang, v.size)
- v.draw_func( self )
- cam.End3D2D()
- end
- end
- end
- function SWEP:CreateModels( tab )
- if (!tab) then return end
- // Create the clientside models here because Garry says we can't do it in the render hook
- for k, v in pairs( tab ) do
- if (v.type == "Model" and v.model and v.model != "" and (!ValidEntity(v.modelEnt) or v.createdModel != v.model) and
- string.find(v.model, ".mdl") and file.Exists ("../"..v.model) ) then
- v.modelEnt = ClientsideModel(v.model, RENDER_GROUP_VIEW_MODEL_OPAQUE)
- if (ValidEntity(v.modelEnt)) then
- v.modelEnt:SetPos(self:GetPos())
- v.modelEnt:SetAngles(self:GetAngles())
- v.modelEnt:SetParent(self)
- v.modelEnt:SetNoDraw(true)
- v.createdModel = v.model
- else
- v.modelEnt = nil
- end
- elseif (v.type == "Sprite" and v.sprite and v.sprite != "" and (!v.spriteMaterial or v.createdSprite != v.sprite)
- and file.Exists ("../materials/"..v.sprite..".vmt")) then
- local name = v.sprite.."-"
- local params = { ["$basetexture"] = v.sprite }
- // make sure we create a unique name based on the selected options
- local tocheck = { "nocull", "additive", "vertexalpha", "vertexcolor", "ignorez" }
- for i, j in pairs( tocheck ) do
- if (v[j]) then
- params["$"..j] = 1
- name = name.."1"
- else
- name = name.."0"
- end
- end
- v.createdSprite = v.sprite
- v.spriteMaterial = CreateMaterial(name,"UnlitGeneric",params)
- end
- end
- end
- function SWEP:RemoveModels()
- if (self.VElements) then
- for k, v in pairs( self.VElements ) do
- if (ValidEntity( v.modelEnt )) then v.modelEnt:Remove() end
- end
- end
- if (self.WElements) then
- for k, v in pairs( self.WElements ) do
- if (ValidEntity( v.modelEnt )) then v.modelEnt:Remove() end
- end
- end
- self.VElements = nil
- self.WElements = nil
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement