How to add Animation and custom view model to this code.



--[[
Name: "shared.lua".
Creator: "Shaneman (Fixes by SoulRipper)".
Product: "AN-Gaming.Net".
--]]

if (SERVER) then
    AddCSLuaFile("shared.lua");
end

-- Check if we're running on the client.
if (CLIENT) then
    SWEP.PrintName = "Hostage Rope";
    SWEP.Slot = 1;
    SWEP.SlotPos = 1;
    SWEP.DrawAmmo = false;
    SWEP.DrawCrosshair = true;
end

-- Define some shared variables.
SWEP.Author    = "Shaneman";
SWEP.Instructions = "Primary Fire: Tie Someone Up
Secondary Fire: Let Them go.
";
SWEP.Contact = "";
SWEP.Purpose = "Tie Up, and hostage people. And of course letting them go. Don't Abuse.";

-- Set the view model and the world model to nil.
SWEP.ViewModel = "";
SWEP.WorldModel = "models/weapons/w_fists.mdl";

-- Set the animation prefix and some other settings.
SWEP.AnimPrefix    = "admire";
SWEP.Spawnable = false;
SWEP.AdminSpawnable = true;
  
-- Set the primary fire settings.
SWEP.Primary.Damage = 0;
SWEP.Primary.ClipSize = -1;
SWEP.Primary.DefaultClip = 0;
SWEP.Primary.Automatic = false;
SWEP.Primary.Ammo = "";

-- Set the secondary fire settings.
SWEP.Secondary.ClipSize = -1;
SWEP.Secondary.DefaultClip = 0;
SWEP.Secondary.Automatic = false;
SWEP.Secondary.Ammo    = "";

-- Set the iron sight positions (pointless here).
SWEP.IronSightPos = Vector(0, 0, 0);
SWEP.IronSightAng = Vector(0, 0, 0);
SWEP.NoIronSightFovChange = true;
SWEP.NoIronSightAttack = true;

-- Called when the SWEP is initialized.
function SWEP:Initialize()
    if (SERVER) then self:SetWeaponHoldType("normal"); end;
end;

-- Called when the player attempts to primary fire.
function SWEP:PrimaryAttack()
    self.Weapon:SetNextPrimaryFire(CurTime() + 6);
    self.Weapon:SetNextSecondaryFire(CurTime() + 6);
    if(SERVER) then
    local trace = self.Owner:GetEyeTrace();
    
    if (trace.Entity:IsPlayer() and self.Owner:GetPos():Distance(trace.Entity:GetPos()) <= 128) then
        local ply = trace.Entity
        timer.Simple(1, function()
            self.Owner:ConCommand("say /me starts to tie up "..trace.Entity:GetNetworkedString("cityrp_Igname")..".");
        end)
        timer.Simple(1.5, function()
            self.Owner:ConCommand("say /me does a simple knot.");
        end)
        timer.Simple(2, function()
            self.Owner:ConCommand("say /me doubles the knot.");
        end)
        timer.Simple(3, function()
            local trace = self.Owner:GetEyeTrace()
            if(ply == trace.Entity) then
                self.Owner:ConCommand("say /me finished the rope with a strong knot.");
                cityrp.player.holsterAll(trace.Entity)
                trace.Entity:StripWeapons()
                trace.Entity:SetWalkSpeed( 55 )
                trace.Entity._Hostaged = true;
                self.Owner:PrintMessage( HUD_PRINTCENTER, "You have tied up "..trace.Entity:Nick().."." )
                trace.Entity:PrintMessage( HUD_PRINTCENTER, "You have been tied up by "..self.Owner:Nick().."." )
            else
                cityrp.player.notify(self.Owner, "Target got away.", 1);
            end
        end)
    else
        cityrp.player.notify(self.Owner, "This is not a person!  You cannot tie it up.", 1);
    end;
    end
end;
        

