简体   繁体   English

编写Garry的Mod SWEP脚本时出现奇怪的LUA错误

[英]Strange LUA Error While Scripting Garry's Mod SWEP

I am currently working on a Garry's Mod SWEP for my friends server. 我目前正在为我的朋友服务器开发Garry的Mod SWEP。 I have been troubleshooting for about 8 hours, when i got this strange error: 当我收到这个奇怪的错误时,我已经进行了大约8个小时的故障排除:

line 13: attempt to index global 'SWEP' (a nil value)
stack traceback:
    t.lua:13: in main chunk
    [C]: ?

not sure what it means, as i am fairly new to LUA. 不知道这意味着什么,因为我对LUA相当陌生。

Here is my whole script (also at codepad ): 这是我的整个脚本(也在codepad上 ):

if SERVER then
    SWEP.Weight             = 30        
    SWEP.AutoSwitchTo           = true      
    SWEP.AutoSwitchFrom         = true      
end

if CLIENT then
    SWEP.PrintName = "Bill Nye's Test Weapon"
    SWEP.Slot               = 4                     
    SWEP.SlotPos            = 1                     
end

SWEP.Base = "weapon_base" -- line 13
SWEP.Category = "Bill Nye's Admin Weapons"
SWEP.Author = "Bill Nye The Russian Spy"
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.ViewModelFlip = true

SWEP.HoldType = "ar2"
SWEP.ViewModel  = 
                               {["element_name2"] = { type = "Model", model = "models/XQM/cylinderx2.mdl", bone = "v_weapon.AK47_Parent", rel = "", pos = Vector(0.027, 4.118, 0.518), angle = Angle(-90.025, -4.764, -0.364), size = Vector(0.167, 0.167, 0.167), color = Color(90, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
    ["element_name4"] = { type = "Model", model = "models/props_lab/huladoll.mdl", bone = "v_weapon.AK47_Parent", rel = "", pos = Vector(-0.89, 3.947, 1.452), angle = Angle(-86.752, -1.621, -180), size = Vector(0.273, 0.273, 0.273), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
    ["element_name3"] = { type = "Model", model = "models/props_phx/construct/glass/glass_plate1x1.mdl", bone = "v_weapon.AK47_Parent", rel = "", pos = Vector(0.017, 6.109, 2.431), angle = Angle(0, 0, 0), size = Vector(0.041, 0.041, 0.041), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 3, bodygroup = {} },
    ["element_name"] = { type = "Model", model = "models/sprops/misc/alphanum/alphanum_plu.mdl", bone = "v_weapon.AK47_Parent", rel = "", pos = Vector(0.067, 6.19, 2.417), angle = Angle(0, -1.17, 87.662), size = Vector(0.107, 0.107, 0.107), color = Color(255, 0, 0, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {}}
}
SWEP.WorldModel =  
                               {["element_name2"] = { type = "Model", model = "models/XQM/cylinderx2.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(4.316, 0.736, -4.292), angle = Angle(0, 0, 0), size = Vector(0.167, 0.167, 0.167), color = Color(90, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
    ["element_name4"] = { type = "Model", model = "models/props_lab/huladoll.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(4.987, 0.634, -5.249), angle = Angle(180, 17.653, 0), size = Vector(0.273, 0.273, 0.273), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} },
    ["element_name3"] = { type = "Model", model = "models/props_phx/construct/glass/glass_plate1x1.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(12.293, 0.656, -7.63), angle = Angle(88.204, 1.24, 1.22), size = Vector(0.041, 0.041, 0.041), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 3, bodygroup = {} },
    ["element_name"] = { type = "Model", model = "models/sprops/misc/alphanum/alphanum_plu.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(12.619, 0.646, -7.801), angle = Angle(0, 89.783, 0.244), size = Vector(0.107, 0.107, 0.107), color = Color(255, 0, 0, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {}}
}

SWEP.Primary.Recoil = 0.00
SWEP.Primary.Damage = 1000
SWEP.Primary.NumShots = 1
SWEP.Primary.Spread = 0
SWEP.Primary.Cone = 0
SWEP.Primary.ClipSize = 27
SWEP.Primary.DefaultClip = 100
SWEP.Primary.Ammo = "ar2"
SWEP.Primary.Automatic = true
SWEP.Primary.Delay = 0.1

SWEP.IronSightsPos = Vector(6.099, -13.468, 2.612)
SWEP.IronSightsAng = Vector(3.517, 0, -0)

SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = "none"

function SWEP:Initialize()
    self:SetWeaponHoldType(self.HoldType)
end

function SWEP:PrimaryAttack()

    if (self:CanPrimaryAttack()) then
        return 
    end

    local Bullet = {}
    Bullet.Num = self.Primary.NumShots
    Bullet.Src = self.Owner:GetShootPos ()
    Bullet.Dir = self.Owner:GetAimVector ()
    Bullet.Spread = Vector(self.Primary.Spread, self.Primary.Spread,0)
    Bullet.Tracer = 0
    Bullet.Damage = self.Primary.Damage
    Bullet.AmmoType = self.Primary.Ammo

    self:ShootEffects()
    self:FireBullets(Bullet)
    self:EmitSound ("Weapon_IRifle.Single")
    self:TakePrimaryAmmo ( 1 )
    self:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
end

function SWEP:SecondaryAttack()
    return false 
end

It means: in your t.lua file on line 13 you point to SWEP value, which is a null value. 这意味着:在第13行的t.lua文件中,您指向SWEP值,这是一个空值。

Did you call: SWEP:initialize() ? 您是否致电: SWEP:initialize()

function SWEP:Initialize()
    self:SetWeaponHoldType(self.HoldType)
end

check if your value is "local" or if your SWEP value has been initialized. 检查您的值是否为“本地”或SWEP值是否已初始化。 also check if you remove it before like this: SWEP = nil or not. 还请检查是否像这样之前将其删除:SWEP = nil。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM