• Gravity Gun Claws
    4 replies, posted
Gravity gun opens it's claws when you look at a prop. How do I make my swep play claw opening animation? My code so far: [lua] if (SERVER) then AddCSLuaFile( "weapons/weapon_testweapon.lua" ) SWEP.Weight = 5 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false end if ( CLIENT ) then SWEP.DrawCrosshair = true SWEP.ViewModelFOV = 55 SWEP.ViewModelFlip = false SWEP.CSMuzzleFlashes = false SWEP.Category = "test" SWEP.PrintName = "test weapon" SWEP.Author = "test" SWEP.Slot = 0 SWEP.SlotPos = 10 end SWEP.Spawnable = true SWEP.AdminSpawnable = false SWEP.UseHands = true SWEP.ViewModel = "models/weapons/c_physcannon.mdl" SWEP.WorldModel = "models/weapons/w_physics.mdl" SWEP.Primary.Ammo = "nil" SWEP.Primary.ClipSize = -1 SWEP.Primary.Delay = 1 SWEP.Primary.Automatic = true SWEP.Secondary.Ammo = "nil" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.Delay = 0.1 SWEP.Secondary.Automatic = true function SWEP:PrimaryAttack() PrintTable(self.Owner:GetViewModel():GetAnimInfo(1)) -- output: -- flags = 0 -- fps = 30 -- label = ProngsOpen -- numframes = 1 self.Weapon:EmitSound("Weapon_PhysCannon.OpenClaws") self.Weapon:SendWeaponAnim( ACT_VM_IDLE ) self.Weapon:GetSequenceInfo(0).label = "ProngsOpen" self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay) end function SWEP:SecondaryAttack() self.Weapon:SetNextSecondaryFire(CurTime() + self.Secondary.Delay) end function SWEP:Deploy() self.Weapon:SendWeaponAnim( ACT_VM_IDLE ) return true end function SWEP:Holster() return true end function SWEP:OnRemove() return true end [/lua]
its a pose parameter i think, i don't know much about it though
It seems to be "active" pose parameter, but i still couldn't make my swep open those claws. [lua] function SWEP:PrimaryAttack() self.Weapon:EmitSound("Weapon_PhysCannon.OpenClaws") self.Owner:GetViewModel():SetPoseParameter("active", 1) if(CLIENT) then self.Owner:GetViewModel():InvalidateBoneCache( ) end self.Weapon:SendWeaponAnim( ACT_VM_IDLE ) end [/lua]
See if that works: [code] function SWEP:ViewModelDrawn() local vm = self.Owner:GetViewModel() if vm and vm:IsValid() then vm:SetPoseParameter("active",1) end end [/code] You might need to use a boolean or something to open/close claws, tho.
Thanks! I got it working. I had to use Think instead of ViewModelDrawn though. Full code for anyone interested: [lua] if (SERVER) then AddCSLuaFile( "weapons/weapon_testweapon.lua" ) SWEP.Weight = 5 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false end if ( CLIENT ) then SWEP.DrawCrosshair = true SWEP.ViewModelFOV = 55 SWEP.ViewModelFlip = false SWEP.CSMuzzleFlashes = false SWEP.Category = "test" SWEP.PrintName = "test weapon" SWEP.Author = "test" SWEP.Slot = 0 SWEP.SlotPos = 10 end SWEP.Spawnable = true SWEP.AdminSpawnable = false SWEP.UseHands = true SWEP.ViewModel = "models/weapons/c_physcannon.mdl" SWEP.WorldModel = "models/weapons/w_physics.mdl" SWEP.Primary.Ammo = "nil" SWEP.Primary.ClipSize = -1 SWEP.Primary.Delay = 1 SWEP.Primary.Automatic = true SWEP.Secondary.Ammo = "nil" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.Delay = 0.1 SWEP.Secondary.Automatic = true if(CLIENT) then local clawframe = 0 function SWEP:Think() local vm = self.Owner:GetViewModel() local clawopen = self:GetNWBool("clawopen") local moveclaws = self:GetNWBool("moveclaws") -- Check if claws should move. if(!moveclaws) then return end if(clawopen==true) then -- Open claws. clawframe = clawframe + FrameTime() if(clawframe>1) then clawframe = 1 end vm:SetPoseParameter("active", clawframe) else -- Close claw. clawframe = clawframe - FrameTime() if(clawframe<0) then clawframe = 0 end vm:SetPoseParameter("active", clawframe) end end end function SWEP:PrimaryAttack() self.Weapon:SendWeaponAnim( ACT_VM_IDLE ) local clawopen = self:GetNWBool("clawopen") if(clawopen==true) then clawopen = false -- Close claws. elseif(clawopen==false) then clawopen = true -- Open claws. end self:SetNWBool("clawopen", clawopen) self:SetNWBool("moveclaws", true) -- Move claws. timer.Simple(1, function() if(SERVER) then -- Update claw position to server. self:SetNWBool("moveclaws", false) local vm = self.Owner:GetViewModel() if(clawopen) then vm:SetPoseParameter("active", 1) else vm:SetPoseParameter("active", 0) end end if(CLIENT) then vm:InvalidateBoneCache() end end) self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay) end function SWEP:SecondaryAttack() self.Weapon:SetNextSecondaryFire(CurTime() + self.Secondary.Delay) end function SWEP:Deploy() return true end function SWEP:Holster() return true end function SWEP:OnRemove() return true end [/lua]
Sorry, you need to Log In to post a reply to this thread.