• increase crowbar range/width
    13 replies, posted
I have a swep I'm working on that is a big sword, I have the model and animations down (as that is my skill), along with some simple lua code. The code uses the crowbar as a base and I feel it is too limited for a big sword. Is it possible to increase the range that I can hit with the weapon and change the hit area from a bullet hole to maybe a larger diameter? For the record, I don't really know how to program in lua, so I apologize for any ignorance in advance. Oh yeah, forgot to post this: [code] AddCSLuaFile( "shared.lua" ) SWEP.UseHands = true SWEP.Contact = "" SWEP.Author = "" SWEP.Instructions = "Left Click to attack" SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.ViewModelFOV = 70 SWEP.ViewModel = "models/weapons/v_frostmourne.mdl" SWEP.WorldModel = "models/weapons/w_crowbar.mdl" SWEP.HoldType = "crowbar" SWEP.FiresUnderwater = true SWEP.Primary.Damage = 100 SWEP.base = "stunstick" SWEP.Primary.ClipSize = -1 SWEP.Primary.DefaultClip = -1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "none" SWEP.Primary.Delay = 1 SWEP.Weight = 5 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false SWEP.Category = "Other" SWEP.PrintName = "The Lich King's Sword" SWEP.Slot = 1 SWEP.SlotPos = 1 SWEP.DrawAmmo = false SWEP.DrawCrosshair = true function SWEP:SecondaryAttack() end function SWEP:ShouldDropOnDie() return false end -- function SWEP:Reload() --To do when reloading -- end function SWEP:Think() -- Called every frame end function SWEP:Initialize() self:SetWeaponHoldType( "melee" ) end function SWEP:PrimaryAttack() self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) local spos = self.Owner:GetShootPos() local sdest = spos + (self.Owner:GetAimVector() * 70) local kmins = Vector(1,1,1) * -10 local kmaxs = Vector(1,1,1) * 10 local tr = util.TraceHull({start=spos, endpos=sdest, filter=self.Owner, mask=MASK_SHOT_HULL, mins=kmins, maxs=kmaxs}) -- Hull might hit environment stuff that line does not hit if not IsValid(tr.Entity) then tr = util.TraceLine({start=spos, endpos=sdest, filter=self.Owner, mask=MASK_SHOT_HULL}) end local hitEnt = tr.Entity -- effects if IsValid(hitEnt) then self.Weapon:SendWeaponAnim( ACT_VM_HITCENTER ) local edata = EffectData() edata:SetStart(spos) edata:SetOrigin(tr.HitPos) edata:SetNormal(tr.Normal) edata:SetEntity(hitEnt) if hitEnt:IsPlayer() or hitEnt:GetClass() == "prop_ragdoll" then util.Effect("BloodImpact", edata) end else self.Weapon:SendWeaponAnim( ACT_VM_MISSCENTER ) end if SERVER then self.Owner:SetAnimation( PLAYER_ATTACK1 ) end self.Weapon:SetNextPrimaryFire(CurTime() + .43) local trace = self.Owner:GetEyeTrace() if trace.HitPos:Distance(self.Owner:GetShootPos()) <= 75 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 = 3 bullet.Damage = 60 self.Owner:DoAttackEvent() self.Owner:FireBullets(bullet) self.Weapon:EmitSound("Weapon_Crowbar.Melee_Hit") else self.Weapon:EmitSound("Zombie.AttackMiss") self.Owner:DoAttackEvent() end end function SWEP:Deploy() return true; end function SWEP:Holster() return true; end [/code]
What crowbar as base? Show what code you already have.
Oh yeah, that'd probably help, sorry.
70 on this line is the range: [code]local sdest = spos + (self.Owner:GetAimVector() * 70)[/code] Change it to whatever you need. This line: [code]SWEP.AdminSpawnable = true[/code] Doesn't do anything for almost a year now. This line: [code]SWEP.base = "stunstick"[/code] Won't do anything. First it's SWEP.[b]B[/b]ase, and "stunstick" isn't a valid weapon base and you can [B]only[/B] use [B]Lua[/B] weapons as base.
Okay, and what about increasing the hit diameter? Right now it is only the size of a pistol shot, is it possible to make it as large as a shotgun blast (basically the majority of the player's screen)?
[QUOTE=xXpyroHatakeXx;43003303]Okay, and what about increasing the hit diameter? Right now it is only the size of a pistol shot, is it possible to make it as large as a shotgun blast (basically the majority of the player's screen)?[/QUOTE] You will have to perform traces in the areas that you want to give the illusion of a blade swiping.
I found the code for increasing the hit diameter and increased it(still playing with the numbers though, thus the # sign in the code): [code] bullet = {} bullet.Num = # bullet.Src = self.Owner:GetShootPos() bullet.Dir = self.Owner:GetAimVector() bullet.Spread = Vector(#, #, #) bullet.Tracer = 0 bullet.Force = 3 bullet.Damage = 120 //originally 60 [/code] BUT changing that 70 for the range didn't do anything.
[QUOTE=xXpyroHatakeXx;43004655]I found the code for increasing the hit diameter and increased it(still playing with the numbers though, thus the # sign in the code): [code] bullet = {} bullet.Num = # bullet.Src = self.Owner:GetShootPos() bullet.Dir = self.Owner:GetAimVector() bullet.Spread = Vector(#, #, #) bullet.Tracer = 0 bullet.Force = 3 bullet.Damage = 120 //originally 60 [/code] BUT changing that 70 for the range didn't do anything.[/QUOTE] Shooting several bullets with spread might simulate a larger range, but several of those bullets could hit the one target. You can increase the size of the trace in your original code by playing with the *10 after kmins and kmaxs. It is using those variables to define the size of the hull trace.
Well the spread was a bad idea, and I found where to modify the range [code]if trace.HitPos:Distance(self.Owner:GetShootPos()) <= 120 then[/code] I changed the *10 for kmin and kmax to higher values, but I'm not noticing any differences in-game.
Try multiplying the vector components themselves, like [code] local kmins = Vector(-10,-10,-10) local kmaxs = Vector(10,10,10) [/code]
[QUOTE=BFG9000;43005716]Try multiplying the vector components themselves, like [code] local kmins = Vector(-10,-10,-10) local kmaxs = Vector(10,10,10) [/code][/QUOTE] That won't make any difference, Vector(1,1,1)*-10 is the same as Vector(-10,-10,-10), but if you want to make a change to the code you only have to change 1 number instead of 3.
Don't you have to multiply it by the respective components? Unless you only want one component to be multiplied, at which point you'd have to define it after typing out the variable. like for a local variable that is an angle: angle.yaw * 10 ?
[QUOTE=BFG9000;43014881]Don't you have to multiply it by the respective components? Unless you only want one component to be multiplied, at which point you'd have to define it after typing out the variable. like for a local variable that is an angle: angle.yaw * 10 ?[/QUOTE] I'm not sure about Angles but I know for certain that if you multiply a Vector by a Number it multiplies all components.
[QUOTE=YoshieMaster;43016469]I'm not sure about Angles but I know for certain that if you multiply a Vector by a Number it multiplies all components.[/QUOTE] Angles and Vectors can both be multiplied by scalars.
Sorry, you need to Log In to post a reply to this thread.