So I made a SNPCs pack before GMod13 after GMod13 it broke my whole the biggest problem is when I kill the SNPC it spawns another of it Here is the code and other information:
------------------------------------------------------------------------------------------------
init.lua:
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')
ENT.Model = "models/darkmessiah/spider_regular.mdl"
ENT.health = 100
ENT.Alerted = false
ENT.Territorial = true
ENT.Bleeds = true
ENT.Leaps = false
ENT.Chasing = true
ENT.Flinches = true
ENT.FriendlyToPlayer = false
ENT.Damage = 30
ENT.AcidBlood = true
ENT.BleedsRed = false
//ENT.LeapDamage = 15
ENT.LeapSpeed = 1000
ENT.LeapDistance = 10000
ENT.MinLeapDistance = 200
ENT.MeleeAttacking = false;
ENT.Leaping = true
ENT.alert1 = Sound("spider/spider_misc1.wav")
ENT.alert2 = Sound("spider/spider_guardmode1.wav")
ENT.alert3 = Sound("spider/spider_guardmode2.wav")
ENT.idle1 = Sound("spider/spider_hail0.wav")
ENT.idle2 = Sound("spider/spider_hail1.wav")
ENT.idle3 = Sound("spider/spider_hail2.wav")
ENT.idle4 = Sound("spider/spider_misc0.wav")
ENT.attack1 = Sound("spider/spider_striking0.wav")
ENT.attack2 = Sound("spider/spider_striking1.wav")
ENT.attack3 = Sound("spider/spider_striking2.wav")
ENT.attack3 = Sound("spider/spider_striking3.wav")
ENT.attack4 = Sound("spider/spider_threat0.wav")
ENT.attack5 = Sound("spider/spider_threat1.wav")
ENT.attack6 = Sound("spider/spider_threat2.wav")
ENT.attackmiss1 = Sound("spidermonster/spidermonster_foothit0.wav")
ENT.attackmiss2 = Sound("spidermonster/spidermonster_foothit1.wav")
ENT.attackmiss3 = Sound("spidermonster/spidermonster_foothit2.wav")
ENT.attackmiss4 = Sound("spidermonster/spidermonster_foothit3.wav")
ENT.attackleap = Sound("spider/spider_guardmode0.wav")
ENT.hurt1 = Sound("spider/spider_ouch_strong0.wav")
ENT.hurt2 = Sound("spider/spider_ouch_strong1.wav")
ENT.hurt3 = Sound("spider/spider_ouch_strong2.wav")
ENT.die1 = Sound("spider/spider_dying0.wav")
ENT.die2 = Sound("spider/spider_dying1.wav")
ENT.die3 = Sound("spider/spider_dying2.wav")
ENT.dead = false
local schedJump = ai_schedule.New( "Jump" )
schedJump:EngTask( "TASK_PLAY_SEQUENCE", ACT_JUMP )
function ENT:Initialize()
local modelchoice = math.random(1,1)
if modelchoice == 1 then
self.Model = "models/darkmessiah/spider_regular.mdl"
end
self:SetModel( self.Model )
self:SetHullType( HULL_TINY )
self:SetHullSizeNormal()
self:SetCollisionBounds(Vector(80, 25, 80), Vector(0, 5, 0))
self:SetSolid( SOLID_BBOX )
self:SetMoveType( MOVETYPE_STEP )
self:CapabilitiesAdd( CAP_MOVE_GROUND )( CAP_SQUAD )
self:SetMaxYawSpeed( 5000 )
self:SetHealth(self.health)
end
function ENT:Think()
//---------------
local function setmeleefalse()
if self:Health() < 0 then return end
self.MeleeAttacking = false
self.Leaping = false
self:SetSchedule(SCHED_CHASE_ENEMY)
end
//---------------
local function Attack_Melee()
if self:Health() < 0 then return end
local entstoattack = ents.FindInSphere(self:GetPos() + self:GetForward()*75,47)
local hit = false
if entstoattack != nil then
for _,v in pairs(entstoattack) do
if ( (v:IsNPC() || ( v:IsPlayer() && v:Alive())) && (v != self) && (v:GetClass() != self:GetClass()) || (v:GetClass() == "prop_physics")) then
v:TakeDamage( self.Damage, self )
if v:IsPlayer() then
v:ViewPunch(Angle(math.random(-1,1)*self.Damage,math.random(-1,1)*self.Damage,math.random(-1,1)*self.Damage))
end
if v:GetClass() == "prop_physics" then
local phys = v:GetPhysicsObject()
if phys != nil && phys != NULL then
phys:ApplyForceOffset(self:GetForward()*1000,Vecto r(math.random(-1,1),math.random(-1,1),math.random(-1,1)))
end
end
hit = true
end
end
end
local randomsound = math.random(1,4)
if hit == false then
self:StopSound(self.idle1)
self:StopSound(self.idle2)
self:StopSound(self.idle3)
self:StopSound(self.idle4)
if randomsound == 1 then
self:EmitSound( self.attackmiss1,500,math.random(80,100))
elseif randomsound == 2 then
self:EmitSound( self.attackmiss2,500,math.random(80,100))
elseif randomsound == 3 then
self:EmitSound( self.attackmiss3,500,math.random(80,100))
elseif randomsound == 4 then
self:EmitSound( self.attackmiss4,500,math.random(80,100))
end
else
local randomsound = math.random(1,6)
//make the sound
self:StopSound(self.idle1)
self:StopSound(self.idle2)
self:StopSound(self.idle3)
self:StopSound(self.idle4)
if randomsound == 1 then
self:EmitSound( self.attack1,500,math.random(80,100))
elseif randomsound == 2 then
self:EmitSound( self.attack2,500,math.random(80,100))
elseif randomsound == 3 then
self:EmitSound( self.attack3,500,math.random(80,100))
elseif randomsound == 4 then
self:EmitSound( self.attack4,500,math.random(80,100))
elseif randomsound == 5 then
self:EmitSound( self.attack5,500,math.random(80,100))
elseif randomsound == 6 then
self:EmitSound( self.attack6,500,math.random(80,100))
end
end
timer.Create( "melee_done_timer" .. self.Entity:EntIndex( ), 0.5, 1, setmeleefalse )
end
//---------------
//---------------
if GetConVarNumber("ai_disabled") == 0 then
if self:GetEnemy() != nil then
self:UpdateEnemyMemory(self:GetEnemy(),self:GetEne my():GetPos())
end
//make the sound
local randomsound = math.random(1,120)
if randomsound == 1 then
self:StopSound(self.idle1)
self:StopSound(self.idle2)
self:StopSound(self.idle3)
self:StopSound(self.idle4)
//self:EmitSound( self.idle1,500,math.random(80,100))
elseif randomsound == 2 then
self:StopSound(self.idle1)
self:StopSound(self.idle2)
self:StopSound(self.idle3)
self:StopSound(self.idle4)
self:EmitSound( self.idle2,500,math.random(80,100))
elseif randomsound == 3 then
self:StopSound(self.idle1)
self:StopSound(self.idle2)
self:StopSound(self.idle3)
self:StopSound(self.idle4)
self:EmitSound( self.idle3,500,math.random(80,100))
elseif randomsound == 4 then
self:StopSound(self.idle1)
self:StopSound(self.idle2)
self:StopSound(self.idle3)
self:StopSound(self.idle4)
self:EmitSound( self.idle4,500,math.random(80,100))
end
//print( "Think start" );
//Get all the npc's and other entities.
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
if (!ents) then print( "No Entities!" ); return end
if (x:GetClass() != self:GetClass() && x:GetClass() != "npc_grenade_frag" && x:IsNPC()) then
x:AddEntityRelationship( self, 1, 10 )
end
end
if self.TakingCover == false then
//if(math.random(1,20) == 1) then
self:FindCloseEnemies()//get guys close to me
//end
end//Hit them.
if self:GetEnemy() != nil then
if math.random(1,15) == 1 && self:GetPos():Distance(self:GetEnemy():GetPos()) < self.LeapDistance && self:GetPos():Distance(self:GetEnemy():GetPos()) > self.MinLeapDistance && self.Leaps == true && self.Leaping == false then
self:SetSchedule(schedJump)
self.Leaping = true
self:SetVelocity( (self:GetEnemy():GetPos()-self:GetPos() + Vector(0,0,50)):Normalize() * self.LeapSpeed )
timer.Simple(0.25,setmeleefalse)
end
if (self:GetEnemy():GetPos():Distance(self:GetPos()) < 70) || self:HasPropInFrontOfMe() then
if self.MeleeAttacking == false then
if self.Leaping == false then
self:SetSchedule( SCHED_MELEE_ATTACK1 )
else
self:EmitSound( self.attackleap)
self:SetLocalVelocity( Vector( 0, 0, 0 ) )
end
timer.Create( "melee_attack_timer" .. self.Entity:EntIndex( ), 0.6, 1, Attack_Melee )
self.MeleeAttacking = true;
end
end
else
self:FindEnemyDan()
self.MeleeAttacking = false
end
local friends = ents.FindByClass("npc_spider_giant")
for _, x in pairs(friends) do
x:AddEntityRelationship( self, 3, 10 )
end
end
//---------------
print(self:GetEnemy())
print(self.Alerted)
print(self.Chasing)
end
function ENT:HasPropInFrontOfMe()
local entstoattack = ents.FindInSphere(self:GetPos() + self:GetForward()*75,47)
for _,v in pairs(entstoattack) do
if v:GetClass() == "prop_physics" then
return true
end
end
return false
end
function ENT:SelectSchedule()
if self:GetEnemy() != nil then
i
You might have figured the error out already, if not I hope this helps.[URL="https://docs.google.com/document/d/1khSuIYrAMkqXu7wlH5YRJNwz6hOH6Xqi5lqBhE3x6gA/edit"]
https://docs.google.com/document/d/1khSuIYrAMkqXu7wlH5YRJNwz6hOH6Xqi5lqBhE3x6gA/edit[/URL]
ValidEntity has been removed. Use IsValid instead.
if ( ValidEntity( ent ) ) then if ( IsValid( ent ) ) then
Thanks for the help![QUOTE=shinji144;38706735]You might have figured the error out already, if not I hope this helps.[URL="https://docs.google.com/document/d/1khSuIYrAMkqXu7wlH5YRJNwz6hOH6Xqi5lqBhE3x6gA/edit"]
https://docs.google.com/document/d/1khSuIYrAMkqXu7wlH5YRJNwz6hOH6Xqi5lqBhE3x6gA/edit[/URL]
ValidEntity has been removed. Use IsValid instead.
if ( ValidEntity( ent ) ) then if ( IsValid( ent ) ) then[/QUOTE]
Sorry, you need to Log In to post a reply to this thread.