簡體   English   中英

嘗試將全局“ SWEP”修復為零

[英]attempt to fix global 'SWEP' a nil value

我正在嘗試為Gara's Mod與Lua上的朋友創建武器。 我已經通過所有其他錯誤,但我一直收到此錯誤:

input:22: attempt to index global SWEP (a nil value)

我嘗試將一個函數放在第22行之前

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

除非SWEP是在加載代碼時已經存在的表,否則您嘗試分配給SWEP.Base但SWEP不存在(錯誤指示為nil)。

另外,稍后您將對SWEP函數有多個定義。 當您的代碼完成運行時,只有最后一個實際上將存在。 該定義還將替換您最初用所有各種SWEP。*分配填充的任何表。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM