Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gmod 13 Lua错误_Lua_Garrys Mod - Fatal编程技术网

Gmod 13 Lua错误

Gmod 13 Lua错误,lua,garrys-mod,Lua,Garrys Mod,我正在努力学习Lua,我决定在我的第一个项目中,我将尝试修复一个损坏的脚本。我已经修复了一些bug,但我现在被卡住了。你能帮我吗 function SWEP:PrimaryAttack() if( CurTime() < self.NextStrike ) then return; end self.Weapon:EmitSound("player/skick/sparta.mp3") self.NextStrike = ( CurTime() + 3

我正在努力学习Lua,我决定在我的第一个项目中,我将尝试修复一个损坏的脚本。我已经修复了一些bug,但我现在被卡住了。你能帮我吗

    function SWEP:PrimaryAttack()
     if( CurTime() < self.NextStrike ) then return; end
     self.Weapon:EmitSound("player/skick/sparta.mp3")
     self.NextStrike = ( CurTime() + 3.5 );
     timer.Simple( 1.80, function() self:AttackAnim() end)
                        -Next line broken-
         timer.Simple( 2.40, function() self.Weapon:SendWeaponAnim( ACT_VM_IDLE ) end);
     timer.Simple( 2.00, function() self.ShootBullets( self ) end)
     self.Owner:SetAnimation( PLAYER_ATTACK1 );
end 

function SWEP:ShootBullets()
    -Next line Broken-
         local trace =Owner:GetEyeTrace();
    if trace.HitPos:Distance(self.Owner:GetShootPos()) <= 130 then
        if( trace.Entity:IsPlayer() or trace.Entity:IsNPC() or trace.Entity:GetClass()=="prop_ragdoll" ) then
                timer.Simple(0, game.ConsoleCommand, "host_timescale 0.1\n")
                timer.Simple(0.5, game.ConsoleCommand, "host_timescale 1\n")
            self.Owner:EmitSound( self.FleshHit[math.random(1,#self.FleshHit)] );
        else
            self.Owner:EmitSound( self.Hit[math.random(1,#self.Hit)] );
        end
                bullet = {}
                bullet.Num    = 5
                bullet.Src    = self.Owner:GetShootPos()
                bullet.Dir    = self.Owner:GetAimVector()
                bullet.Spread = Vector(0.04, 0.04, 0.04)
                bullet.Tracer = 0
                bullet.Force  = 250
                bullet.Damage = 1000000
            self.Owner:FireBullets(bullet)
    end
函数SWEP:PrimaryAttack()
如果(CurTime()如果trace.HitPos:Distance(self.Owner:GetShootPos())出现该错误的原因是“武器”(特别是self.wearm)未初始化。武器没有指向任何东西,所以你不能对它调用任何函数


你能给我们看一下错误信息引用的行吗?文件似乎是共享的。lua
,第84、85和90行。周围的代码也会有帮助。我猜你把它作为原始问题的一部分发布了,但是没有行号是没有帮助的

我喜欢GMOD,祝你好运!您可以使用
self:AttackAnim()
代替
self.AttackAnim(self)
。这就是冒号(:)的全部意义。第一次使用
武器
字段时,您确定它不会更早崩溃吗?谢谢,我会尝试一下,但不知道为什么会出现这个错误?