Change in Animation?

So before I list off my issue, I just want to say that I have the most basic possible knowledge of LUA, I am currently trying to pick it up multiple different ways, from this forum, to trying to create cool little addons I guess.

So to start of I am making a starwars rp server <-(I understand it’s a very questionable variant of darkrp in many ways.) And decided I wanted to add animations to the playermodels to whenever they primary attacked the animation would play, (With the lightsaber from robotboy, but he did say the lightsaber by itself cannot apply animations so I wen’t with playermodels.) I searched the web for a hook then found an animation function of the garrysmod lua site. I then went into a playermodels lua section and added this.

hook.Add("PlayerBindPress", "Primary attack", function(ply, bind, pressed)
	if string.find(bind, "+attack1") then

     self:SetAnimation( phalanx_b_right_t2 )

return true

This may or may not look like absolute shit to actual lua developers, but I am just wondering where to go next or where to start if this is completely off track.

That would not be the right way – you would want to implement it into your weapons’ PrimaryAttack methods, instead. Also, what is phalanx_b_right_t2 ?

Blade symphony animation, looks great for swords/sabers

When you say implement it, do you mean implement it into the way the lightsaber attacks with it’s own sort of PrimaryAttack so to speak. Or implement this code into the lua of the lightsaber itself. I understand it’s probably easiest to put this animation code within the lightsabers lua itself, but is it possible to place this code within the playermodels lua section, to have different animations for different playermodels?

EDIT: I found a nice PrimaryAttack hook on the garrysmod site and decided I might be able to add the change animation function to it. Could this work? If it did work what would it sort of look like? (Sry I am new to the lua formatting.)

EDIT: This is how Robotboy designed his PrimaryAttack

function SWEP:PrimaryAttack()
	if ( !IsValid( self.Owner ) ) then return end

	self:SetNextAttack( 0.5 )

	if ( !self.Owner:IsNPC() && self:GetEnabled() ) then
		self.Owner:AnimResetGestureSlot( GESTURE_SLOT_CUSTOM )
		self.Owner:SetAnimation( PLAYER_ATTACK1 )

Is there anyway of implementing it here or should I implement it differently?