Lua replace timer

I want to replace the timer here



        self.Owner:DoAnimationEvent(ACT_ZOMBIE_LEAPING)
        timer.Simple(0.5, function()
         self.Owner:DoAnimationEvent(ACT_ZOMBIE_LEAPING)
        end )


With something that will repeat ACT_ZOMBIE_LEAPING until the player is on the ground.

81 Views and no one knows how

Just use Think hook to verify that, it’s not about no one knows, it’s about no one wants to take the time to help you

Worst avatar I ever saw pls change




  local ply = self.Owner --Or whatever you want to determine Player/NPC, using what you had as base

  while not ply:OnGround() do
    timer.Simple( 0.5, function() 
      ply:DoAnimationEvent(ACT_ZOMBIE_LEAPING)
    end)
  end



That should work, untested (with a touchpad so any obvious typos are being blamed on that), also if you do use a while loop, try and make sure you add error catching.

That while loop will just run forever; it should be done in a think hook as gonzalalog said

Is that in the assumption that the code is the only code in file or something to do with on ground? Asking as I’m confused why that while loop would run if the player is on the ground??

Because due to how all this shit works, when that loop is running it will block everything else from running, including all the stuff that processes user input and updates game state. Which means if the player wasn’t on the ground and that code gets triggered, the player will never get back on ground again. Actually it will hang whatever it’s running on (either the client or the server).

This code is for a weapon right?

[editline]31st July 2017[/editline]

[Lua]self.owner.nextjumpanim = self.owner.nextjumpanim or 0
if !self.owner:OnGround() and (self.owner.nextjumpanim - CurTime()) < 0 then
self.owner:DoAnimationEvent(TheJumpAnimationGoesHere)
self.owner.nextjumpanim = CurTime() + .5
end
[/Lua]
If you put that code in your weapons think hook and correct any mistakes I made with my phone it should work

I only want it to do the animation when i right click


 
function SWEP:SecondaryAttack()

    if ( SERVER ) then
    
        if ( not self:CanSecondaryAttack() ) or self.Owner:IsOnGround() == false then return end
        
            local JumpSounds = { "npc/fast_zombie/leap1.wav", "npc/zombie/zo_attack2.wav", "npc/fast_zombie/fz_alert_close1.wav", "npc/zombie/zombie_alert1.wav" }
            self.SecondaryDelay = CurTime()+10
            self.Owner:SetVelocity( self.Owner:GetForward() * 200 + Vector(0,0,400) )
            self.Owner:EmitSound( JumpSounds[math.random(4)], 100, 100 )
            self:SetNextSecondaryFire( CurTime() + self.Secondary.Delay )
    end
end


You didn’t use the code from highvoltage anywhere in there? Try putting it in SWEP:Think()

Also, your check could be simplified to this:



if CLIENT or not self:CanSecondaryAttack() or not self.Owner:IsOnGround() then return end


[editline]6th August 2017[/editline]

Also, I have to change my avatar now :frowning:

Just put the DoAnimation part of the code after the if statement

No because it will only do the animation once

Please explain what you want to happen exactly

I want to do the Act when i right click until Im on the ground