• Help me to finish this,please
    0 replies, posted
I have some problems to make it shoot npcs and explosives... and it makes a lot of erros when the entity is destroyed... Here is the code.. Launcher and stool.. Launcher [lua]include( 'shared.lua' ) AddCSLuaFile("shared.lua") AddCSLuaFile("cl_init.lua") ENT.InitialHealth =500 //Spawned by player function ENT:SpawnFunction( ply, tr ) if ( !tr.Hit ) then return end local SpawnPos = tr.HitPos local ent = ents.Create( "crox_antiair_launcher" ) ent:SetPos( SpawnPos + Vector(0,0,40) ) --ent:SetAngles(ply:EyeAngles()) --ent:SetOwner(ply) ent:Spawn() ent:Activate() ent:DropToFloor() ent:SetVar("Team",ply:Team()) Msg("Turret spawned:" .. ent .. "\n") return ent end function ENT:Initialize() if not (WireAddon == nil) then self.Inputs = Wire_CreateInputs(self.Entity, { "Activate" }) end Msg("Turret init\n") self.Entity:SetNWInt("pitch", 20) self.HasTarget = false self.NextFire = 0 self.MaxRange = 2000 self.MinRange = 500 self.AttackPlayers = false self.AttackOwner = false self.AttackThrusters = false self.AttackHoverballs = false self.AttackNPCs = false self.AttackExplosives = false -- Set our initial health self:SetxHealth(self.InitialHealth) self.Entity:SetModel( "models/props_borealis/bluebarrel001.mdl" ) self.Entity:PhysicsInit( SOLID_VPHYSICS ) self.Entity:SetMoveType( MOVETYPE_NONE ) self.Entity:SetUseType(SIMPLE_USE) self:SetEnabled(false) local phys = self.Entity:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() end --self.Entity:SetCollisionBounds( Vector( -60, -60, -60 ), Vector( 60, 60, 60 ) ) end function ENT:TriggerInput(iname, value) --wire inputs if (iname == "Activate") then if (value > 0) then self:SetEnabled(true) end elseif (value <= 0) then if self:SetEnabled(true) then self:SetEnabled(false) end end end function ENT:SetxHealth(amt) self.Entity:SetNetworkedInt("health",amt) end function ENT:GetxHealth() return self:GetNetworkedInt("health",-1) end function ENT:OnTakeDamage(dmg) local health=self:GetxHealth() self:SetxHealth(health-dmg:GetDamage()) local health=self:GetxHealth() -- Is it dead yet? if health<1 then self.Entity:Boom() self.Entity:Remove() end end function ENT:Boom() -- Make an explosion effect local effectdata = EffectData() effectdata:SetOrigin( self.Entity:GetPos() ) util.Effect( "Explosion", effectdata, true, true ) util.BlastDamage( self.Entity, self.Entity, self.Entity:GetPos(), 150, 150) end --Turns and aims at target function ENT:TakeAim(e) local d = e:GetPos() - self.Entity:GetPos() local a = d:Angle() self.Entity:SetAngles(Angle(0,a.y,0)) self.Entity:SetNWInt("pitch",a.p) end function ENT:CanFire() return CurTime() > self.NextFire end function ENT:CreateMissile(p,a) m = ents.Create( "crox_antiair_heatseeker" ) m:SetPos( p ) m:SetAngles( a ) m:SetVar("Target",self.Target) m:Spawn() m:Activate() end function ENT:LaunchPrimary() Msg("Fireing\n") self.Entity:EmitSound( Sound("Weapon_RPG.Single") ) local p1 = self.Entity:LocalToWorld(Vector(0,15,0)) local p2 = self.Entity:LocalToWorld(Vector(0,-15,0)) local d = self.Target:GetPos() - p1 local a = d:Normalize() self:CreateMissile(p1 + (a*t),a) self:CreateMissile(p2 + (a*t),a) self.NextFire = CurTime() + 1.5 end function ENT:LoseTarget() self.Target = nil self.HasTarget = false end function ENT:AquireTarget() local entities=ents.FindInSphere(self.Entity:GetPos(),self.MaxRange) for k,v in pairs(entities) do local vec = v:GetPos() local pAng= vec - self.Entity:LocalToWorld(Vector(0,0,50)) local pitch = pAng:Angle().p if v:IsValid() && pitch > 0 && self:isHostile(v) then self.Target = v self.HasTarget = true return end end end --Entity Think Function function ENT:Think() if self.HasTarget then if !self:isHostile(self.Target) then -- Target has bein pacified? self:LoseTarget() self:AquireTarget() return end if self.Target:IsValid() then self:TakeAim(self.Target) if self.Enabled && self:CanFire() then self:LaunchPrimary() end end else --No Target self:AquireTarget() end end function ENT:SetEnabled(v) self.Enabled = v if self.Enabled then self.Entity:SetColor(100,255,100,255) end if !self.Enabled then self.Entity:SetColor(255,100,100,255) end end --Determin wether we should shoot at target function ENT:isHostile(ent) if !ent:IsValid() then return false end trace={} trace.start=self.Entity:GetPos() trace.endpos=ent:GetPos() trace.filter=self.Entity traceRes=util.TraceLine(trace) if traceRes.Entity ~= ent then --Only if we can actualy fit them directly or they will recive splash adamage local d = traceRes.HitPos - ent:GetPos() if d:Length() > 75 then return false end end if ent:GetClass() == "gmod_hoverball" && self.AttackHoverballs then return true end if ent:GetClass() == "gmod_thruster" && self.AttackThrusters then return true end if (ent:IsNPC() && ent:Health() > 0) and self.AttackNPCs then return true end if ent:IsPlayer() && self.AttackPlayers then if self:GetPlayer() == ent then return self.AttackOwner end return false end if (ent:GetClass() == "drone" && ent:GetClass() == "staff_pulse" && ent:GetClass() == "staff_pulse_stationary" && ent:GetModel() == "models/\props_phx/amraam.mdl" && ent:GetModel() == "models/weapons/W_missile_launch.mdl" && ent:GetModel() == "models/props_phx/mk-82.mdl" && ent:GetModel() == "models/props_phx/ww2bomb.mdl" && ent:GetModel() == "models/props_phx/torpedo.mdl" && ent:GetModel() == "models/props_c17/canister01a.mdl" && self.AttackExplosives) then return true end return false end --Enable/ Disable the turret function ENT:Use( activator, caller ) if(activator ~= self:GetPlayer()) then return end self:SetEnabled(!self.Enabled) end [/lua] STOOL [lua] TOOL.Category = "Destruction" TOOL.Name = "Anti Air Turrett" TOOL.Command = nil TOOL.ConfigName = "" if ( CLIENT ) then language.Add( "Tool_Launcher_Turret_name", "Anti-Aircraft Turret" ) language.Add( "Tool_Launcher_Turret_desc", "Used to shoot down thrusters and hover balls." ) language.Add( "Tool_Launcher_Turret_0", "Creates Turret" ) language.Add( "Tool_Launcher_Turret_1", "" ) language.Add( "Launcher_TurretTool_attackowner", "Attack Owners stuff?" ) language.Add( "Launcher_TurretTool_attackplayers", "Shoot players aswell" ) language.Add( "Launcher_TurretTool_attacknpcs", "Attack Npcs?" ) language.Add( "Launcher_TurretTool_attackthrusters", "Attack Thrusters" ) language.Add( "Launcher_TurretTool_attackhoverballs", "Attack Hoverballs" ) language.Add( "Launcher_TurretTool_attackexplosives", "Attack Missiles,Bombs,Rockets,Drones ect" ) language.Add( "Launcher_TurretTool_enabled", "Start Enabled" ) language.Add( "Launcher_TurretTool_maxrange", "Maximum Range" ) language.Add( "Launcher_TurretTool_minrange", "Minimum Range" ) language.Add( "Undone_Launcher_Turret", "Undone Launcher" ) end --TOOL.ClientConVar[ "force" ] = "1500" TOOL.ClientConVar[ "attackowner" ] = "0" TOOL.ClientConVar[ "attackplayers" ] = "0" TOOL.ClientConVar[ "attackthrusters" ] = "0" TOOL.ClientConVar[ "attackhoverballs" ] = "0" TOOL.ClientConVar[ "attacknpcs" ] = "0" TOOL.ClientConVar[ "attackexplosives" ] = "0" TOOL.ClientConVar[ "enabled" ] = "0" TOOL.ClientConVar[ "maxrange" ] = "3500" TOOL.ClientConVar[ "minrange" ] = "500" function TOOL:LeftClick( trace ) --`if !trace.HitWorld then return end local ent = ents.Create( "crox_antiair_launcher" ) local ply = self:GetOwner() ent:SetPos( trace.HitPos +
Sorry, you need to Log In to post a reply to this thread.