Lua を使って Garry's Mod でフレンド用の武器を作成しようとしています。他のすべてのエラーを解決しましたが、次のエラーが引き続き発生します。
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