Basicly I’ve been working on modifying animate2 script for my needs and I need to detect and stop special animations from being stopped. I tried to use tables for it but after hours of reading i couldn’t find any functions to detect if animation track is located inside the table. Can I implement the table to detect those animations?What should i use to easily access animations to ignore them?
heres the code that i tried
local function StopAllAnimations(ignoreName1, ignoreName2, ignoreName3)
local AnimationsToIgnore = {
‘Climb’,
‘Tool’,
}
for i, animTrack in pairs(animator:GetPlayingAnimationTracks()) do
for i = 1, #AnimationsToIgnore do
if animTrack.Name == table.unpack(AnimationsToIgnore) then
print(“Ignoring” … animTrack.Name)
continue
end
end
if animTrack.Name == ignoreName1 or animTrack.Name == ignoreName2 or animTrack.Name == ignoreName3 then
continue
end
animTrack:Stop(transitionTime)
end
end
You have the right idea to use a table for this purpose. You should use a table as a lookup rather than a list though. In Lua, tables can also be used as dictionaries or hashmaps, which allow you to look up a value in constant time.
In your case, you should use a table where the keys are the animation names, and the values are all true. Then, you can check if an animation is in the table by just indexing it.
local function StopAllAnimations(ignoreName1, ignoreName2, ignoreName3)
local AnimationsToIgnore = {
['Climb'] = true,
['Tool'] = true,
['ShotGunIdle'] = true,
['ShotGunFire'] = true,
['ShotGunPump'] = true,
['ShotGunReload'] = true,
['RifleIdle'] = true,
['RifleShot'] = true,
['RifleReload'] = true,
['PistolIdle'] = true,
['PistolShot'] = true,
['PistolReload'] = true,
[ignoreName1] = true,
[ignoreName2] = true,
[ignoreName3] = true
}
for _, animTrack in pairs(animator:GetPlayingAnimationTracks()) do
if not AnimationsToIgnore[animTrack.Name] then
animTrack:Stop(transitionTime)
else
print("Ignoring " .. animTrack.Name)
end
end
end