• SWEP distance question
    6 replies, posted
I want to setup a few melee SWEP's but am not certain if there is a place in the code that I specify the distance, or if I have to actually make the weapon itself that distance.
You have to actually check the distance yourself, there is no base setting to setup a melee weapon. You first have to either trace or check distances to get where you're looking, then deal the damage. And please for the love of god, do NOT use entity:FireBullets() for a melee SWEP - take the time and write out the effects you want for it but don't use FireBullets() as they can go through fences and other props like that. [lua] function SWEP:PrimaryAttack() self.Weapon:SetNextPrimaryFire(CurTime() + .4) self.Owner:DoAttackEvent() local trace = self.Owner:GetEyeTrace() local distance = 75 --How far away from the player you want to allow the weapon to hit if trace.HitPos:Distance(self.Owner:GetShootPos()) <= distance then self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK) local dmg = DamageInfo() dmg:SetDamagePosition(trace.HitPos) dmg:SetDamage(10) dmg:SetDamageType(DMG_SLASH | DMG_CLUB) dmg:SetInflictor(self) dmg:SetAttacker(self:GetOwner()) trace.Entity:TakeDamageInfo(dmg) else self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK) end end [/lua]
on PrimaryAttack call [b][url=http://wiki.garrysmod.com/?title=Util.TraceLine]Util.TraceLine [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] there's an example down there that you can use. FREAKIN' NINJA :ninja: Also Feihc I think it's better to use a trace.
[QUOTE=JohnnyThunders;28879177]on PrimaryAttack call [b][url=http://wiki.garrysmod.com/?title=Util.TraceLine]Util.TraceLine [img_thumb]http://wiki.garrysmod.com/favicon.ico[/img_thumb][/url][/b] there's an example down there that you can use. FREAKIN' NINJA :ninja: Also Feihc I think it's better to use a trace.[/QUOTE] I did use a trace in mine =P I just did it the weird way and checked the distance from the shoot pos to the hitpos.
Um... Firebullets sounds really dumb for a melee choice but I'll keep that in mind.
It is dumb, yet tons of people do it because it's the easiest way to make one and it makes me rage every time I see it. People don't know the wonderful ease of TakeDamageInfo
[QUOTE=Feihc;28879399]It is dumb, yet tons of people do it because it's the easiest way to make one and it makes me rage every time I see it. People don't know the wonderful ease of TakeDamageInfo[/QUOTE] And versatiliness (is that a word?)
Sorry, you need to Log In to post a reply to this thread.