【问题标题】:Can't set the damage value(s) to insta-kill NPCs/Players in a Garry's Mod "Spartan Kick" addon无法在 Garry 的 Mod“Spartan Kick”插件中设置伤害值以秒杀 NPC/玩家
【发布时间】:2021-11-09 17:44:13
【问题描述】:

这是我在 StackOverflow 上发布的内容的常见更改!今天我正在尝试编辑某人的 Garry's Mod Workshop Addon。

我想让它成为一击必杀,它是斯巴达踢。

代码如下:

if( SERVER ) then
    AddCSLuaFile( "shared.lua" );
end

if( CLIENT ) then
    SWEP.Category = "Epic Kicks";
    SWEP.PrintName = "Spartan Kick";
    SWEP.WepSelectIcon = surface.GetTextureID("VGUI/entities/spartan_kick") 
    SWEP.Slot = 1;
    SWEP.SlotPos = 4;
    SWEP.DrawAmmo = false;
    SWEP.DrawCrosshair = false;
end

SWEP.Author         = "Shot846 (Original) + 2Epic4You (Modified)"
SWEP.Instructions   = "A better Sparta Kick. Use sv_cheats 1 for slow-motion!"
SWEP.Contact        = "..."
SWEP.Purpose        = "THIS IS EDITED SPARTAAAAAAA!"

SWEP.ViewModelFOV   = 75
SWEP.ViewModelFlip  = false

SWEP.Spawnable          = true
SWEP.AdminSpawnable     = true

SWEP.NextStrike = 0;
  
SWEP.ViewModel      = "models/weapons/v_kick.mdl"
SWEP.WorldModel   = ""
  
-------------Primary Fire Attributes----------------------------------------
SWEP.Primary.Delay          = 0.4   --In seconds
SWEP.Primary.Recoil         = 0     --Gun Kick
SWEP.Primary.Damage         = math.huge --Damage per Bullet
SWEP.Primary.NumShots       = 1     --Number of shots per one fire
SWEP.Primary.Cone           = 0     --Bullet Spread
SWEP.Primary.ClipSize       = -1    --Use "-1 if there are no clips"
SWEP.Primary.DefaultClip    = -1    --Number of shots in next clip
SWEP.Primary.Automatic      = true  --Pistol fire (false) or SMG fire (true)
SWEP.Primary.Ammo           = "none"    --Ammo Type

-------------Secondary Fire Attributes----------------------------------------
SWEP.Secondary.Delay            = 0     --In seconds
SWEP.Secondary.Recoil           = 0     --Gun Kick
SWEP.Secondary.Damage           = math.huge --Damage per Bullet
SWEP.Secondary.NumShots     = 1     --Number of shots per one fire
SWEP.Secondary.Cone         = 0     --Bullet Spread
SWEP.Secondary.ClipSize     = -1    --Use "-1 if there are no clips"
SWEP.Secondary.DefaultClip  = -1    --Number of shots in next clip
SWEP.Secondary.Automatic    = true  --Pistol fire (false) or SMG fire (true)
SWEP.Secondary.Ammo             = "none"    --Ammo Type
 
-------------Precache Sounds----------------------------------------
util.PrecacheSound("player/skick/madness.mp3")
util.PrecacheSound("player/skick/foot_kickwall.wav")
util.PrecacheSound("player/skick/foot_kickbody.wav")
util.PrecacheSound("player/skick/sparta.mp3")
util.PrecacheSound("player/skick/kick1.wav")
util.PrecacheSound("player/skick/kick2.wav")
util.PrecacheSound("player/skick/kick3.wav")
util.PrecacheSound("player/skick/kick4.wav")
util.PrecacheSound("player/skick/kick5.wav")
util.PrecacheSound("player/skick/kick6.wav")

function SWEP:Initialize()
    if( SERVER ) then
            self:SetWeaponHoldType("normal");
    end
    self.Hit = { 
    Sound( "player/skick/foot_kickwall.wav" )};
    self.FleshHit = {
    Sound( "player/skick/kick1.wav" ),
    Sound( "player/skick/kick2.wav" ),
    Sound( "player/skick/kick3.wav" ),
    Sound( "player/skick/kick4.wav" ),
    Sound( "player/skick/kick5.wav" ),
    Sound( "player/skick/kick6.wav" ) } ;

end

function SWEP:Precache()
end

function SWEP:Deploy()
    self.Weapon:SendWeaponAnim( ACT_VM_IDLE );
    return true;
