So I've been trying to make a nightstick SWEP for some one I'm developing a DarkRP server for, and they requested a; left click = arrest/right click = unarrest. Seems simple, however I seem to be getting these errors.
Left click to arrest results in this error:
[CODE][ERROR] lua/weapons/weapon_nightstick/shared.lua:548: attempt to compare number with nil
1. unknown - lua/weapons/weapon_nightstick/shared.lua:548
[/CODE]
Right click to unarrest results in this error:
[CODE]
[ERROR] lua/weapons/weapon_nightstick/shared.lua:598: attempt to compare number with nil
1. unknown - lua/weapons/weapon_nightstick/shared.lua:598
[/CODE]
Here's the actual SWEP code:
[CODE]AddCSLuaFile("shared.lua")
SWEP.PrintName = "Nightstick"
SWEP.Slot = 1
SWEP.SlotPos = 3
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = false
SWEP.Author = "Oneleg"
SWEP.HoldType = "melee"
SWEP.ViewModelFOV = 70
SWEP.ViewModelFlip = false
SWEP.ViewModel = "models/weapons/c_stunstick.mdl"
SWEP.WorldModel = "models/weapons/w_stunbaton.mdl"
SWEP.ShowViewModel = false
SWEP.ShowWorldModel = false
SWEP.ViewModelBoneMods = {}
SWEP.Spawnable = false
SWEP.AdminSpawnable = true
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "none"
SWEP.Primary.Delay = 1
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"
SWEP.Weight = 5
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.Base = "weapon_cs_base2"
SWEP.VElements = {
["stick2"] = { type = "Model", model = "models/props_c17/canister02a.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "stick", pos = Vector(0, 0, 0.239), angle = Angle(180, 0, 0), size = Vector(0.146, 0.146, 0.061), color = Color(10, 9, 9, 255), surpresslightning = false, material = "phoenix_storms/fender_chrome", skin = 0, bodygroup = {} },
["stick3"] = { type = "Model", model = "models/props_vehicles/tire001a_tractor.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "stick1", pos = Vector(0, 0, 4.356), angle = Angle(90, 0, 0), size = Vector(0.453, 0.02, 0.02), color = Color(10, 9, 9, 255), surpresslightning = false, material = "phoenix_storms/iron_rails", skin = 0, bodygroup = {} },
["stick1"] = { type = "Model", model = "models/hunter/tubes/tube1x1x4.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "stick", pos = Vector(0.081, -0.08, 18.1), angle = Angle(92.955, 111.037, 0), size = Vector(0.029, 0.029, 0.039), color = Color(10, 9, 9, 255), surpresslightning = false, material = "phoenix_storms/fender_chrome", skin = 0, bodygroup = {} },
["stick"] = { type = "Model", model = "models/props_c17/oildrum001.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(5.022, 1.485, -21.591), angle = Angle(5.763, 0, 0), size = Vector(0.05, 0.05, 0.533), color = Color(10, 9, 9, 255), surpresslightning = false, material = "phoenix_storms/fender_chrome", skin = 0, bodygroup = {} }
}
SWEP.WElements = {
["stick2"] = { type = "Model", model = "models/props_c17/canister02a.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "stick", pos = Vector(0, 0, 0.578), angle = Angle(180, 0, 0), size = Vector(0.137, 0.137, 0.057), color = Color(10, 9, 9, 255), surpresslightning = false, material = "phoenix_storms/fender_chrome", skin = 0, bodygroup = {} },
["stick1"] = { type = "Model", model = "models/hunter/tubes/tube1x1x4.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "stick", pos = Vector(0.081, -0.08, 18.1), angle = Angle(92.955, 111.037, 0), size = Vector(0.029, 0.029, 0.039), color = Color(10, 9, 9, 255), surpresslightning = false, material = "phoenix_storms/fender_chrome", skin = 0, bodygroup = {} },
["stick3"] = { type = "Model", model = "models/props_vehicles/tire001a_tractor.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "stick1", pos = Vector(0, 0, 4.356), angle = Angle(90, 0, 0), size = Vector(0.453, 0.02, 0.02), color = Color(10, 9, 9, 255), surpresslightning = false, material = "phoenix_storms/iron_rails", skin = 0, bodygroup = {} },
["stick"] = { type = "Model", model = "models/props_c17/oildrum001.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(6.651, 1.228, -20.611), angle = Angle(12.236, 0, 0), size = Vector(0.05, 0.05, 0.533), color = Color(10, 9, 9, 255), surpresslightning = false, material = "phoenix_storms/fender_chrome", skin = 0, bodygroup = {} }
}
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.SetColorModulation(v.color.r/255, v.color.g/255, v.color.b/255)
render.SetBlend(v.color.a/255)
model:DrawModel()
render.SetBlend(1)
render.SetColorModulation(1, 1, 1)
if (v.surpresslightning) then
render.SuppressEngineLighting(false)
end
elseif (v.type == "Sprite" and sprite) then
local drawpos = pos + ang:Forward() * v.pos.x + ang:Right() * v.pos.y + ang:Up() * v.pos.z
re
self.NextStrike isn't initialized anywhere before 548 and 598. It is initialized later, however, on lines 558 and 608 respectively, but it does no use to do it after the initial CurTime() check.
Sorry, you need to Log In to post a reply to this thread.