AddCSLuaFile( "cl_init.lua" ) AddCSLuaFile( "shared.lua" ) include('shared.lua') ENT.health = 35 ENT.rotates = false ENT.CollideDamage = 7 ENT.LoopSound = "" ENT.Idle1 = "" ENT.Idle2 = "" ENT.Idle3 = "" ENT.Die = "" function ENT:Initialize() math.randomseed(CurTime()) self.exploded = false self.Entity:SetModel( "models/gibs/hgibs.mdl" ) self.Entity:PhysicsInit( SOLID_VPHYSICS ) -- Make us work with physics, self.Entity:SetMoveType( MOVETYPE_VPHYSICS ) --after all, gmod is a physics self.Entity:SetSolid( SOLID_VPHYSICS ) -- Toolbox //self.Entity:SetMaterial("models/props_lab/Tank_Glass001") //self.Entity:SetColor(0,191,255,235) //self.Entity:Ignite( 120, 40 ) self:SetHealth(self.health) self.dietime = CurTime() + 3 //local Sprite = ents.Create("env_sprite"); //Sprite:SetKeyValue( "renderfx", "14" ) //Sprite:SetKeyValue( "model", "sprites/glow02.vmt") //Sprite:SetKeyValue( "scale", "0.18") //Sprite:SetKeyValue( "spawnflags", "1") //Sprite:SetKeyValue( "angles", "0 0 0") //Sprite:SetKeyValue( "rendermode", "9") //Sprite:SetKeyValue( "renderamt", "220") //Sprite:SetKeyValue( "rendercolor", "0 191 255" ) //Sprite:Spawn() //Sprite:Activate() //Sprite:SetParent( Entity ) self.LoopSound = CreateSound(self,Sound(self.LoopSound)) self.LoopSound:PlayEx(4,100) //self.Entity:EmitSound( self.firesound , 500 , 100 ) local phys = self.Entity:GetPhysicsObject() if (phys:IsValid()) then phys:Wake() phys:EnableGravity(false) end end function ENT:OnTakeDamage( dmginfo ) self.Entity:TakePhysicsDamage( dmginfo ) self:SetHealth(self:Health() - dmginfo:GetDamage()) if self:Health() <= 0 then ents.Create("prop_physics") end end function ENT:PhysicsCollide() local phys = self.Entity:GetPhysicsObject() if (phys:IsValid()) then phys:ApplyForceCenter(Vector(0,70,20)) end end function ENT:Think() //enemy selection and activation. local enttable = ents.FindByClass("npc_*") local monstertable = ents.FindByClass("monster_*") table.Add(monstertable,enttable)//merge for _, x in pairs(monstertable) do if self:Health() < 0 then return end if (x:GetClass() != self:GetClass() && x:GetClass() != "npc_grenade_frag" && x:IsNPC()) then x:AddEntityRelationship( self, 1, 10 ) end end self:FindEnemyDan() //movement local phys = self.Entity:GetPhysicsObject() if (phys:IsValid()) then local wantedvector = (self.Enemy:GetPos() - self:GetPos() + Vector(0,0,56)) local wantedangle = (self.Enemy:GetPos() - self:GetPos() + Vector(0,0,56)):Angle() local currentangle = Angle(20,self:GetAngles().y,0) local anglediff = self:GetAngleDiff(wantedangle.y,currentangle.y) if anglediff > 5 then print("turning positive") local phy = self:GetPhysicsObject() if phy:IsValid() then local velocity = phy:GetVelocity() phy:SetAngle( currentangle + Angle(0,2,0) ) phy:SetVelocity(velocity) end elseif anglediff < -5 then print("turning negative") local phy = self:GetPhysicsObject() if phy:IsValid() then local velocity = phy:GetVelocity() phy:SetAngle( currentangle + Angle(0,-2,0) ) phy:SetVelocity(velocity) end end local phy = self:GetPhysicsObject() if phy:IsValid() then phys:ApplyForceCenter(wantedvector:Normal()) end end end function ENT:GetAngleDiff(angle1, angle2) local result = angle1 - angle2 if result < -180 then result = result + 360 end if result > 180 then result = result - 360 end return result end function ENT:Touch(ent) ent:TakeDamage(self.CollideDamage) end function ENT:FindEnemyDan() local MyNearbyTargets = ents.FindInCone(self:GetPos(),self:GetForward(),4000,45) if (!MyNearbyTargets) then print( "No Targets!" ); return end for k,v in pairs(MyNearbyTargets) do if v:Disposition(self) == 1 || v:IsPlayer() then self:ResetEnemy() self:AddEntityRelationship( v, 1, 10 ) self.Enemy = v self.Alerted = true return end end end function ENT:ResetEnemy() local enttable = ents.FindByClass("npc_*") local monstertable = ents.FindByClass("monster_*") table.Add(monstertable,enttable)//merge //sort through each ent. for _, x in pairs(monstertable) do //print(x) if (!ents) then print( "No Entities!" ); return end if (x:GetClass() != self:GetClass()) then self:AddEntityRelationship( x, 2, 10 ) end end //self:AddRelationship("player D_NU 10") end