end

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(self) end)
     timer.Simple( 2.40, function() self.Weapon:SendWeaponAnim( ACT_VM_IDLE ) end)
     timer.Simple( 2.0,  function() self.ShootBullets (self) end)
     self.Owner:SetAnimation( PLAYER_ATTACK1 );
end 

function SWEP:ShootBullets()
    self.Weapon:EmitSound("player/skick/foot_swing.wav");
    local trace = self.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, function() game.ConsoleCommand("host_timescale 0.1\n") end) 
                timer.Simple(0.1, function() game.ConsoleCommand("host_timescale 1\n") end)
            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  = math.huge
                bullet.Damage = math.huge
            self.Owner:FireBullets(bullet)
    end
    
    if trace.Entity:GetClass() == "prop_door_rotating" then
     trace.Entity:EmitSound(Sound("physics/wood/wood_box_impact_hard3.wav"))
     trace.Entity:Fire("open", "", .001)
     trace.Entity:Fire("unlock", "", .001)
     local pos = trace.Entity:GetPos()
     local ang = trace.Entity:GetAngles()
     local model = trace.Entity:GetModel()
     local skin = trace.Entity:GetSkin()
     trace.Entity:SetNotSolid(true)
     trace.Entity:SetNoDraw(true)
     local function ResetDoor(door, fakedoor)
     door:SetNotSolid(false)
     door:SetNoDraw(false)
     fakedoor:Remove()
     end
     local norm = (pos - self.Owner:GetPos()):Normalize()
     local push = 1000000 * norm
     local ent = ents.Create("prop_physics")
     ent:SetPos(pos)
     ent:SetAngles(ang)
     ent:SetModel(model)
    if(skin) then
      ent:SetSkin(skin)
    end
     ent:Spawn()
     timer.Simple(.01, ent.SetVelocity, ent, push)               
     timer.Simple(.01, ent:GetPhysicsObject().ApplyForceCenter, ent:GetPhysicsObject(), push)
     timer.Simple(140, ResetDoor, trace.Entity, ent)
end

end

function SWEP:SecondaryAttack()
     if( CurTime() < self.NextStrike ) then return; end
     self.NextStrike = ( CurTime() + 0.75 );
     timer.Simple( 0.00, function() self.AttackAnim(self) end)
     timer.Simple( 0.75, function() self.Weapon:SendWeaponAnim( ACT_VM_IDLE ) end)
     timer.Simple( 0.20,  function() self.ShootBullets (self) end)
     self.Owner:SetAnimation( PLAYER_ATTACK1 );
end 

function SWEP:Reload()
     if( CurTime() < self.NextStrike ) then return; end
     self.Weapon:EmitSound("player/skick/madness.mp3")
     self.NextStrike = ( CurTime() + 2.00 );
end

function SWEP:AttackAnim()
    self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
end 

是的,但它不会立即杀死我生成的 NPC。

我需要更改什么值才能使其被秒杀?

我的尝试:

  • 将找到的所有伤害值更改为 math.huge

我发现了什么:

  • 我发现它仍然会损坏 NPC,原始值为 1000000 但它并没有立即杀死 NPC。

【问题讨论】:

    标签: lua steam garrys-mod


    【解决方案1】:

    我真的想通了!在对 Wiki 进行了一些广泛的研究之后,我发现你可以拥有 bullet.Callback ,所以这就是我所做的:

                    bullet = {}
                    bullet.Num    = 10
                    bullet.Src    = self.Owner:GetShootPos()
                    bullet.Dir    = self.Owner:GetAimVector()
                    bullet.Spread = Vector(0.04, 0.04, 0.04)
                    bullet.Tracer = 0
                    bullet.Force  = 20000
                    bullet.Damage = 999999
                    bullet.Callback = function(attacker, tree, damageinfo)
                        if(trace.Entity:IsNPC()) then
                            trace.Entity:SetHealth(0) 
                        elseif(trace.Entity:IsPlayer()) then
                            trace.Entity:Kill()
                        end
                    end
                self.Owner:FireBullets(bullet)
    

    【讨论】:

      猜你喜欢
      • 2018-09-14
      • 2019-11-19
      • 2020-09-03
      • 2020-05-18
      • 2020-03-03
      • 1970-01-01
      • 2018-12-16
      • 1970-01-01
      • 2021-09-15
      相关资源
      最近更新 更多