I'm making a pack for M9K, and im doing the M1903 Springfield. Now, the scope works fine, then I use the Swep Construction Kit to make a World Model, and when I reload the game when I scope in I get this error.
[code]
[ERROR] addons/m9k heavy weapons/lua/weapons/bobs_scoped_base/shared.lua:387: attempt to index field 'LensTable' (a nil value)
1. unknown - addons/m9k heavy weapons/lua/weapons/bobs_scoped_base/shared.lua:387
[/code]
Springfield Code
[code]
-- Variables that are used on both client and server
SWEP.Gun = ("nam_sfa") -- must be the name of your swep but NO CAPITALS!
SWEP.Category = "[M9K] Vietnam Weapons" --Category where you will find your weapons
SWEP.Author = "overki11"
SWEP.Contact = ""
SWEP.Purpose = ""
SWEP.Instructions = ""
SWEP.PrintName = "M1903 Springfield" -- Weapon name (Shown on HUD)
SWEP.Slot = 2 -- Slot in the weapon selection menu
SWEP.SlotPos = 4 -- 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 = true -- Set false if you want no crosshair from hip
SWEP.Weight = 30 -- 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.XHair = true -- Used for returning crosshair after scope. Must be the same as DrawCrosshair
SWEP.BoltAction = true -- Is this a bolt action rifle?
SWEP.HoldType = "ar2" -- 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_snip_sfa.mdl" -- Weapon view model
SWEP.WorldModel = "models/weapons/w_snip_scout.mdl" -- Weapon world model
SWEP.ShowWorldModel = false`
SWEP.Base = "bobs_scoped_base" --the Base this weapon will work on. PLEASE RENAME THE BASE!
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.Primary.Sound = Sound("springfield.Fire1") -- script that calls the primary fire sound
SWEP.Primary.RPM = 1400 -- This is in Rounds Per Minute
SWEP.Primary.ClipSize = 5 -- Size of a clip
SWEP.Primary.DefaultClip = 60 -- Bullets you start with
SWEP.Primary.KickUp = .4 -- Maximum up recoil (rise)
SWEP.Primary.KickDown = .4 -- Maximum down recoil (skeet)
SWEP.Primary.KickHorizontal = .6 -- Maximum up recoil (stock)
SWEP.Primary.Automatic = false -- Automatic/Semi Auto
SWEP.Primary.Ammo = "ar2" -- pistol, 357, smg1, ar2, buckshot, slam, SniperPenetratedRound, AirboatGun
-- Pistol, buckshot, and slam always ricochet. Use AirboatGun for a light metal peircing shotgun pellets
SWEP.Secondary.ScopeZoom = 4
SWEP.Secondary.UseACOG = false -- Choose one scope type
SWEP.Secondary.UseMilDot = true -- 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 = false
SWEP.Secondary.UseElcan = false
SWEP.Secondary.UseGreenDuplex = false
SWEP.data = {}
SWEP.data.ironsights = 1
SWEP.ScopeScale = 0.5
SWEP.ReticleScale = 0.6
SWEP.Primary.Damage = 33 --base damage per bullet
SWEP.Primary.Spread = .015 --define from-the-hip accuracy 1 is terrible, .0001 is exact)
SWEP.Primary.IronAccuracy = .01 -- ironsight accuracy, should be the same for shotguns
-- enter iron sight info and bone mod info below
SWEP.IronSightsPos = Vector (0, 0, 0)
SWEP.IronSightsAng = Vector (0, 0, 0)
SWEP.SightsPos = Vector(0,0,0)
SWEP.SightsAng = Vector(0,0,0)
SWEP.RunSightsPos = Vector (0, 0, 0)
SWEP.RunSightsAng = Vector (0, 0, 0)
/********************************************************
SWEP Construction Kit base code
Created by Clavus
Available for public use, thread at:
facepunch.com/threads/1032378
DESCRIPTION:
This script is meant for experienced scripters
that KNOW WHAT THEY ARE DOING. Don't come to me
with basic Lua questions.
Just copy into your SWEP or SWEP base of choice
and merge with your own code.
The SWEP.VElements, SWEP.WElements and
SWEP.ViewModelBoneMods tables are all optional
and only have to be visible to the client.
********************************************************/
function SWEP:Initialize()
// other initialize code goes here
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
if IsValid(self.Owner) then
local vm = self.Owner:GetViewModel()
if IsValid(vm) then
self:ResetBonePositions(vm)
// Init viewmodel visibility
if (self.ShowViewModel == nil or self.ShowViewModel) then
vm:SetColor(Color(255,255,255,255))
else
// we set the alpha to 1 instead of 0 because else ViewModelDrawn stops being called
vm:SetColor(Color(255,255,255,1))
// ^ stopped working in GMod 13 because you have to do Entity:SetRenderMode(1) for translucency to kick in
// however for some reason the view model resets to render mode 0 every frame so we just apply a debug material to prevent it from drawing
vm:SetMaterial("Debug/hsv")
end
end
end
end
end
function SWEP:Holster()
if CLIENT and IsValid(self.Owner) then
local vm = self.Owner:GetViewModel()
if IsValid(vm) then
self:ResetBonePositions(vm)
end
end
return true
end
function SWEP:OnRemove()
self:Holster()
end
if CLIENT then
SWEP.vRenderOrder = nil
function SWEP:ViewModelDrawn()
local vm = self.Owner:GetViewModel()
if !IsValid(vm) then return end
if (!self.VElements) then return end
self:UpdateBonePositions(vm)
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
if (v.hide) then continue 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 IsValid(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)
local matrix = Matrix()
matrix:Scale(v.size)
model:EnableMatrix( "RenderMultiply", matrix )
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.SetC
You need a 'LensTable' defined somewhere. What GM is this for?
I believe _Jacob gave me this long ago. I've edited it a tiny bit but all credits to him (This was for TTT).
[CODE]SWEP.ScopeScale = 0.5
SWEP.ReticleScale = 0.5
-- Set up ironsights dt bool. Weapons using their own DT vars will have to make
-- sure they call this.
function SWEP:SetupDataTables()
-- Put it in the last slot, least likely to interfere with derived weapon's
-- own stuff.
self:DTVar("Bool", 3, "ironsights")
end
function SWEP:Initialize()
if CLIENT and self.Weapon:Clip1() == -1 then
self.Weapon:SetClip1(self.Primary.DefaultClip)
elseif SERVER then
self.fingerprints = {}
self:SetIronsights(false)
end
if CLIENT then
-- We need to get these so we can scale everything to the player's current resolution.
local iScreenWidth = surface.ScreenWidth()
local iScreenHeight = surface.ScreenHeight()
-- The following code is only slightly riped off from Night Eagle
-- These tables are used to draw things like scopes and crosshairs to the HUD.
-- so DONT GET RID OF IT!
self.ScopeTable = {}
self.ScopeTable.l = iScreenHeight*self.ScopeScale
self.ScopeTable.x1 = 0.5*(iScreenWidth + self.ScopeTable.l)
self.ScopeTable.y1 = 0.5*(iScreenHeight - self.ScopeTable.l)
self.ScopeTable.x2 = self.ScopeTable.x1
self.ScopeTable.y2 = 0.5*(iScreenHeight + self.ScopeTable.l)
self.ScopeTable.x3 = 0.5*(iScreenWidth - self.ScopeTable.l)
self.ScopeTable.y3 = self.ScopeTable.y2
self.ScopeTable.x4 = self.ScopeTable.x3
self.ScopeTable.y4 = self.ScopeTable.y1
self.ScopeTable.l = (iScreenHeight + 1)*self.ScopeScale -- I don't know why this works, but it does.
self.QuadTable = {}
self.QuadTable.x1 = 0
self.QuadTable.y1 = 0
self.QuadTable.w1 = iScreenWidth
self.QuadTable.h1 = 0.5*iScreenHeight - self.ScopeTable.l
self.QuadTable.x2 = 0
self.QuadTable.y2 = 0.5*iScreenHeight + self.ScopeTable.l
self.QuadTable.w2 = self.QuadTable.w1
self.QuadTable.h2 = self.QuadTable.h1
self.QuadTable.x3 = 0
self.QuadTable.y3 = 0
self.QuadTable.w3 = 0.5*iScreenWidth - self.ScopeTable.l
self.QuadTable.h3 = iScreenHeight
self.QuadTable.x4 = 0.5*iScreenWidth + self.ScopeTable.l
self.QuadTable.y4 = 0
self.QuadTable.w4 = self.QuadTable.w3
self.QuadTable.h4 = self.QuadTable.h3
self.LensTable = {}
self.LensTable.x = self.QuadTable.w3
self.LensTable.y = self.QuadTable.h1
self.LensTable.w = 2*self.ScopeTable.l
self.LensTable.h = 2*self.ScopeTable.l
self.ReticleTable = {}
self.ReticleTable.wdivider = 3.125
self.ReticleTable.hdivider = 1.7579/self.ReticleScale -- Draws the texture at 512 when the resolution is 1600x900
self.ReticleTable.x = (iScreenWidth/2)-((iScreenHeight/self.ReticleTable.hdivider)/2)
self.ReticleTable.y = (iScreenHeight/2)-((iScreenHeight/self.ReticleTable.hdivider)/2)
self.ReticleTable.w = iScreenHeight/self.ReticleTable.hdivider
self.ReticleTable.h = iScreenHeight/self.ReticleTable.hdivider
self.FilterTable = {}
self.FilterTable.wdivider = 3.125
self.FilterTable.hdivider = 1.7579/1.35
self.FilterTable.x = (iScreenWidth/2)-((iScreenHeight/self.FilterTable.hdivider)/2)
self.FilterTable.y = (iScreenHeight/2)-((iScreenHeight/self.FilterTable.hdivider)/2)
self.FilterTable.w = iScreenHeight/self.FilterTable.hdivider
self.FilterTable.h = iScreenHeight/self.FilterTable.hdivider
end
self:SetDeploySpeed(self.DeploySpeed)
-- compat for gmod update
if self.SetWeaponHoldType then
self:SetWeaponHoldType(self.HoldType or "pistol")
end
end[/CODE]
I'm planning to release the weapon pack on the workshop for all gamemodes. But the scope works as long as I don't have the code for the SWEP Construction kit in there....
Sorry, you need to Log In to post a reply to this thread.