Animations are not playing correctly

Hello :smile:,

I don’t know what the problem is…



function ENT:Think()
self:NextThink(CurTime());

if self.ExistBattery == 0 then
local sequence = self:LookupSequence("disable")
self:ResetSequence(sequence)

elseif self.ExistBattery == 1 and self.PowerOn == 0 then
local sequence = self:LookupSequence("disable")
self:ResetSequence(sequence)

elseif self.ExistBattery == 2 and self.PowerOn == 1 then
local sequence = self:LookupSequence("power_on")
self:ResetSequence(sequence)
self:SetPlaybackRate(0.6)
self.ExistBattery = 3
timer.Simple( 2.4, function() self.ExistBattery = 4 end )

elseif self.ExistBattery == 4 and self.PowerOn == 1 then
local sequence = self:LookupSequence("idle")
self:ResetSequence(sequence)

elseif self.ExistBattery == 4 and self.PowerOn == 0 then
local sequence = self:LookupSequence("power_off")
self:ResetSequence(sequence)
self:SetPlaybackRate(0.6)
self.ExistBattery = 5
timer.Simple( 2.4, function() self.ExistBattery = 1 end )

end

return true;
end



function ENT:Use(v, caller)

	if ( v:IsPlayer() ) && self.ExistBattery == 1 and self.PowerOn == 0 then
						self.ExistBattery = 2
						self.PowerOn = 1

	elseif ( v:IsPlayer() ) && self.ExistBattery == 4 and self.PowerOn == 1 then
						self.PowerOn = 0
	end

end


It’s a “base_anim” Base Type, self.AutomaticFrameAdvance = true and self:SetUseType(SIMPLE_USE)
If you put a battery (Ent) on it and you use it, then it starts. If you use it again then it stops.
The problem: the power_on and power_off animations are not always playing correctly… sometimes it playing it twice or it looks interrupted.
Any Ideas?

(sorry for my english)

I found the “problem”… I have just put self:SetCycle( 0 ) after self:ResetSequence(sequence), then it works :speechless: