diff --git a/lua/weapons/laserpointer/cl_init.lua b/lua/weapons/laserpointer/cl_init.lua index adf984a6fd..4fdbe94c50 100644 --- a/lua/weapons/laserpointer/cl_init.lua +++ b/lua/weapons/laserpointer/cl_init.lua @@ -9,33 +9,26 @@ SWEP.DrawCrosshair = true local color_red = Color(255, 0, 0) local laser = Material("cable/redlaser") -function SWEP:Setup(ply) - 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 = viewmodel - self.Attach = attachmentIndex - end - end +-- Scale screen coords by linear proportion of viewmodel and world fov +local function WorldToViewModel(point) + local view = render.GetViewSetup() + local factor = math.tan(math.rad(view.fovviewmodel_unscaled) * 0.5) / math.tan(math.rad(view.fov_unscaled) * 0.5) + point = WorldToLocal(point, angle_zero, view.origin, view.angles) + point:Mul(Vector(1, factor, factor)) + point = LocalToWorld(point, angle_zero, view.origin, view.angles) + return point end -function SWEP:Initialize() - self:Setup(self:GetOwner()) -end +function SWEP:PostDrawViewModel(vm, wep, ply) + if self:GetLaserEnabled() then + local att = vm:GetAttachment(vm:LookupAttachment("muzzle") or 0) + if not att then return end -function SWEP:Deploy() - self:Setup(self:GetOwner()) -end + local startpos = WorldToViewModel(att.Pos) + local endpos = ply:GetEyeTrace().HitPos -function SWEP:ViewModelDrawn() - 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) + render.DrawBeam(startpos, endpos, 2, 0, 12.5, color_red) end end @@ -61,4 +54,4 @@ function SWEP:DrawWorldModel() render.SetMaterial(laser) render.DrawBeam(startpos, endpos, 2, 0, 12.5, color_red) end -end +end \ No newline at end of file diff --git a/lua/weapons/laserpointer/init.lua b/lua/weapons/laserpointer/init.lua index f5f2f6c1e1..faa4b98d13 100644 --- a/lua/weapons/laserpointer/init.lua +++ b/lua/weapons/laserpointer/init.lua @@ -2,47 +2,11 @@ AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") -SWEP.Weight = 8 -SWEP.AutoSwitchTo = false -SWEP.AutoSwitchFrom = false - -SWEP.Receiver = nil -SWEP.Pointing = false - -function SWEP:Initialize() - self.Pointing = false -end - function SWEP:Equip(newOwner) if IsValid(newOwner.LasReceiver) then self.Receiver = newOwner.LasReceiver newOwner.LasReceiver = nil - newOwner:PrintMessage(HUD_PRINTTALK, "Relinked Sucessfully") - end -end - -function SWEP:PrimaryAttack() - self.Pointing = not self.Pointing - self:SetLaserEnabled(self.Pointing) - - if self.Pointing and IsValid(self.Receiver) then - Wire_TriggerOutput(self.Receiver,"Active", 1) - else - Wire_TriggerOutput(self.Receiver,"Active", 0) - end -end - -function SWEP:SecondaryAttack() - local owner = self:GetOwner() - if not IsValid(owner) then return end - - local trace = owner:GetEyeTrace() - - if IsValid(trace.Entity) and trace.Entity:GetClass() == "gmod_wire_las_receiver" and gamemode.Call("CanTool", owner, trace, "wire_las_receiver") then - self.Receiver = trace.Entity - owner:PrintMessage(HUD_PRINTTALK, "Linked Sucessfully") - - return true + newOwner:PrintMessage(HUD_PRINTTALK, "Relinked Successfully!") end end @@ -61,13 +25,14 @@ function SWEP:Think() end local point = trace.HitPos + local receiver = self.Receiver - Wire_TriggerOutput(self.Receiver, "X", point.x) - Wire_TriggerOutput(self.Receiver, "Y", point.y) - Wire_TriggerOutput(self.Receiver, "Z", point.z) - Wire_TriggerOutput(self.Receiver, "Pos", point) - Wire_TriggerOutput(self.Receiver, "RangerData", trace) + WireLib.TriggerOutput(receiver, "X", point.x) + WireLib.TriggerOutput(receiver, "Y", point.y) + WireLib.TriggerOutput(receiver, "Z", point.z) + WireLib.TriggerOutput(receiver, "Pos", point) + WireLib.TriggerOutput(receiver, "RangerData", trace) - self.Receiver.VPos = point + receiver.VPos = point end -end +end \ No newline at end of file diff --git a/lua/weapons/laserpointer/shared.lua b/lua/weapons/laserpointer/shared.lua index ebfcc3280e..3878a9ea08 100644 --- a/lua/weapons/laserpointer/shared.lua +++ b/lua/weapons/laserpointer/shared.lua @@ -1,14 +1,15 @@ SWEP.Author = "" SWEP.Contact = "" -SWEP.Purpose = "" -SWEP.Instructions = "Left Click to designate targets. Right click to select laser receiver." +SWEP.Purpose = "Input source for Laser Pointer Receivers in Wiremod." +SWEP.Instructions = "Left click to designate targets. Right click to select laser receiver." SWEP.Category = "Wiremod" SWEP.Spawnable = true SWEP.AdminOnly = false -SWEP.viewModel = "models/weapons/v_pistol.mdl" -SWEP.worldModel = "models/weapons/w_pistol.mdl" +SWEP.UseHands = true +SWEP.ViewModel = "models/weapons/c_pistol.mdl" +SWEP.WorldModel = "models/weapons/w_pistol.mdl" SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 @@ -20,6 +21,55 @@ SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" +SWEP.Weight = 8 +SWEP.AutoSwitchTo = false +SWEP.AutoSwitchFrom = false + +SWEP.Receiver = nil +SWEP.Pointing = false + +local singleplayer = game.SinglePlayer() + function SWEP:SetupDataTables() - self:NetworkVar("Bool", 0, "LaserEnabled") + self:NetworkVar("Bool", 0, "LaserEnabled") end + +function SWEP:PrimaryAttack() + self.Pointing = not self.Pointing + self:SetLaserEnabled(self.Pointing) + + if CLIENT or singleplayer then + local pitch = self.Pointing and 120 or 80 + self:EmitSound("ambient/energy/newspark03.wav", 100, pitch, 0.5) + + if CLIENT then return end + end + + if self.Pointing and IsValid(self.Receiver) then + WireLib.TriggerOutput(self.Receiver, "Active", 1) + else + WireLib.TriggerOutput(self.Receiver, "Active", 0) + end +end + +function SWEP:SecondaryAttack() + local owner = self:GetOwner() + if not IsValid(owner) then return end + + local trace = owner:GetEyeTrace() + + if IsValid(trace.Entity) and trace.Entity:GetClass() == "gmod_wire_las_receiver" and gamemode.Call("CanTool", owner, trace, "wire_las_receiver") then + if SERVER then + self.Receiver = trace.Entity + owner:PrintMessage(HUD_PRINTTALK, "Linked Successfully!") + end + + if CLIENT or singleplayer then + self:EmitSound("buttons/bell1.wav") + end + + return true + elseif CLIENT or singleplayer then + self:EmitSound("buttons/button16.wav", 100, 50, 0.5) + end +end \ No newline at end of file diff --git a/lua/weapons/remotecontroller.lua b/lua/weapons/remotecontroller.lua index c0f9c04c06..15877ac9ef 100644 --- a/lua/weapons/remotecontroller.lua +++ b/lua/weapons/remotecontroller.lua @@ -2,9 +2,10 @@ AddCSLuaFile() SWEP.Author = "Divran" -- Originally by ShaRose, rewritten by Divran at 2011-04-03 SWEP.Contact = "" -SWEP.Purpose = "Remote control for Pod Controllers in wire." -SWEP.Instructions = "Left Click on Pod Controller to link up, and use to start controlling." +SWEP.Purpose = "Remote control for Pod Controllers in Wiremod." +SWEP.Instructions = "Left click on a Pod Controller to link up, and use to start controlling." SWEP.Category = "Wiremod" +SWEP.IconOverride = "entities/weapon_pistol.png" SWEP.PrintName = "Remote Control" SWEP.Slot = 0 @@ -24,20 +25,34 @@ SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" -SWEP.viewModel = "models/weapons/v_pistol.mdl" -SWEP.worldModel = "models/weapons/w_pistol.mdl" -if CLIENT then return end +SWEP.UseHands = true +SWEP.ViewModel = "models/weapons/c_pistol.mdl" +SWEP.WorldModel = "models/weapons/w_pistol.mdl" function SWEP:PrimaryAttack() local ply = self:GetOwner() local trace = ply:GetEyeTrace() - if IsValid(trace.Entity) and trace.Entity:GetClass() == "gmod_wire_pod" and gamemode.Call("PlayerUse", ply, trace.Entity) then - self.Linked = trace.Entity - ply:ChatPrint("Remote Controller linked.") + local ent = trace.Entity + + if IsValid(ent) and ent:GetClass() == "gmod_wire_pod" then + if SERVER and gamemode.Call("PlayerUse", ply, ent) then + self.Linked = ent + ply:ChatPrint("Remote Controller linked.") + end + + if CLIENT or game.SinglePlayer() then + self:EmitSound("buttons/bell1.wav") + end + elseif CLIENT or game.SinglePlayer() then + self:EmitSound("buttons/button16.wav", 100, 50) end end +function SWEP:SecondaryAttack() end + +if CLIENT then return end + function SWEP:Holster() local ply = self:GetOwner() if IsValid(ply) and self.Linked then @@ -112,5 +127,4 @@ end hook.Add("PlayerNoClip", "wire_remotecontroller_antinoclip", function(ply, cmd) if ply.using_wire_remote_control then return false end -end) - +end) \ No newline at end of file