• Multiple Zoom Scope for a TTT SWEP
    0 replies, posted
I have been trying to create a multiple zoom scope for a sniper rifle SWEP to be used in TTT. I have gotten it to work if only one person is using the weapon. However, if multiple people are using the gun, the local variable in the code is affecting anyone using the gun. Thus, it causes people to zoom into random points of the multizoom. The only way I can think of fixing it is to give each player their own variable to be saved. However, I can't figure out how to do this. I'll post the code for the zoom below. [CODE]-- SCOPE CODE zoomLevel = 0 function SWEP:SetZoom(newLevel) if CLIENT then return end if IsValid(self.Owner) and self.Owner:IsPlayer() then zoomLevel = newLevel if (zoomLevel > 3 or zoomLevel <= 0) then zoomLevel = 0 self.Owner:SetFOV(0, 0.2) self:SetIronsights(false) elseif zoomLevel == 1 then self.Owner:SetFOV(20 , 0.3) self:SetIronsights(true) elseif zoomLevel == 2 then self.Owner:SetFOV(10, 0.3) elseif zoomLevel == 3 then self.Owner:SetFOV(5, 0.3) end end end -- Add some zoom to ironsights for this gun function SWEP:SecondaryAttack() if not self.IronSightsPos then return end if self.Weapon:GetNextSecondaryFire() > CurTime() then return end if SERVER then self:SetZoom(zoomLevel + 1) end self.Weapon:SetNextSecondaryFire( CurTime() + 0.3) end function SWEP:PreDrop() self:SetZoom(0) self:SetIronsights(false) return self.BaseClass.PreDrop(self) end function SWEP:Reload() self.Weapon:DefaultReload( ACT_VM_RELOAD ); self:SetIronsights( false ) self:SetZoom(0) end function SWEP:Holster() self:SetIronsights(false) self:SetZoom(0) return true end if CLIENT then local scope = surface.GetTextureID("sprites/scope") function SWEP:DrawHUD() if self:GetIronsights() then surface.SetDrawColor( 0, 0, 0, 255 ) local x = ScrW() / 2.0 local y = ScrH() / 2.0 local scope_size = ScrH() -- crosshair local gap = 80 local length = scope_size surface.DrawLine( x - length, y, x - gap, y ) surface.DrawLine( x + length, y, x + gap, y ) surface.DrawLine( x, y - length, x, y - gap ) surface.DrawLine( x, y + length, x, y + gap ) gap = 0 length = 50 surface.DrawLine( x - length, y, x - gap, y ) surface.DrawLine( x + length, y, x + gap, y ) surface.DrawLine( x, y - length, x, y - gap ) surface.DrawLine( x, y + length, x, y + gap ) -- cover edges local sh = scope_size / 2 local w = (x - sh) + 2 surface.DrawRect(0, 0, w, scope_size) surface.DrawRect(x + sh - 2, 0, w, scope_size) surface.SetDrawColor(255, 0, 0, 255) surface.DrawLine(x, y, x + 1, y + 1) -- scope surface.SetTexture(scope) surface.SetDrawColor(255, 255, 255, 255) surface.DrawTexturedRectRotated(x, y, scope_size, scope_size, 0) else return self.BaseClass.DrawHUD(self) end end function SWEP:AdjustMouseSensitivity() return (self:GetIronsights() and 0.2) or nil end end[/CODE]
Sorry, you need to Log In to post a reply to this thread.