• A simple turret
    5 replies, posted
Could someone take the time to fix this turret, make it aim after people, take damage (something that it apparently doesn't do now) and so on? I guess it would be a alright job for a good lua scripter! [lua] function TurretSpawn( ply ) local SpawnPos = ply:EyePos() barrel=ents.Create("prop_physics") barrel:SetModel("models/props_c17/oildrum001.mdl") barrel:SetPos(Vector(SpawnPos)) barrel:Spawn() bullet = {} bullet.Num=1 bullet.Src=barrel:GetPos() bullet.Dir=barrel:GetAngles():Forward() bullet.Spread=Vector(0.01,0.01,0) bullet.Tracer=1 bullet.Force=300 bullet.Damage=200 timer.Create( "shooter_timer", 1, 0, function() barrel:FireBullets(bullet) end) end concommand.Add("kb_spawnturret", TurretSpawn) [/lua] It would help really much!
think the best thing u can do is this: [lua] function TurretSpawn( ply ) local SpawnPos = ply:EyePos() barrel=ents.Create("prop_physics") barrel:SetModel("models/props_c17/oildrum001.mdl") barrel:SetPos(Vector(SpawnPos)) barrel:Spawn() timer.Create( "shooter_timer", 1, 0, function() bullet = {} bullet.Num=1 bullet.Src=barrel:GetPos() bullet.Dir=barrel:GetAngles():Forward() bullet.Spread=Vector(0.01,0.01,0) bullet.Tracer=1 bullet.Force=300 bullet.Damage=200 barrel:FireBullets(bullet) end) end concommand.Add("kb_spawnturret", TurretSpawn) [/lua]
this code should help you take what you need [lua] /* ====================================== AUTO_TURRET/gun gun attachment ====================================== */ AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include('shared.lua') /*--------------------------------------------------------- Name: Initialize ---------------------------------------------------------*/ function ENT:Initialize() self.Entity:SetModel( "models/weapons/w_smg1.mdl" ) // self.Entity:SetModel( "models/airboatgun.mdl" ) //self.Entity:PhysicsInit( SOLID_NONE ) self.Entity:SetMoveType( MOVETYPE_NONE ) self.Entity:SetSolid( SOLID_VPHYSICS ) //self.Entity:DrawShadow( false ) local headshot = ents.Create("info_target") self.Aimtarg = headshot self.Firing = false self.NextShot = 0 self.MaxRange = 1000 self.SawShit = 0 self.Beeptime = 0 util.PrecacheSound("buttons/blip2.wav") end /*--------------------------------------------------------- Name: FireShot Fire a bullet. ---------------------------------------------------------*/ function ENT:FireShot(targ) // bullet is just for effect, were gonna railgun this fucker. if ( self.NextShot > CurTime() || self.Body:GetNWBool("ison")==false) then return end self.NextShot = CurTime() + 0.34 // Make a sound if you want to. self.Entity:EmitSound( "Weapon_Pistol.Single" ) // Get the muzzle attachment (this is pretty much always 1) local Attachment = self.Entity:GetAttachment( 1 ) // Msg(Attachment .. "\n") // Get the shot angles and stuff. local shootOrigin = Attachment.Pos local shootAngles = self.Entity:GetAngles() local shootDir = shootAngles:Forward() if (self.Body:GetNWInt("upgrade")>0) then targ:TakeDamage(30, self.Entity:GetOwner(), self.Entity) else targ:TakeDamage(25, self.Entity:GetOwner(), self.Entity) end // Shoot a bullet local bullet = {} bullet.Num = 1 bullet.Src = shootOrigin bullet.Dir = shootDir bullet.Spread = Vector( 0, 0, 0 ) bullet.Tracer = 1 bullet.TracerName = "AirboatGunHeavyTracer" bullet.Force = 50 bullet.Damage = 0 bullet.Attacker = self.Entity:GetOwner() self.Entity:FireBullets( bullet ) // Make a muzzle flash local effectdata = EffectData() effectdata:SetOrigin( shootOrigin ) effectdata:SetAngle( shootAngles ) effectdata:SetScale( 1 ) util.Effect( "MuzzleEffect", effectdata ) end function ENT:Think() if (self.Body:IsBuilt()) then local nearesttarg = self.Entity local Attachment = self.Entity:GetAttachment( 1 ) local shootOrigin = Attachment.Pos for k, v in pairs( ents.FindInSphere(self.Entity:GetPos(), self.MaxRange*1.25)) do // if theres a spawn point, DONT FUCKING FIRE if (v:GetClass() == "info_player_deathmatch" || v:GetClass() == "info_player_rebel" || v:GetClass() == "info_player_combine" || v:GetClass() == "gmod_player_start" || v:GetClass() == "info_player_start" || v:GetClass() == "info_player_allies" || v:GetClass() == "info_player_axis" || v:GetClass() == "info_player_counterterrorist" || v:GetClass() == "info_player_terrorist") then nearesttarg = self.Entity return; end // only shoot at valid targets that could actually get hit, and dont shoot at any player matching any "ally" string local isally = false if v:IsPlayer() && self.Entity:GetOwner()!=v then if self.Entity:GetOwner():IsAllied(v) then isally = true end end /* if v:IsPlayer() && self.Entity:GetOwner()!=v then for l, w in pairs(self.Body:GetTable().AllyTable) do if ValidEntity(w) && w==v then isally = true end end end */ /*if ((string.find(string.lower(v:GetName()), string.lower(self.Body:GetNWString("ally"))) != nil && self.Body:GetNWString("ally")!="") || (string.find(string.lower(v:GetNWString("job")), string.lower(self.Body:GetNWString("jobally"))) != nil && self.Body:GetNWString("jobally")!="")) then isally = true end*/ local istarget = false if ((string.find(string.lower(v:GetName()), string.lower(self.Body:GetNWString("enemytarget"))) != nil && self.Body:GetNWString("enemytarget")!="")) then istarget = true end if ( (((v:GetClass()!="player" || !isally || istarget) && self.Body:GetNWBool("hatetarget")==false) || (v:GetClass()!="player" || (istarget && self.Body:GetNWBool("hatetarget")==true))) && ( (v:GetClass()=="player" && self.Entity:GetOwner()!=v) || (v:IsNPC() && v:GetClass() != "npc_heli_avoidsphere" && v:GetClass() != "npc_template_maker" && v:GetClass() != "npc_maker" && v:GetClass() != "npc_vehicledriver" && v:GetClass() != "npc_launcher" && v:GetClass() != "npc_heli_nobomb" && v:GetClass() != "npc_heli_avoidsphere" && v:GetClass() != "npc_heli_avoidbox" && v:GetClass() != "npc_furniture" && v:GetClass() != "npc_enemyfinder" && v:GetClass() != "npc_missiledefense" && v:GetClass() != "npc_bullseye" && v:GetClass() != "npc_apcdriver" && v:GetClass() != "monster_generic" && v:GetClass() != "info_npc_spawn_destination" && v:GetClass() != "generic_actor" && v:GetClass() != "cycler_actor" && v:GetClass() != "npc_antion_template_maker" && v:GetClass() != "npc_cranedriver" && v:GetClass() != "npc_sniper") ) ) then local tracerun = false local traceshit = {} traceshit.start = self.Entity:GetPos() traceshit.endpos = v:GetPos() traceshit.filter = { self.Body, v, self.Entity } // traceshit.mask = COLLISION_GROUP_PLAYER traceshit = util.TraceLine(traceshit) if (ValidEntity(traceshit.Entity) && !traceshit.HitWorld) then if (traceshit.Entity:GetVar("PropProtection")!=false) then local entowner = player.GetByUniqueID(traceshit.Entity:GetVar("PropProtection")) if (entowner==v) then tracerun=true end elseif (traceshit.Fraction==1) then tracerun=true end elseif (!traceshit.HitWorld) then tracerun = true end local tracehrun = false local traceshith = {} traceshith.start = self.Entity:GetPos() traceshith.endpos = v:GetPos()+Vector(0, 0, 30) traceshith.filter = { self.Body, v, self.Entity } // traceshith.mask = COLLISION_GROUP_PLAYER traceshith = util.TraceLine(traceshith) if (ValidEntity(traceshith.Entity) && !traceshith.HitWorld) then if (traceshith.Entity:GetVar("PropProtection")!=false) then local entowner = player.GetByUniqueID(traceshith.Entity:GetVar("PropProtection")) if (entowner==v) then tracehrun=true end elseif (traceshith.Fraction==1) then tracehrun=true end elseif (!traceshith.HitWorld) then tracehrun = true end local tracebrun = false local traceshitb = {} traceshitb.start = self.Body:GetPos()+Vector(0,0,5) traceshitb.endpos = v:GetPos() traceshitb.filter = { self.Body, v, self.Entity } // traceshitb.mask = COLLISION_GROUP_PLAYER traceshitb = util.TraceLine(traceshitb) if (ValidEntity(traceshitb.Entity) && !traceshitb.HitWorld) then if (traceshitb.Entity:GetVar("PropProtection")!=false) then local entowner = player.GetByUniqueID(traceshitb.Entity:GetVar("PropProtection")) if (entowner==v) then tracebrun=true end elseif (traceshitb.Fraction==1) then tracebrun=true end elseif (!traceshitb.HitWorld) then tracebrun = true end local tracebhrun = false local traceshitbh = {} traceshitbh.start = self.Body:GetPos()+Vector(0,0,5) traceshitbh.endpos = v:GetPos()+Vector(0, 0, 30) traceshitbh.filter = { self.Body, v, self.Entity } // traceshitbh.mask = COLLISION_GROUP_PLAYER traceshitbh = util.TraceLine(traceshitbh) if (ValidEntity(traceshitbh.Entity) && !traceshitbh.HitWorld) then if (traceshitbh.Entity:GetVar("PropProtection")!=false) then local entowner = player.GetByUniqueID(traceshitbh.Entity:GetVar("PropProtection")) if (entowner==v) then tracebhrun=true end elseif (traceshitbh.Fraction==1) then tracebhrun=true end elseif (!traceshitbh.HitWorld) then tracebhrun = true end local tracewrun = false local traceshitw = {} traceshitw.start = self.Entity:GetPos() traceshitw.endpos = v:GetPos() traceshitw.filter = { self.Body, v, self.Entity } traceshitw.mask = COLLISION_GROUP_PLAYER traceshitw = util.
^ i did not understand 1 single bit of that shit but it looks like it would work. did you code in a body for it?
ye want the code for that also?
yes plz :D.. How do i make it spawnable though... lol that looks like it works and everything
Sorry, you need to Log In to post a reply to this thread.