I have made a custom SWEP with custom animations. I have been stuck with this problem for at least two hours so I'm calling it a day.
My swep works. It's a melee weapon. It attacks, the idle animation plays (there is no draw animation). However, when i press fire there is no animation. I've made one and named it properly. If i change the shared.lua idle animation to use the file for the attack animation instead, it will play. I checked the model in HLMV and the animation works. This has to be a lua problem right?
if (SERVER) then
AddCSLuaFile("shared.lua")
--models
resource.AddFile("models/weapons/combatcross.mdl")
resource.AddFile("models/weapons/combatcross_retracted.mdl")
--materials
resource.AddFile("materials/models/weapons/chain_spike.vtf")
resource.AddFile("materials/models/weapons/chain_spike.vmt")
resource.AddFile("materials/models/weapons/cross.vtf")
resource.AddFile("materials/models/weapons/cross.vmt")
resource.AddFile("materials/models/weapons/pike.vtf")
resource.AddFile("materials/models/weapons/pike.vmt")
end
SWEP.PrintName = "00"
SWEP.Slot = 0
SWEP.SlotPos = 0
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
SWEP.Author = "Willom"
SWEP.Instructions = "Left click for attack."
SWEP.Contact = "N/A"
SWEP.Purpose = "00"
SWEP.Category = "00"
SWEP.ViewModelFOV = 70
SWEP.ViewModelFlip = false
SWEP.Spawnable = true
SWEP.AdminSpawnable = true
SWEP.HoldType = "melee"
SWEP.ViewModel = "models/weapons/combatcross.mdl"
SWEP.WorldModel = "models/weapons/combatcross_retracted.mdl"
SWEP.UseHands = true
SWEP.Primary.Sound = Sound( "" )
SWEP.Primary.Delay = 1.8
SWEP.Primary.Recoil = 0
SWEP.Primary.Damage = 1
SWEP.Primary.NumShots = 1
SWEP.Primary.Cone = 0
SWEP.Primary.ClipSize = -1
SWEP.Primary.DefaultClip = -1
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = "none"
SWEP.Secondary.Ammo = "none"
function SWEP:Precache()
end
function
SWEP:PrimaryAttack()
self.Weapon:SendWeaponAnim(ACT_VM_MISSCENTER)
self.Owner:SetAnimation(PLAYER_ATTACK1)
self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay)
self.Weapon:EmitSound("Weapon_Knife.Slash")
local trace = self.Owner:GetEyeTrace()
if trace.HitPos:Distance(self.Owner:GetShootPos()) <= 30 then
bullet = {}
bullet.Num = 1
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Spread = Vector(0, 0, 0)
bullet.Tracer = 0
bullet.Force = 14
bullet.Damage = 50
self.Owner:FireBullets(bullet)
self.Weapon:EmitSound("Weapon_Knife.Slash")
if(trace.Entity:IsPlayer() or trace.Entity:IsNPC() or trace.Entity:GetClass() == "prop_ragdoll") then
self.Weapon:EmitSound(SFleshHit[math.random(1,#SFleshHit)])
else
util.Decal("ManhackCut", trace.HitPos + trace.HitNormal, trace.HitPos - trace.HitNormal)
if (trace.MatType == MAT_METAL or trace.MatType == MAT_VENT or trace.MatType == MAT_COMPUTER) then
self.Weapon:EmitSound(SMetalHit[math.random(1,#SMetalHit)])
elseif (trace.MatType == MAT_WOOD or trace.MatType == "MAT_FOLIAGE") then
self.Weapon:EmitSound(SWoodHit[math.random(1,#SWoodHit)])
elseif (trace.MatType == MAT_GLASS) then
self.Weapon:EmitSound(SGlassHit[math.random(1,#SGlassHit)])
elseif (trace.MatType == MAT_DIRT or trace.MatType == MAT_SAND or trace.MatType == MAT_SLOSH or trace.MatType == MAT_TILE or trace.MatType == MAT_PLASTIC or trace.MatType == MAT_CONCRETE) then
self.Weapon:EmitSound(SGroundHit[math.random(1,#SGroundHit)])
else
self.Weapon:EmitSound(SGroundHit[math.random(1,#SGroundHit)])
end
end
if (SERVER) then
local hitposent = ents.Create("info_target")
local trace = self.Owner:GetEyeTrace()
local hitpos = trace.HitPos
end
end
end
function SWEP:SecondaryAttack()
return
end
SWEP.Animations = {
primaryattack = PLAYER_ATTACK1;
vmprimaryattack = ACT_VM_PRIMARYATTACK;
};
-- Animations.
local ActIndex = {}
ActIndex["pistol"] = ACT_HL2MP_IDLE_PISTOL
ActIndex["smg"] = ACT_HL2MP_IDLE_SMG1
ActIndex["grenade"] = ACT_HL2MP_IDLE_GRENADE
ActIndex["ar2"] = ACT_HL2MP_IDLE_AR2
ActIndex["shotgun"] = ACT_HL2MP_IDLE_SHOTGUN
ActIndex["rpg"] = ACT_HL2MP_IDLE_RPG
ActIndex["physgun"] = ACT_HL2MP_IDLE_PHYSGUN
ActIndex["crossbow"] = ACT_HL2MP_IDLE_CROSSBOW
ActIndex["melee"] = ACT_HL2MP_IDLE_MELEE
ActIndex["slam"] = ACT_HL2MP_IDLE_SLAM
ActIndex["normal"] = ACT_HL2MP_IDLE
ActIndex["knife"] = ACT_HL2MP_IDLE_KNIFE
ActIndex["melee2"] = ACT_HL2MP_IDLE_MELEE2
ActIndex["passive"] = ACT_HL2MP_IDLE_PASSIVE
ActIndex["fist"] = ACT_HL2MP_IDLE_FIST
function SWEP:SetHoldType(t)
local index = ActIndex[t]
if (index == nil) then
Msg("SWEP:SetWeaponHoldType - ActIndex[ \""..t.."\" ] isn't set!\n")
return
end
self.ActivityTranslate = {}
self.ActivityTranslate [ ACT_MP_STAND_IDLE ] = index
self.ActivityTranslate [ ACT_MP_WALK ] = index+1
self.ActivityTranslate [ ACT_MP_RUN ] = index+2
self.ActivityTranslate [ ACT_MP_CROUCH_IDLE ] = index+3
self.ActivityTranslate [ ACT_MP_CROUCHWALK ] = index+4
self.ActivityTranslate [ ACT_MP_ATTACK_STAND_PRIMARYFIRE ] = index+5
self.ActivityTranslate [ ACT_MP_ATTACK_CROUCH_PRIMARYFIRE ] = index+5
self.ActivityTranslate [ ACT_MP_RELOAD_STAND ] = index+6
self.ActivityTranslate [ ACT_MP_RELOAD_CROUCH ] = index+6
self.ActivityTranslate [ ACT_MP_JUMP ] = index+7
self.ActivityTranslate [ ACT_RANGE_ATTACK1 ] = index+8
if t == "normal" then
self.ActivityTranslate [ ACT_MP_JUMP ] = ACT_HL2MP_JUMP_SLAM
end
if t == "passive" then
self.ActivityTranslate [ ACT_MP_CROUCH_IDLE ] = ACT_HL2MP_CROUCH_IDLE
end
self:SetupWeaponHoldTypeForAI(t)
end
function SWEP:TranslateActivity(act)
if (self.Owner:IsNPC()) then
if (self.ActivityTranslateAI[act]) then
return self.ActivityTranslateAI[act]
end
return -1
end
if (self.ActivityTranslate[act] != nil) then
return self.ActivityTranslate[act]
end
return -1
end
It's been a while since I watched these so I don't know if it's applicable anymore but if I do remember correctly you have to use Player/LagCompensation
for melee sweps specifically:
https://www.youtube.com/watch?v=Nw-T7fksUJU&index=11&list=PLLAN7OC4G99Sx65F38iYoqv2J1OoaiJse
Where in the code would I put that? I don't see anywhere where it'd be necessary for my swep but I'm a noob.
Sorry, you need to Log In to post a reply to this thread.