• Needing help with swep making, weapon bullet.
    1 replies, posted
So im trying to learn lua & shit Im reading others code making simple stuff Im currently trying to modifie a swep called Pretty Light Gun, from : Lord Dude Im making it a gun, The bullet/light "ENT" are not going out of the gun, my gun point down and the bullet going up So my question is this: how do I make my bullet get out of the gun barrel, I thought of putting a offset, on where the bullet spawn, but then I would have to change it angle ? Here a video showing what im talking about, [video=youtube;Kvv2rGrwrnA]http://www.youtube.com/watch?v=Kvv2rGrwrnA[/video] Here SWEP:PrimaryAttack: [CODE]function SWEP:PrimaryAttack() if ( !self:CanPrimaryAttack() ) then return end if SERVER then local tr = self.Owner:GetEyeTrace() local ent = ents.Create("flaresmg_flare") local RecoilX = math.random(-self.Primary.Recoil*2500,self.Primary.Recoil*2500) local RecoilX2 = math.random(-self.Primary.Recoil*2500,self.Primary.Recoil*2500) local RecoilY = math.random(-self.Primary.Recoil*5000,self.Primary.Recoil*20000 ) if (ent:IsValid()) then ent:SetPos(self.Owner:GetShootPos()) ent:SetAngles(self.Owner:EyeAngles()) ent:Spawn() ent.Owner = self.Owner ent.Stay = false local phys = ent:GetPhysicsObject() local shot_length = tr.HitPos:Length() if (phys:IsValid()) then phys:ApplyForceCenter(self.Owner:GetAimVector():Ge tNormalized() * math.pow(shot_length, 5) * Vector(100000+RecoilX, 100000+RecoilX2, 100000-RecoilY)) end end end self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) self.Weapon:EmitSound( self.Primary.Sound ) self:TakePrimaryAmmo( 1 ) self.Owner:SetVelocity(self.Owner:GetVelocity()+se lf.Owner:GetAimVector()*-self.Primary.Recoil*15-self.Owner:GetVelocity()) self.Owner:ViewPunch( Angle( math.Rand(2,0.5) * self.Primary.Recoil, math.Rand(-1,1) *self.Primary.Recoil, 0 ) ) self:ShootEffects( self ) return true end [/CODE] Im also using a code im my gamemod that put a 3rd person cam on the player eye: [CODE]local head = pl:GetAttachment( pl:LookupAttachment("eyes") ); local AliveView = { // Cree la vue 1st person 3rd person cam origin = head.Pos+(angles:Forward()*3), //Si le joueur est en vie angles = Ang, fov = fov, }; return AliveView[/CODE] and with this the bullet are being spawn in the midle of my screen
So after much search I found a way, My bullet now spawn at my barrel and the angle is ok. The bullet now spawn on the weapon model position itself and with a offset same for angle I found out how to do it reading Kogitsune's Portable Radar code, so thanks I also had to modifie the player view because the gun point down and shoot down, so now the player look down, to do this I had to aply a angle offset but, I did not know how to add one to the view I allready had so now the view angle is stuck on the player model head angle with a offset. But now my view move/vibrate to mutch/fast, how could I smooth my view? Here a video of the bullet comming out of the barel and the view: [video=youtube;LermQjjyhho]http://www.youtube.com/watch?v=LermQjjyhho[/video] and Here the code of the gun itself: [CODE]if SERVER then AddCSLuaFile() resource.AddFile("materials/sprites/light_big01.vmt") resource.AddFile("materials/sprites/light_big01.vtf") resource.AddFile("materials/sprites/light_flare01.vmt") resource.AddFile("materials/sprites/light_flare01.vtf") resource.AddFile("materials/entities/weapon_flaresmg.png") SWEP.Weight = 5 SWEP.AutoSwitchTo = false SWEP.AutoSwitchFrom = false end if CLIENT then SWEP.PrintName = "lua_swep_base" SWEP.Slot = 3 SWEP.SlotPos = 1 SWEP.DrawAmmo = false SWEP.DrawCrosshair = false language.Add("Undone_Pretty Light", "Undone Pretty Light") end SWEP.Author = "Lord Dude + Slowhead" SWEP.Contact = "" SWEP.Purpose = "" SWEP.Instructions = "" SWEP.Spawnable = true; SWEP.AdminSpawnable = true; SWEP.ViewModel = "models/weapons/v_rif_ak47.mdl" SWEP.WorldModel = "models/weapons/w_rif_ak47.mdl" SWEP.HoldType = "Ar2" SWEP.Primary.Recoil = 1.5 SWEP.Primary.Damage = 40 SWEP.Primary.NumShots = 1 SWEP.Primary.Cone = 0.02 SWEP.Primary.ClipSize = 2500 SWEP.Primary.Delay = 0.07 SWEP.Primary.DefaultClip = 2500 SWEP.Primary.Automatic = true SWEP.Primary.Ammo = "smg1" SWEP.Primary.Sound = Sound( "Weapon_AK47.Single" ) SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = true SWEP.Secondary.Ammo = "none" SWEP.Barrel = { WorldModel = { Pos = { Up = 40, Right = 10.1, Forward = 60, }, Ang = { Up = 0, Right = -18, Forward = 0, }, }, } function SWEP:Initialize() self:SetWeaponHoldType(self.HoldType) end function SWEP:Think() end function SWEP:PrimaryAttack() if ( !self:CanPrimaryAttack() ) then return end if SERVER then pos = self:GetPos( ) ang = self:GetAngles( ) offset = ang:Right( ) * self.Barrel.WorldModel.Pos.Right + ang:Forward( ) * self.Barrel.WorldModel.Pos.Forward + ang:Up( ) * self.Barrel.WorldModel.Pos.Up pos = pos + offset ang:RotateAroundAxis( ang:Right( ), self.Barrel.WorldModel.Ang.Right ) ang:RotateAroundAxis( ang:Forward( ), self.Barrel.WorldModel.Ang.Forward ) ang:RotateAroundAxis( ang:Up( ), self.Barrel.WorldModel.Ang.Up ) local tr = self.Owner:GetEyeTrace() local ent = ents.Create("flaresmg_flare") local RecoilX = math.random(-self.Primary.Recoil*2500,self.Primary.Recoil*2500) local RecoilX2 = math.random(-self.Primary.Recoil*2500,self.Primary.Recoil*2500) local RecoilY = math.random(-self.Primary.Recoil*5000,self.Primary.Recoil*20000 ) if (ent:IsValid()) then ent:SetPos(pos) ent:SetAngles(ang) ent:Spawn() ent.Owner = self.Owner ent.Stay = false local phys = ent:GetPhysicsObject() local shot_length = tr.HitPos:Length() if (phys:IsValid()) then phys:ApplyForceCenter(ang:Forward( ) * math.pow(shot_length, 5) * Vector(100000+RecoilX, 100000+RecoilX2, 100000-RecoilY)) end end end self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay ) self.Weapon:EmitSound( self.Primary.Sound ) self:TakePrimaryAmmo( 1 ) self.Owner:SetVelocity(self.Owner:GetVelocity()+se lf.Owner:GetAimVector()*-self.Primary.Recoil*10-self.Owner:GetVelocity()) //self.Owner:ViewPunch( Angle( math.Rand(2,0.5) * self.Primary.Recoil, math.Rand(-1,1) *self.Primary.Recoil, 0 ) ) self:ShootEffects( self ) return true end[/CODE] and here the code of the view: [CODE]local head = pl:GetAttachment( pl:LookupAttachment("eyes") ); local tr = head.Ang+Angle(20,15,-20) local AliveView = { // Cree la vue 1st person 3rd person cam origin = head.Pos+(angles:Forward()*3), //Si le joueur est en vie angles = tr, fov = fov, }; return AliveView[/CODE]
Sorry, you need to Log In to post a reply to this thread.