• Trying to fix weapon hold type some old sweps, need some help.
    4 replies, posted
  • Avatar of Unkle Dada
  • Right, so I'm trying to fix the holdtypes of these old melee sweps: [URL]http://www.garrysmod.org/downloads/?a=view&id=95395[/URL] So far, it works. However, there's one problem. These sweps have a feature that allows to raise and lower the weapon by pressing the right mouse button, and this is supposed to change the third person hold type from sword/melee/knife to normal. However, these weapons will now use the normal holdtype regardless of whether the weapon is raised or lowered, and I have no idea how to fix that. This is my edit for the code for the baseball bat. The other weapons have pretty much identical code, so if I can fix the baseball bat, then I can fix the rest of the weapons. I just need to know how. [lua]if ( SERVER ) then AddCSLuaFile( "shared.lua" ) resource.AddFile( "models/weapons/v_basebat.mdl" ) resource.AddFile( "models/weapons/w_basebat.mdl" ) resource.AddFile( "materials/models/weapons/baseball_bat/Metal_bat.vmt" ) resource.AddFile( "materials/models/weapons/baseball_bat/Metal_bat.vtf" ) resource.AddFile( "materials/models/weapons/baseball_bat/Metal_bat_normal.vmt" ) resource.AddFile( "materials/models/weapons/baseball_bat/Metal_bat_normal.vtf" ) resource.AddFile( "materials/models/weapons/baseball_bat/envalpha.vtf" ) end --mode 1 = raised --mode 2 = lowered SWEP.PrintName = "Baseball Bat" SWEP.Category = "Weapons" SWEP.Slot = 0 SWEP.SlotPos = 4 SWEP.DrawAmmo = true SWEP.DrawCrosshair = true SWEP.ViewModelFlip = false SWEP.CSMuzzleFlashes = false SWEP.ViewModelFOV = 66 SWEP.ViewModel = "models/weapons/v_basebat.mdl" SWEP.WorldModel = "models/weapons/w_basebat.mdl" SWEP.HoldType = "" SWEP.Weight = 8 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.Author = "Patrick Hunt (HunteR4708)" SWEP.Contact = "" SWEP.Purpose = "Just a Baseball Bat" SWEP.Instructions = "Left click to hit, right click to raise or lower." SWEP.Primary.Sound = Sound("Weapon_Crowbar.Single") SWEP.Primary.Damage = 75 SWEP.Primary.NumShots = 0 SWEP.Primary.Recoil = 0.8 SWEP.Primary.Cone = 0.1 SWEP.Primary.Delay = 0.5 SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Tracer = 0 SWEP.Primary.Force = 2 SWEP.Primary.TakeAmmoPerBullet = false SWEP.Primary.Automatic = true SWEP.Primary.Ammo = "none" SWEP.Secondary.Sound = ("") SWEP.Secondary.Damage = 0 SWEP.Secondary.NumShots = 0 SWEP.Secondary.Recoil = 0 SWEP.Secondary.Cone = 0 SWEP.Secondary.Delay = 0 SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Tracer = 0 SWEP.Secondary.Force = 0 SWEP.Secondary.TakeAmmoPerBullet = false SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "" SWEP.IronSightsPos = Vector (0, 0, 0) SWEP.IronSightsAng = Vector (-66.4823, 4.1536, 0) function SWEP:Initialize() self:SetWeaponHoldType("sword"); self.mode = 1 self.changemode = 0 self.CanPrimary = true self.Weapon:SetNetworkedBool( "Ironsights", false ) self.Hit = { Sound( "physics/wood/wood_box_impact_hard1.wav" ), Sound( "physics/wood/wood_box_impact_hard2.wav" ), Sound( "physics/wood/wood_box_impact_hard3.wav" )}; self.FleshHit = { Sound( "physics/body/body_medium_impact_hard1.wav" ), Sound( "physics/body/body_medium_impact_hard2.wav" ), Sound( "physics/body/body_medium_impact_hard3.wav" ), Sound( "physics/body/body_medium_impact_hard4.wav" ), } ; end local IRONSIGHT_TIME = 0.25 /*--------------------------------------------------------- Name: GetViewModelPosition Desc: Allows you to re-position the view model ---------------------------------------------------------*/ function SWEP:GetViewModelPosition( pos, ang ) if ( !self.IronSightsPos ) then return pos, ang end local bIron = self.Weapon:GetNetworkedBool( "Ironsights" ) if ( bIron != self.bLastIron ) then self.bLastIron = bIron self.fIronTime = CurTime() if ( bIron ) then self.SwayScale = 1.0 self.BobScale = 1.0 else self.SwayScale = 0.3 self.BobScale = 0.1 end end local fIronTime = self.fIronTime or 0 if ( !bIron && fIronTime < CurTime() - IRONSIGHT_TIME ) then return pos, ang end local Mul = 1.0 if ( fIronTime > CurTime() - IRONSIGHT_TIME ) then Mul = math.Clamp( (CurTime() - fIronTime) / IRONSIGHT_TIME, 0, 1 ) if (!bIron) then Mul = 1 - Mul end end local Offset = self.IronSightsPos if ( self.IronSightsAng ) then ang = ang * 1 ang:RotateAroundAxis( ang:Right(), self.IronSightsAng.x * Mul ) ang:RotateAroundAxis( ang:Up(), self.IronSightsAng.y * Mul ) ang:RotateAroundAxis( ang:Forward(), self.IronSightsAng.z * Mul ) end local Right = ang:Right() local Up = ang:Up() local Forward = ang:Forward() pos = pos + Offset.x * Right * Mul pos = pos + Offset.y * Forward * Mul pos = pos + Offset.z * Up * Mul return pos, ang end /*--------------------------------------------------------- SetIronsights ---------------------------------------------------------*/ function SWEP:SetIronsights( b ) self.Weapon:SetNetworkedBool( "Ironsights", b ) end function SWEP:Precache() end function SWEP:Deploy() self.Weapon:SendWeaponAnim( ACT_VM_DRAW ) self:SetNextPrimaryFire(CurTime() + 0.7) self:SetNextSecondaryFire(CurTime() + 0.7) return true; end function SWEP:SecondaryAttack() if ( !self.IronSightsPos ) then return end bIronsights = !self.Weapon:GetNetworkedBool( "Ironsights", false ) self:SetIronsights( bIronsights ) self.NextSecondaryAttack = CurTime() + 0.3 if self.mode == 1 and CurTime() > self.changemode then self.changemode = CurTime() + 0.2 self.mode = 2 self:SetWeaponHoldType("normal"); self.CanPrimary = false elseif self.mode == 2 and CurTime() > self.changemode then self.changemode = CurTime() + 0.2 self.mode = 1 self:SetWeaponHoldType("sword"); self.CanPrimary = true end end function SWEP:PrimaryAttack() if self.mode == 1 then self.Weapon:SetNextSecondaryFire( CurTime() + self.Secondary.Delay ) self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) self.Weapon:EmitSound( self.Primary.Sound ) self:Slash() self.Weapon:SendWeaponAnim( ACT_VM_MISSCENTER ) self.Owner:SetAnimation( PLAYER_ATTACK1 ) end if self.mode == 2 then end end function SWEP:Slash() local trace = self.Owner:GetEyeTrace(); if trace.HitPos:Distance(self.Owner:GetShootPos()) <= 70 then if( trace.Entity:IsPlayer() or trace.Entity:IsNPC() or trace.Entity:GetClass()=="prop_ragdoll" ) then self.Owner:EmitSound( self.FleshHit[math.random(1,#self.FleshHit)] ); else self.Owner:EmitSound( self.Hit[math.random(1,#self.Hit)] ); end 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 = 8 bullet.Damage = 60 self.Owner:FireBullets(bullet) end end local ActIndex = {} ActIndex["pistol"] = ACT_HL2MP_IDLE_PISTOL ActIndex["smg"] = ACT_HL2MP_IDLE_SMG1 ActIndex["grenade"] = ACT_HL2
  • I would try getting rid of, [QUOTE]/*--------------------------------------------------------- Name: GetViewModelPosition Desc: Allows you to re-position the view model ---------------------------------------------------------*/ function SWEP:GetViewModelPosition( pos, ang ) if ( !self.IronSightsPos ) then return pos, ang end local bIron = self.Weapon:GetNetworkedBool( "Ironsights" ) if ( bIron != self.bLastIron ) then self.bLastIron = bIron self.fIronTime = CurTime() if ( bIron ) then self.SwayScale = 1.0 self.BobScale = 1.0 else self.SwayScale = 0.3 self.BobScale = 0.1 end end local fIronTime = self.fIronTime or 0 if ( !bIron && fIronTime < CurTime() - IRONSIGHT_TIME ) then return pos, ang end local Mul = 1.0 if ( fIronTime > CurTime() - IRONSIGHT_TIME ) then Mul = math.Clamp( (CurTime() - fIronTime) / IRONSIGHT_TIME, 0, 1 ) if (!bIron) then Mul = 1 - Mul end end local Offset = self.IronSightsPos if ( self.IronSightsAng ) then ang = ang * 1 ang:RotateAroundAxis( ang:Right(), self.IronSightsAng.x * Mul ) ang:RotateAroundAxis( ang:Up(), self.IronSightsAng.y * Mul ) ang:RotateAroundAxis( ang:Forward(), self.IronSightsAng.z * Mul ) end local Right = ang:Right() local Up = ang:Up() local Forward = ang:Forward() pos = pos + Offset.x * Right * Mul pos = pos + Offset.y * Forward * Mul pos = pos + Offset.z * Up * Mul return pos, ang end [/QUOTE] if it still doesn't work then it has something to do with "SetIronSights" which I cannot help with. (If the other sweps don't have the lower or raising of the weapon, even one swep.. try to look through both files and see what you need to change to make it stop. Sorry if this didn't help.
  • Avatar of wishbone
  • I don't understand what line 188 to 198 is doing... Wouldn't this work though? [lua]function SWEP:Initialize() self:SetWeaponHoldType("melee2") end[/lua] Also I don't think "sword" is a proper holdtype, though i'm not really sure.
  • Avatar of Unkle Dada
  • [QUOTE=StpdKlown;35842785]I would try getting rid of, if it still doesn't work then it has something to do with "SetIronSights" which I cannot help with. (If the other sweps don't have the lower or raising of the weapon, even one swep.. try to look through both files and see what you need to change to make it stop. Sorry if this didn't help.[/QUOTE] That didn't work, and only caused the viewmodel to not move out of the way like it should when you press the right mouse button to lower it. [editline]6th May 2012[/editline] [QUOTE=wishbone;35843383]I don't understand what line 188 to 198 is doing... Wouldn't this work though? function SWEP:Initialize() self:SetWeaponHoldType("melee2") end Also I don't think "sword" is a proper holdtype, though i'm not really sure.[/QUOTE] As far as I can tell, lines 188 to 198 are supposed to make the player visibly lower or raise their weapon when you press the right mouse button. It doesn't seem to happen, and in third person, it will look like the weapon is lowered regardless of whether you have it set to be lowered or not. It will function normally, it just won't change to the melee holdtype in attack mode. Yes, sword is supposed to be melee2, although replacing every instance of "sword" with "melee2" didn't help.