• Reset bone manipulations on weapon drop??
    1 replies, posted
Hey all, I don't know why but no matter what I do, I can't undo bone manipulations for a SWEP when a player drops a weapon (TTT gamemode). This SWEP manipulates/scales bones in the way that it renders. If the SWEP is holstered (player switches weapons) it calls a ResetBonePositions method which fixes the bones for when the player draws the new weapon out. However, if it is dropped no such fixes take place and you end up with a borked viewmodel for whichever weapon you pull out, like seen here: [url]http://i.imgur.com/PBPdx5U.jpg[/url] The above image is a deagle being drawn after dropping the SWEP. I tried calling ResetBonePositions using the OnDrop hook, but you need a viewmodel to manipulate bones and I cannot obtain a viewmodel of the gun owner inside the OnDrop hook. Here is the entire code for the SWEP: [code] /*--------------------------------------------------------- Think ---------------------------------------------------------*/ function SWEP:Think() if self.Owner:KeyDown(IN_SPEED) then self:SetWeaponHoldType("normal") else self:SetWeaponHoldType(self.HoldType) end if self.MoveTime and self.MoveTime < CurTime() and SERVER then self.MoveTime = nil end local vm = self.Owner:GetViewModel() vmOwner = vm end 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["sword"] = ACT_HL2MP_IDLE_MELEE2 ActIndex["passive"] = ACT_HL2MP_IDLE_PASSIVE ActIndex["fist"] = ACT_HL2MP_IDLE_FIST local ActIndex = { [ "pistol" ] = ACT_HL2MP_IDLE_PISTOL, [ "revolver" ] = ACT_HL2MP_IDLE_REVOLVER, [ "smg" ] = ACT_HL2MP_IDLE_SMG1, [ "grenade" ] = ACT_HL2MP_IDLE_GRENADE, [ "ar2" ] = ACT_HL2MP_IDLE_AR2, [ "shotgun" ] = ACT_HL2MP_IDLE_SHOTGUN, [ "rpg" ] = ACT_HL2MP_IDLE_RPG, [ "physgun" ] = ACT_HL2MP_IDLE_PHYSGUN, [ "crossbow" ] = ACT_HL2MP_IDLE_CROSSBOW, [ "melee" ] = ACT_HL2MP_IDLE_MELEE, [ "slam" ] = ACT_HL2MP_IDLE_SLAM, [ "normal" ] = ACT_HL2MP_IDLE, [ "fist" ] = ACT_HL2MP_IDLE_FIST, [ "melee2" ] = ACT_HL2MP_IDLE_MELEE2, [ "passive" ] = ACT_HL2MP_IDLE_PASSIVE, [ "knife" ] = ACT_HL2MP_IDLE_KNIFE } local vmOwner /*--------------------------------------------------------- Initialize ---------------------------------------------------------*/ function SWEP:Initialize() self:SetWeaponHoldType( self.HoldType ) end local LaserHitImpact = function(attacker, tr, dmginfo) local laserhit = EffectData() laserhit:SetOrigin(tr.HitPos) laserhit:SetNormal(tr.HitNormal) laserhit:SetScale(30) util.Effect("effect_fo3_laserhit", laserhit) return true end if (CLIENT) then SWEP.VElements = { ["alien"] = { type = "Model", model = "models/Halokiller38/fallout/weapons/Energy Weapons/laserrifle.mdl", bone = "v_weapon.Right_Arm", rel = "", pos = Vector(8.1, 1.809, 1.638), angle = Angle(152, -90.296, 1.475), size = Vector(1.001, 1.001, 1.001), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} } } SWEP.WElements = { ["alien"] = { type = "Model", model = "models/Halokiller38/fallout/weapons/Energy Weapons/laserrifle.mdl", bone = "ValveBiped.Bip01_R_Hand", rel = "", pos = Vector(0.456, 0.764, 2.724), angle = Angle(180, -90.001, 6.765), size = Vector(1, 1, 1), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} } } end SWEP.Base = "weapon_tttbase" SWEP.Kind = WEAPON_HEAVY SWEP.AmmoEnt = "item_ammo_smg1_ttt" SWEP.AutoSpawnable = false SWEP.PrintName = "Laser Rifle" SWEP.Slot = 2 SWEP.Spawnable = true SWEP.AdminSpawnable = false SWEP.HoldType = "ar2" SWEP.ViewModelFOV = 56 SWEP.ViewModelFlip = false SWEP.ViewModel = "models/weapons/v_rif_galil.mdl" SWEP.WorldModel = "models/weapons/w_pistol.mdl" SWEP.ShowViewModel = true SWEP.ShowWorldModel = false SWEP.ViewModelBoneMods = { ["v_weapon.Right_Arm"] = { scale = Vector(1, 1, 1), pos = Vector(-0.953, -0.772, -0.917), angle = Angle(0, 0, 0) }, ["v_weapon.Left_Arm"] = { scale = Vector(1, 1, 1), pos = Vector(0, 0, 0.136), angle = Angle(0, 0, 0) }, ["v_weapon.galil"] = { scale = Vector(0.009, 0.009, 0.009), pos = Vector(0, 0, 0), angle = Angle(0, 0, 0) } } SWEP.Primary.Sound = Sound("weapons/laserrifle/wpn_rifle_laser_fire_2d.wav") SWEP.Primary.Recoil = .01 SWEP.Primary.Damage = 45 SWEP.Primary.NumShots = 1 SWEP.Primary.Cone = 0 SWEP.Primary.ClipSize = 20 SWEP.Primary.Delay = 0.5 SWEP.Primary.DefaultClip = 20 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "smg1" SWEP.FiresUnderwater = true SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" /*--------------------------------------------------------- Muzzle Effect + Shell Effect ---------------------------------------------------------*/ SWEP.MuzzleEffect = "rg_muzzle_rifle" -- This is an extra muzzleflash effect -- Available muzzle effects: rg_muzzle_grenade, rg_muzzle_highcal, rg_muzzle_hmg, rg_muzzle_pistol, rg_muzzle_rifle, rg_muzzle_silenced, none SWEP.ShellEffect = "rg_shelleject" -- This is a shell ejection effect -- Available shell eject effects: rg_shelleject, rg_shelleject_rifle, rg_shelleject_shotgun, none SWEP.MuzzleAttachment = "1" -- Should be "1" for CSS models or "muzzle" for hl2 models SWEP.ShellEjectAttachment = "0" -- Should be "2" for CSS models or "1" for hl2 models SWEP.EjectDelay = 0 /*-------------------------------------------------------*/ SWEP.MuzzleEffect = "fo3_muzzle_laserrifle" -- This is an extra muzzleflash effect SWEP.MuzzleAttachment = "1" -- Should be "1" for CSS models or "muzzle" for hl2 models SWEP.ShellEjectAttachment = "0" -- Should be "2" for CSS models or "1" for hl2 models SWEP.RunSightsPos = Vector (-2.6657, 0, 3.5) SWEP.RunSightsAng = Vector (-20.0824, -20.5693, 0) SWEP.IronSightsPos = Vector(-5.5, 0, 2) SWEP.IronSightsAng = Vector(1, 0, -0.75) /*--------------------------------------------------------- Think ---------------------------------------------------------*/ function SWEP:SetWeaponHoldType( t ) local index = ActIndex[ t ] if (index == nil) then Msg( "SWEP:SetWeaponHoldType - ActIndex[ \""..t.."\" ] isn't set! (defaulting to normal)\n" ) t = "normal" 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 if t == "knife" || t == "melee2" then self.ActivityTranslate [ ACT_MP_CROUCH_IDLE ] = nil end self:SetupWeaponHoldTypeForAI( t ) self._InternalHoldType = t end function SWEP:PrimaryAttack() self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay ) self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) if ( !self:CanPrimaryAttack()
If [url]http://wiki.garrysmod.com/page/WEAPON/OnDrop[/url] is called AFTER the player drops the weapon ( and where it is too late to be of use ) then you could use my dev_addon ( when released ) or copy a few files from my dev_base into an addon... If OnDrop does work, I'd suggest using it. [url]https://bitbucket.org/Acecool/acecooldev_base/src/master/gamemode/shared/_definitions/__metatables.lua?at=master[/url] [url]https://bitbucket.org/Acecool/acecooldev_base/src/master/gamemode/shared/hooks/playerdroppedweapon/sh_gm_playerdroppedweapon.lua?at=master[/url] [url]https://bitbucket.org/Acecool/acecooldev_base/src/master/gamemode/shared/hooks/playerdroppedweapon/sv_gm_canplayerdropweapon.lua?at=master[/url] [url]https://bitbucket.org/Acecool/acecooldev_base/src/master/gamemode/shared/hooks/playerdroppedweapon/sv_gm_playerdroppedweapon_logic.lua?at=master[/url] where sh_ files go into addons/acecool/lua/autorun/, and sv_ files go into addons/acecool/lua/autorun/server/ You will also need to add hook.Add( "Initialize", "blah", function( )... end ); around GM functions because addons load prior to GM becoming initialized. Additionally, you'll need to remove the networking* calls unless you use my networking addon ( just comment them out, or strip them ) but, if you want the shared features to work where bones are reset clientside then you'll need to create your own net message to call the hook on the client otherwise it'll all be serverside. This will add several new hooks: CanPlayerDropWeapon with arguments for the weapon and player, and PlayerDroppedWeapon with arguments for the weapon and player. With bones, you need to reset while the weapon is still being held, so add a new line prior to: [code]__META_PLAYER_DROP_WEAPON( self, _w ); [/code] with: [code]hook.Call( "PrePlayerDroppedWeapon", GAMEMODE, self, _w ); [/code] I'll include this in the next update and when my addon is out it'll be a bit more organized and won't require the changes... Then, you'll have 3 hooks to tie into regarding weapon drops... CanPlayerDropWeapon, PrePlayerDroppedWeapon and PlayerDroppedWeapon all with the weapon and player as arguments. You can reset the bones on PrePlayerDroppedWeapon...
Sorry, you need to Log In to post a reply to this thread.