-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Laser Pointer refactoring * Linter pass * Remove COLOSSAL_SANDBOX check
- Loading branch information
1 parent
525512e
commit 656c255
Showing
3 changed files
with
58 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,66 @@ | ||
include('shared.lua') | ||
include("shared.lua") | ||
|
||
SWEP.PrintName = "Laser Pointer" | ||
SWEP.Slot = 0 | ||
SWEP.SlotPos = 4 | ||
SWEP.DrawAmmo = false | ||
SWEP.DrawCrosshair = true | ||
|
||
local LASER = Material('cable/redlaser') | ||
local color_red = Color(255, 0, 0) | ||
local laser = Material("cable/redlaser") | ||
|
||
function SWEP:Setup(ply) | ||
if ply.GetViewModel and ply:GetViewModel():IsValid() then | ||
local attachmentIndex = ply:GetViewModel():LookupAttachment("muzzle") | ||
if attachmentIndex == 0 then attachmentIndex = ply:GetViewModel():LookupAttachment("1") end | ||
if ply:IsValid() then | ||
local viewmodel = ply:GetViewModel() | ||
if not viewmodel:IsValid() then return end | ||
|
||
local attachmentIndex = viewmodel:LookupAttachment("muzzle") | ||
if attachmentIndex == 0 then attachmentIndex = viewmodel:LookupAttachment("1") end | ||
|
||
if LocalPlayer():GetAttachment(attachmentIndex) then | ||
self.VM = ply:GetViewModel() | ||
self.VM = viewmodel | ||
self.Attach = attachmentIndex | ||
end | ||
end | ||
|
||
self.WAttach = self:LookupAttachment("muzzle") | ||
end | ||
|
||
function SWEP:Initialize() | ||
self:Setup(self:GetOwner()) | ||
end | ||
function SWEP:Deploy(ply) | ||
|
||
function SWEP:Deploy() | ||
self:Setup(self:GetOwner()) | ||
end | ||
|
||
function SWEP:ViewModelDrawn() | ||
if self.Weapon:GetNWBool("Active") and self.VM then | ||
-- Draw the laser beam. | ||
render.SetMaterial( LASER ) | ||
render.DrawBeam(self.VM:GetAttachment(self.Attach).Pos, self:GetOwner():GetEyeTrace().HitPos, 2, 0, 12.5, Color(255, 0, 0, 255)) | ||
if self:GetLaserEnabled() and self.VM then | ||
render.SetMaterial(laser) | ||
render.DrawBeam(self.VM:GetAttachment(self.Attach).Pos, self:GetOwner():GetEyeTrace().HitPos, 2, 0, 12.5, color_red) | ||
end | ||
end | ||
|
||
function SWEP:DrawWorldModel() | ||
self.Weapon:DrawModel() | ||
if self.Weapon:GetNWBool("Active") then | ||
self:DrawModel() | ||
|
||
if self:GetLaserEnabled() then | ||
local att = self:GetAttachment(self.WAttach) | ||
if not att then return end | ||
|
||
local owner = self:GetOwner() | ||
local startpos = att.Pos | ||
local endpos | ||
|
||
if IsValid(owner) then | ||
endpos = owner:GetEyeTrace().HitPos | ||
else | ||
local tr = util.TraceLine({start = att.Pos, endpos = att.Pos+att.Ang:Forward()*16384, filter = self}) | ||
local tr = util.TraceLine({ start = startpos, endpos = startpos + att.Ang:Forward() * 16384, filter = self }) | ||
endpos = tr.HitPos | ||
end | ||
|
||
-- Draw the laser beam. | ||
render.SetMaterial( LASER ) | ||
render.DrawBeam(startpos, endpos, 2, 0, 12.5, Color(255, 0, 0, 255)) | ||
render.SetMaterial(laser) | ||
render.DrawBeam(startpos, endpos, 2, 0, 12.5, color_red) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters