Sequence/Animations in SWEPS

Recently I’ve been looking on the wiki for ways to implement animations such as idle and others into a SWEP, yet have had little success in doing so. One of the main issues is the right place to actually put in the sequence code into the rest of the file, another is what the code should actually be.

To whom it may concern, why won’t the code run the “ActionIdle” sequence for the Vortigaunt. The vortigaunt adopts the correct pose but has its head slightly crooked and seems stuck on the first frame of the animation.

shared.lua



SWEP.Author = "";
SWEP.Contact = "";
SWEP.Purpose = "";
SWEP.Instructions = "";
SWEP.Category = ""
SWEP.PrintName = "TestSWEP"
 
SWEP.Spawnable = true;
SWEP.AdminSpawnable = true;
 
SWEP.ViewModel = "models/weapons/v_pistol.mdl";
SWEP.WorldModel = "models/weapons/w_pistol.mdl";
 
SWEP.Primary.ClipSize = 100;
SWEP.Primary.DefaultClip = 100;
SWEP.Primary.Automatic = false;
SWEP.Primary.Ammo = "none";

function SWEP:Initialize()
    --if( SERVER ) then
        --self:SetWeaponHoldType( "normal" );
    --end
end

function SWEP:Precache()
    
end

function SWEP:Deploy()
    self.Owner:SetModel("models/vortigaunt.mdl")
end

function SWEP:PrimaryAttack()
    local trace = self.Owner:GetEyeTrace();
    util.ParticleTracerEx("vortigaunt_beam", trace.StartPos, trace.HitPos, true, 0, -1)
    
    --local sequence = self.Owner:LookupSequence("zapattack1")
    --self.Owner:SetSequence(sequence)

    self.Weapon:SetNextPrimaryFire( CurTime() + 10.0 );
    
  end
  
function SWEP:SecondaryAttack()
end

function SWEP:Reload()
end 

--local NexThink = CurTime() + dur

function SWEP:Think()
    local seq = self.Owner:LookupSequence("ActionIdle")
    self.Owner:ResetSequence(seq)
    local dur = self.Owner:SequenceDuration("ActionIdle")
    self.Owner:NextThink(CurTime() + dur)
    return true
    --if( CurTime() >= NextThink ) then 
      --self.Owner:ResetSequence(seq)
    --end  
end


If cl_init and init are pertinent I will post them, but for the most part the code inside is simply auxiliary stuff. If you need me to clarify anything I’ll do so to the best of my ability.

Try putting self.Owner:SetAnimation(<animation_name>) instead of ResetSequence(“ActionIdle”).

Here’s a list of animations for player/npc models:
**[Activity

http://wiki.garrysmod.com/favicon.ico](wiki.garrysmod.com/?title=Activity)**

so your Think() function should look like this:
[lua]
function SWEP:Think()
self.Owner:SetAnimation(ACT_IDLE)
local dur = self.Owner:SequenceDuration(“ActionIdle”)
self.Owner:NextThink(CurTime() + dur)
return true
–if( CurTime() >= NextThink ) then
–self.Owner:SetAnimation(ACT_IDLE)
–end
end
[/lua]

I just tried what you mentioned here and it didn’t work unfortunately.

The Activities I think are reserved for Rebels/Combine as most of them seem pertinent to how they are conducted in-game. On the model viewer for Source SDK zapattack1, idle01, ActionIdle, and many more are listed as animations/sequences that work for the Vortigaunt. The Gmod wiki also defers to the “SetSequence(“idle”)” for setting the idle sequence (and others) for models. Otherwise we might just use the SetAnimation function for everything.

For my purposes, I believe the activities are useless. Thank you for your help though.

The problem I think lies within how the sequence is played and where it needs to be put. Correct me if I’m wrong, as I am otherwise lost on this subject.

Perhaps I would have to use LookupSequence in conjunction with SetAnimation, as the SetAnimation example uses sequence functions at the end.

No errors come up, yet I get no animation and the playermodel seems to glide across the map without stepping.

Some issues, questions and notes about this SWEP and the sequences.
-In NOKIAMAN’s pill pack, the Vortigaunt pill used correctly working anims, using such things as zapattack1, idle01, etc. Yet functions in there used a translate table for animations to sequences and vice versa.
-If not put in think where it is called every frame, where do sequences for a SWEP go? The wiki does not elaborate.
-Animations/Activities/Enumerations/Sequences do not seem to all be the same thing, what are the differences?
-No errors come up but the animations still do not play, what is the problem?

Here is a photo of the current vortigaunt model using what is in the SWEP.

Note the slightly crooked head. The model does not move from this frame aside from the eyes blinking occasionally.

Additionally whenever I walk + jump or run + jump it shows a jumbled and quickened versions of the walk and run animations while in the air.