-- Called when the player attempts to secondary fire.
function SWEP:SecondaryAttack()
    self.Weapon:SetNextPrimaryFire(CurTime() + 1);
    if(SERVER) then
    local trace = {};
    local trace = self.Owner:GetEyeTrace();
    
    if (trace.Entity._Hostaged) then
        if (trace.Entity:IsPlayer() and self.Owner:GetPos():Distance(trace.Entity:GetPos()) <= 128) then
            self.Owner:ConCommand("say /me removes the strong knot from "..trace.Entity:GetNetworkedString("cityrp_Igname")..".");
            trace.Entity:Give("cityrp_keys");
            trace.Entity:Give("gmod_tool");
            trace.Entity:Give("weapon_physgun");
            trace.Entity._Hostaged = false;
            trace.Entity:SetWalkSpeed( 160 )
            trace.Entity:SetRunSpeed( 320 )
            self.Owner:PrintMessage( HUD_PRINTCENTER, "You have released "..trace.Entity:Nick().."." )
            trace.Entity:PrintMessage( HUD_PRINTCENTER, "You have been released by "..self.Owner:Nick().."." )
                end;
     else
            cityrp.player.notify(self.Owner, "That person isn't hostaged!", 1);
    end;
end;
end;


http://pastebin.com/itjJ5vai - better version

How do I add a view model to this, and animations:

When Left Click - Starts animation ACT_VM_PRIMARYATTACK
When Right Click - Starts animation ACT_VM_SECONDARYATTACK
After any of those played or when taking choosing weapon it Starts: ACT_VM_DRAW
After ACT_VM_DRAW it always plays ACT_VM_IDLE
Name of model:
models/als/ROPE/v_rope

World model: models/als/ROPE/w_rope

Please help.
Thanks.

function SWEP:PrimaryAttack()
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK )
end
function SWEP:SecondaryAttack()
self.Weapon:SendWeaponAnim( ACT_VM_SECONDARYATTACK)
end

SWEP.ViewModel = “models/als/ROPE/v_rope”

merge that with your code and what do you mean by:
After any of those played or when taking choosing weapon it Starts: ACT_VM_DRAW
After ACT_VM_DRAW it always plays ACT_VM_IDLE

be as clear as possible

Well I meant like,
After secondary or primary attack animation is played. I want it first to play ACT_VM_DRAW, and then after ACT_VM_DRAW always return to Idle state.

[lua]
local act_primary_time = 1.4 – change this
local act_secondary_time = 1.4 – change this
local act_draw_time = 1.4 – change this

function SWEP:DoPrimaryAnims()
if !IsValid( self.Weapon ) then return end – Safety first!
self.Weapon:SendWeaponAnim( ACT_VM_PRIMARYATTACK ) – Play primary anim
timer.Simple( act_primary_time, self.PlayDrawAnim, self ) – Now make a timer to play the draw anim
end

function SWEP:DoSecondaryAnims()
if !IsValid( self.Weapon ) then return end – Safety first!
self.Weapon:SendWeaponAnim( ACT_VM_SECONDARYATTACK ) – Play secondary anim
timer.Simple( act_secondary_time, self.PlayDrawAnim, self ) – Now make a timer to play the draw anim
end

function SWEP:PlayDrawAnim()
if !IsValid( self.Weapon ) then return end – Safety first!
self.Weapon:SendWeaponAnim( ACT_VM_DRAW ) – Play draw anim
timer.Simple( act_draw_time, self.PlayIdleAnim, self ) – Now make a timer to play the idle anim
end

function SWEP:PlayIdleAnim()
if !IsValid( self.Weapon ) then return end – Safety first!
self.Weapon:SendWeaponAnim( ACT_VM_IDLE ) – Player idle anim
end
[/lua]

Try this. I’m not sure if this is what you are asking for, so correct me if I’m wrong.
All you need to do is paste this in your SWEP code and call self:DoPrimaryAnims() and self:DoSecondaryAnims() in your SWEP:PrimaryAttack() and SWEP:SecondaryAttack() functions.

