Ok so I've recently added a few custom zooms onto a few snipers. I now have this issue:
[IMG]http://i.imgur.com/KKzQs65.jpg[/IMG]
What do I have to change?
Mind posting your code? Maybe something is wrong with the vectors
[CODE]-- Variables that are used on both client and server
SWEP.Gun = ("m9k_aw50") -- must be the name of your swep but NO CAPITALS!
SWEP.Category = "M9K Sniper Rifles"
SWEP.Author = ""
SWEP.Contact = ""
SWEP.Purpose = ""
SWEP.Instructions = ""
SWEP.MuzzleAttachment = "1" -- Should be "1" for CSS models or "muzzle" for hl2 models
SWEP.ShellEjectAttachment = "2" -- Should be "2" for CSS models or "1" for hl2 models
SWEP.PrintName = "AI AW50" -- Weapon name (Shown on HUD)
SWEP.Slot = 2 -- Slot in the weapon selection menu
SWEP.SlotPos = 76 -- Position in the slot
SWEP.DrawAmmo = true -- Should draw the default HL2 ammo counter
SWEP.DrawWeaponInfoBox = false -- Should draw the weapon info box
SWEP.BounceWeaponIcon = false -- Should the weapon icon bounce?
SWEP.DrawCrosshair = false -- Set false if you want no crosshair from hip
SWEP.XHair = false -- Used for returning crosshair after scope. Must be the same as DrawCrosshair
SWEP.Weight = 50 -- Rank relative ot other weapons. bigger is better
SWEP.AutoSwitchTo = true -- Auto switch to if we pick it up
SWEP.AutoSwitchFrom = true -- Auto switch from if you pick up a better weapon
SWEP.BoltAction = true -- Is this a bolt action rifle?
SWEP.HoldType = "rpg" -- how others view you carrying the weapon
-- normal melee melee2 fist knife smg ar2 pistol rpg physgun grenade shotgun crossbow slam passive
-- you're mostly going to use ar2, smg, shotgun or pistol. rpg and crossbow make for good sniper rifles
SWEP.ViewModelFOV = 70
SWEP.ViewModelFlip = true
SWEP.ViewModel = "models/weapons/v_aw50_awp.mdl" -- Weapon view model
SWEP.WorldModel = "models/weapons/w_acc_int_aw50.mdl" -- Weapon world model
SWEP.Base = "weapon_tttbase"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.Primary.Sound = Sound("Weaponaw50.Single") -- script that calls the primary fire sound
SWEP.Primary.RPM = 50 -- This is in Rounds Per Minute
SWEP.Primary.ClipSize = 10 -- Size of a clip
SWEP.Primary.DefaultClip = 10 -- Bullets you start with
SWEP.Primary.KickUp = 1 -- Maximum up recoil (rise)
SWEP.Primary.KickDown = 1 -- Maximum down recoil (skeet)
SWEP.Primary.KickHorizontal = 1 -- Maximum up recoil (stock)
SWEP.Primary.Automatic = false -- Automatic/Semi Auto
SWEP.Primary.Ammo = "357" -- pistol, 357, smg1, ar2, buckshot, slam, SniperPenetratedRound, AirboatGunSWEP.Primary.Cone = 0.005
SWEP.HeadshotMultiplier = 4
SWEP.Primary.Cone = 0.005
SWEP.Primary.Delay = 1.0
SWEP.Primary.ClipMax = 60
SWEP.Kind = WEAPON_HEAVY
SWEP.AmmoEnt = "item_ammo_357_ttt"
-- Pistol, buckshot, and slam always ricochet. Use AirboatGun for a light metal peircing shotgun pellets
SWEP.Secondary.ScopeZoom = 9
SWEP.Secondary.UseACOG = false -- Choose one scope type
SWEP.Secondary.UseMilDot = false -- I mean it, only one
SWEP.Secondary.UseSVD = false -- If you choose more than one, your scope will not show up at all
SWEP.Secondary.UseParabolic = true
SWEP.Secondary.UseElcan = false
SWEP.Secondary.UseGreenDuplex = false
SWEP.Secondary.UseAimpoint = false
SWEP.Secondary.UseMatador = false
SWEP.data = {}
SWEP.data.ironsights = 1
SWEP.ScopeScale = 0.7
SWEP.ReticleScale = 0.6
SWEP.Primary.NumShots = 1 --how many bullets to shoot per trigger pull
SWEP.Primary.Damage = 50 --base damage per bullet
SWEP.Primary.Spread = .1 --define from-the-hip accuracy 1 is terrible, .0001 is exact)
SWEP.Primary.IronAccuracy = .0001 -- ironsight accuracy, should be the same for shotguns
-- enter iron sight info and bone mod info below
SWEP.IronSightsPos = Vector(3.68, 0, 1.08)
SWEP.IronSightsAng = Vector(0, 0, 0)
SWEP.SightsPos = Vector(3.68, 0, 1.08)
SWEP.SightsAng = Vector(0, 0, 0)
SWEP.RunSightsPos = Vector (-2.3095, -3.0514, 2.3965)
SWEP.RunSightsAng = Vector (-19.8471, -33.9181, 10)
SWEP.Secondary.Sound = Sound("Default.Zoom")
function SWEP:SetZoom(state)
if CLIENT then
return
elseif IsValid(self.Owner) and self.Owner:IsPlayer() then
if state then
self.Owner:SetFOV(20, 0.3)
else
self.Owner:SetFOV(0, 0.2)
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
bIronsights = not self:GetIronsights()
self:SetIronsights( bIronsights )
if SERVER then
self:SetZoom(bIronsights)
else
self:EmitSound(self.Secondary.Sound)
end
self.Weapon:SetNextSecondaryFire( CurTime() + 0.3)
end
function SWEP:PreDrop()
self:SetZoom(false)
self:SetIronsights(false)
return self.BaseClass.PreDrop(self)
end
function SWEP:Reload()
self.Weapon:DefaultReload( ACT_VM_RELOAD );
self:SetIronsights( false )
self:SetZoom(false)
end
function SWEP:Holster()
self:SetIronsights(false)
self:SetZoom(false)
return true
end
if CLIENT then
local scope = surface.GetTextureID("scope/gdcw_scopesight.vtf`")
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]
I used the default sniper zoom as a template
would I have to change the cover edge size?
[QUOTE=Aeternal;44098506]would I have to change the cover edge size?[/QUOTE]
Well, your first big issue is that you're using M9K.
Replace your code with [URL="http://pastebin.com/GKJGUDuf"]this [/URL]and replace your SWEP:Initialize() in weapon_tttbase with [URL="http://pastebin.com/YYFD7UKB"]this[/URL]. I just finished doing something similar with this today so this should work fine for you
[QUOTE=_Jacob;44100087]Replace your code with [URL="http://pastebin.com/GKJGUDuf"]this [/URL]and replace your SWEP:Initialize() in weapon_tttbase with [URL="http://pastebin.com/YYFD7UKB"]this[/URL]. I just finished doing something similar with this today so this should work fine for you[/QUOTE]
Alright so your code works however I now get this error in the console
[CODE][ERROR] gamemodes/terrortown/entities/weapons/weapon_tttbase/shared.lua:484: attempt to perform arithmetic on field 'ScopeScale' (a nil value)
1. unknown - gamemodes/terrortown/entities/weapons/weapon_tttbase/shared.lua:484[/CODE]
I'm assuming it can't multiply by self.ScopeScale? (Not smart)
Anyway how to fix?
[editline]2nd March 2014[/editline]
What could I put in place of ScopeScale but still have this work?
self.ScopeScale needs to be defined elsewhere in the swep.
[QUOTE=DropDeadTed;44103643]self.ScopeScale needs to be defined elsewhere in the swep.[/QUOTE]
Alright. How would I do that? Would I have to create a function? Or add it to another existing function?