[英]attempt to fix global 'SWEP' a nil value
I am trying to create a weapon for a friend on Garry's Mod with Lua. 我正在尝试为Gara's Mod与Lua上的朋友创建武器。 I have made it through all other errors but I keep getting this error:
我已经通过所有其他错误,但我一直收到此错误:
input:22: attempt to index global SWEP (a nil value)
I try to put a function before line 22 where it would say 我尝试将一个函数放在第22行之前
function SWEP.Base = "weapon_tttbase"
but then I would get an error saying '(' expected near =
function SWEP.Base = "weapon_tttbase"
但随后我会收到一条错误消息,说'(' expected near =
if SERVER then
AddCSLuaFile( "shared.lua" )
SWEP.HoldType = "normal"
end
if CLIENT then
SWEP.PrintName = "Cloak"
SWEP.Slot = 6
SWEP.ViewModelFlip = false
SWEP.EquipMenuData = {
type = "item_weapon",
desc = "cloak_desc"
};
SWEP.Icon = "VGUI/ttt/icon_disguiser"
end
SWEP.Base = "weapon_tttbase"
SWEP.UseHands = true
SWEP.ViewModelFlip = false
SWEP.ViewModelFOV = 70
SWEP.ViewModel = "models/weapons/v_models/v_watch_spy.mdl"
SWEP.WorldModel = "models/weapons/w_models/w_watch.mdl"
SWEP.ShowViewModel = true
SWEP.ShowWorldModel = true
SWEP.ViewModelBoneMods = {}
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.DrawCrosshair = false
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Delay = 129.0
SWEP.Primary.Ammo = "none"
SWEP.Primary.ClipMax = -1
SWEP.AutoSpawnable = false
SWEP.AmmoEnt = "none"
SWEP.Kind = WEAPON_EQUIP1
SWEP.CanBuy = {ROLE_DETECTIVE} -- only detectives can buy
SWEP.LimitedStock = true -- only buyable once
SWEP.Primary.Sound = Sound( "hl2_sound_misc_000" )
-- Pull out faster than standard guns
SWEP.DeploySpeed = 2
SWEP.AllowDrop = false
SWEP.NoSights = true
SWEP.Initialize()
self.Weapon:SetNetworkFloat("energy",100)
function SWEP:Think()
if SERVER then
if( self.Owner:KeyDown( IN_ATTACK ) ) then
if self.Weapon:GetNetworkedFloat("energy") >0 then
if self.Weapon:GetNetworkedFloat("energy") >0 then
end
end
end
self.Weapon:SetNetworkedFloat("energy",self.Weapon:GetNetworkedFloat("energy")-0.1)
end
if (self.Invis) then if self.Invis:IsValid() then return end
end
self.Invis = ents.Create("ms_cloakent")
self.Invis:SetPos(
self.Owner:GetPos()+Vector(0,0,50) )
self.Invis:SetAngles( Vector(0,0,0) )
self.Invis:SetParent( self.Owner )
self.Invis:SetNetworkedEntity("parent",self.Owner)
self.Invis:SetNetworkedBool("set",true)
self.Invis:Spawn()
self.Owner:DrawWorldModel(false)
self.Owner:SetColor(255,255,255,0)
end
if (self.Invis) then
if self.Invis:IsValid() then
self.Invis:Remove()
end
end
self.Owner:DrawWorldModel(true)
self.Owner:SetColor(255,255,255,255)
if (self.Invis) then
if self.Invis:IsValid() then
self.Invis:Remove()
end
end
self.Owner:DrawWorldModel(true)
self.Owner:SetColor(255,255,255,255)
if self.Weapon:GetNetworkedFloat("energy") <100 then
self.Weapon:SetNetworkedFloat("energy",self.Weapon:GetNetworkedFloat("energy"))
end
function SWEP:PrimaryAttack()
local effect = EffectData()
effect:SetOrigin(self.Owner:GetPos())
effect:SetScale(100)
util.Effect("super_explosion2", effect)
local effect = EffectData()
effect:SetOrigin(self.Owner:GetPos())
effect:SetScale(50)
util.Effect("super_explosion2", effect)
end
function SWEP:OnRemove()
if (self.Invis) then
if self.Invis:IsValid() then
self.Invis:remove()
end
end
return true
end
function SWEP (Holster)
if (self.Invis) then
if self.Invis:IsValid() then
self.Invis:Remove()
end
end
return true
end
if CLIENT then
function SWEP (DrawHUD)
draw.RoundedBox( 10, ScrW()/2-20, ScrH/2-20, 40, 40,
Color(0,0,0,100) )
draw.SimpleText(
tostring(math.Round(self.Weapon:GetNetworkedFloat("energy"))).."%",
"ChatFont", ScrW()/2, ScrH/2, Color(255,255,255,255), TEXT_ALIGN_CENTER,
TEXT_ALIGN_CENTER )
end
function SWEP (OnDrop)
self:Remove()
end
function SWEP:PrimaryAttack()
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
self:Cloak()
end
end
Unless SWEP is a table that already exists when your code is loaded you are attempting to assign to SWEP.Base but SWEP does not exist (it is nil as the error indicates). 除非SWEP是在加载代码时已经存在的表,否则您尝试分配给SWEP.Base但SWEP不存在(错误指示为nil)。
Also, you have multiple definitions of a SWEP function later. 另外,稍后您将对SWEP函数有多个定义。 Only the last of which will actually exist when your code is finished running.
当您的代码完成运行时,只有最后一个实际上将存在。 That definition will also replace whatever table you had originally filled with all of your various SWEP.* assignments.
该定义还将替换您最初用所有各种SWEP。*分配填充的任何表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.