how would i apply it to a normal gun? so it lowers the weapon, and cant shoot?
** [lua]
–[[
Name: “shared.lua”.
Product: “Cider (Roleplay)”.
–]]

if (SERVER) then
AddCSLuaFile(“shared.lua”);
else
SWEP.DrawAmmo = true;
SWEP.DrawCrosshair = false;
SWEP.ViewModelFlip = true;
SWEP.CSMuzzleFlashes = true;
SWEP.CustomCrosshair = true;
SWEP.Slot = 3;
SWEP.SlotPos = 1;
SWEP.IconLetter = “b”;
SWEP.DrawWeaponInfoBox = true;
end;

– Set the base and category.
SWEP.Base = “rg_base”;
SWEP.Category = “Cider”;

– Set some shared information.
SWEP.PrintName = “AK47”;
SWEP.Author = “********”;
SWEP.Purpose = “A very powerful rifle which is great at long range.”;
SWEP.Instructions = “Primary Fire: Shoot.
Use + Secondary Fire: Change the fire mode.”;
SWEP.Spawnable = false;
SWEP.AdminSpawnable = false;
SWEP.Weight = 5;
SWEP.AutoSwitchTo = false;
SWEP.AutoSwitchFrom = false;
SWEP.HoldType = “ar2”;
SWEP.FiresUnderwater = false;
SWEP.HasLaser = false;
SWEP.HasSilencer = false;
SWEP.CanPenetrate = true;
SWEP.CanPenetrateWorld = true;
SWEP.BulletTracer = 1;

– Set some information for the primary fire.
SWEP.Primary.Sound = Sound(“Weapon_AK47.Single”);
SWEP.Primary.Damage = 12.5;
SWEP.Primary.NumShots = 1;
SWEP.Primary.ClipSize = 25;
SWEP.Primary.DefaultClip = 25;
SWEP.Primary.Ammo = “smg1”;

– Set some information for the secondary fire.
SWEP.Secondary.ClipSize = -1;
SWEP.Secondary.DefaultClip = -1;

– Set some information about the recoil and spray.
SWEP.RecoverTime = 0.75;
SWEP.MinSpread = 0.01;
SWEP.MaxSpread = 0.08;
SWEP.DeltaSpread = 0.01;
SWEP.MinRecoil = 1;
SWEP.MaxRecoil = 5;
SWEP.DeltaRecoil = 1;
SWEP.MinSpray = 0;
SWEP.MaxSpray = 2;
SWEP.DeltaSpray = 0.25;

– Set some information about the iron sights.
SWEP.IronSightsPos = Vector(6.0837, -6.4072, 2.2469);
SWEP.IronSightsAng = Vector(3.0801, -0.1343, -0.1968);
SWEP.IronSightZoom = 1;
SWEP.UseScope = false;
SWEP.ScopeScale = 0.4;
SWEP.ScopeZooms = {4, 8};
SWEP.DrawSniperSights = false;
SWEP.DrawRifleSights = false;

– Set some information about the model and visual effects.
SWEP.ViewModel = “models/weapons/v_rif_ak47.mdl”;
SWEP.WorldModel = “models/weapons/w_rif_ak47.mdl”;
SWEP.MuzzleEffect = “rg_muzzle_highcal”;
SWEP.ShellEffect = “rg_shelleject_rifle”;
SWEP.MuzzleAttachment = “1”;
SWEP.ShellEjectAttachment = “2”;

– Set some modifier information.
SWEP.CrouchModifier = 0.7;
SWEP.IronSightModifier = 0.4;
SWEP.RunModifier = 1.5;
SWEP.JumpModifier = 2;

– Set some information about the available fire modes and RPM.
SWEP.AvailableFireModes = {“Auto”, “Semi”};
SWEP.AutoRPM = 600;
SWEP.SemiRPM = 500;
[/lua]

anyone?