• Melee SWEP base
    3 replies, posted
Is there any melee SWEP base that I can use? Because after searching in Google and then I found this: [url]http://www.facepunch.com/threads/showthread.php?t=829230[/url] And then I tried to use the swep_crowbar but it errored The default weapon_base doesn't have support for melee weapon
No wonder it errored: [code]14th October 2009[/code]
Now I feel like working on a melee weapon base, hmm. Surely you can find one that's been released publicly that's compatible with the latest GMod?
You don't need much to make a melee weapon. Over-ride the primary and secondary attack functions. For the primary, there is a new function :: [url]http://wiki.garrysmod.com/page/Entity/DispatchTraceAttack[/url] Entity:DispatchTraceAttack( CTakeDamageInfo damageInfo, table traceRes, Vector dir=traceRes.HitNormal ) Which would essentially be all you need for the primary attack. Here's an example of what a PrimaryAttack would look like ( I do this for my admin system, multiple weapons to choose from with one weapon and the admin-system menu integrated into it ) DistanceTrace is a custom function which returns distance, trace; from the player, DispatchTraceAttack takes care of this for you ( just set start-pos and end-pos.. end-pos is start-pos + ( aim-vector-normal * max-units ) ) which would make the code much shorter than below. The networking is just for ensuring all effects are only created clientside. [code]ADMIN_DEV_WEAPON_STUNSTICK = function ( _p, trace, self ) local _w = _p:GetActiveWeapon( ); local _d = _p:DistanceTrace( ); _w:SendWeaponAnim( ACT_VM_PRIMARYATTACK ); _p:SetAnimation(PLAYER_ATTACK1 ); if ( _d > 75 ) then return false; end if ( trace.HitWorld ) then _w:EmitSound("Weapon_StunStick.Melee_HitWorld"); networking:Broadcast( "ProcessEffect", trace.HitPos, trace.HitNormal, "StunstickImpact" ); return false; end if ( !IsValid( trace.Entity ) ) then return false; end if ( trace.Entity:IsPlayer( ) || trace.Entity:IsNPC( ) ) then _w:EmitSound("Weapon_StunStick.Melee_Hit") networking:Broadcast( "ProcessEffect", trace.HitPos, trace.HitNormal, { "StunstickImpact", "BloodImpact" } ); local _dmginfo = DamageInfo( ); _dmginfo:SetAttacker( _p ) _dmginfo:SetDamage( 25 ) _dmginfo:SetMaxDamage( 25 ) _dmginfo:SetInflictor( _p ) _dmginfo:SetDamageForce( Vector( 10000, 10000, 10000 ) ) _dmginfo:SetDamageType( DMG_SHOCK ) trace.Entity:TakeDamageInfo( _dmginfo ) else _w:EmitSound("Weapon_StunStick.Melee_HitWorld"); networking:Broadcast( "ProcessEffect", trace.HitPos, trace.HitNormal, "StunstickImpact" ); end end[/code] This should be more than enough to get you started!
Sorry, you need to Log In to post a reply to this thread.