Lua errors 170 and 239

Hi guys,

i got a problem with the dans snpcs pack, the facehuggers alien ect don’t attack the player anymore, is there anyone over here who knows a script for this so it can be fixed?
the error it gives are 170 and 239 i have asked the uploader already but hes busy with other projects so he got no time atm so now im looking for a fix =-p
anyone here who can help?

thanks in advance =-)

Ah yes, lua error 170 and 239. I am very familiar with those.

Those digits are referring to the line number in the code that is giving the errors

Ok guys thanks so far my bad should have put some of the codes in here indeed=-p
so here are some of the lines from the facehuggers code
im an absolute noob with this but im guessing the error is somewhere in these codes

if self:GetEnemy() != nil then
if 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(SCHED_RANGE_ATTACK1 )
self:EmitSound( self.attackleap)
self.Leaping = true
self:SetVelocity( (self:GetEnemy():GetPos()-self:GetPos() + Vector(0,0,64)):Normalize() * self.LeapSpeed )
timer.Simple(2,setmeleefalse)
end
if (self:GetEnemy():GetPos():Distance(self:GetPos()) < 70) then
if self.MeleeAttacking == false then
if self.Leaping == false then
//self:SetSchedule( SCHED_MELEE_ATTACK1 )
else
timer.Create( “melee_attack_timer” … self.Entity:EntIndex( ), 0.25, 1, Attack_Melee )
self.MeleeAttacking = true;
self:SetLocalVelocity( Vector( 0, 0, 0 ) )
end
end
end
else
self.MeleeAttacking = false
self:FindEnemyDan()
end

line 149 till 171

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:SetEnemy(v)
self:UpdateEnemyMemory(v,v:GetPos())
local distance = self:GetPos():Distance(v:GetPos())
local randomsound = math.random(1,5)
if self.Alerted == false then
if randomsound == 1 then
self:EmitSound( self.alert1)
elseif randomsound == 2 then
self:EmitSound( self.alert2)
elseif randomsound == 3 then
self:EmitSound( self.alert3)
end
end
self.Alerted = true
return
end
end
//if ClosestDistance == 4000 then
//self:SetEnemy(NULL)
//end
end
*
this is line 235 till 262*

Paste the lua error in chat so we know what the issue is.
Also use the


 tags.

Also, if you can post the entire file in


 or [lua] tags, that'd help out too.

This is what it says ingame

Local file is overriding addon’s file! lua/entities/npc_facehugger/init.lua (Dan’s SNPC Pack)

[ERROR] lua/entities/npc_facehugger/init.lua:239: attempt to call method ‘Disposition’ (a nil value)

  1. FindEnemyDan - lua/entities/npc_facehugger/init.lua:239
  2. unknown - lua/entities/npc_facehugger/init.lua:170

TEST [lua/entities/npc_facehugger/cl_init.lua][lua/entities/npc_facehugger/init.lua]
TEST [lua/entities/npc_facehugger/init.lua][lua/entities/npc_facehugger/init.lua]
FOUND IN ADDON [132268360]
TEST [lua/entities/npc_facehugger/shared.lua][lua/entities/npc_facehugger/init.lua]

u guys need the complete facehugger lua to?
ok be prepared =-p


AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua')

ENT.Model = "models/facehugr.mdl"
ENT.health = 15
ENT.Alerted = false
ENT.Territorial = false
ENT.Bleeds = true
ENT.Leaps = true
ENT.Chasing = false
ENT.Flinches = false
ENT.FriendlyToPlayer = false
ENT.Damage = 300
ENT.AcidBlood = true
ENT.BleedsRed = false
//ENT.LeapDamage = 15
ENT.LeapSpeed = 600
ENT.LeapDistance = 200
ENT.MinLeapDistance = 0
ENT.MeleeAttacking = false;
ENT.Leaping = false
ENT.alert1 = ""
ENT.alert2 = ""
ENT.alert3 = ""
ENT.idle1 = ""
ENT.idle2 = ""
ENT.idle3 = ""
ENT.idle4 = ""
ENT.attack1 = ""
ENT.attack2 = ""
ENT.attack3 = ""
ENT.attackmiss1 = ""
ENT.attackmiss2 = ""
ENT.attackmiss3 = ""
ENT.attackleap = "npc/headcrab/attack1.wav"
ENT.hurt1 = ""
ENT.hurt2 = ""
ENT.hurt3 = ""
ENT.die1 = ""
ENT.die2 = ""
ENT.die3 = ""
ENT.dead = false;

local schedJump = ai_schedule.New( "Jump" ) 
schedJump:EngTask( "TASK_PLAY_SEQUENCE", ACT_JUMP )

function ENT:Initialize()
   self:SetModel( self.Model )
   self:SetHullType( HULL_TINY )
   self:SetHullSizeNormal()
   self:SetSolid( SOLID_BBOX )
   self:SetMoveType( MOVETYPE_STEP )
   self:CapabilitiesAdd( CAP_MOVE_GROUND )
   self:CapabilitiesAdd( CAP_SQUAD )
   self:CapabilitiesAdd( CAP_MOVE_JUMP )  
   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 randomsound = math.random(1,3)
		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
					//if v:Health() < self.Damage && v:IsNPC() then
						//self:SetEnemy(v)
						//self:PregnateTarget()
					//else
					v:TakeDamage( self.Damage, self ) 
					//end
					hit = true
				end
			end
		end
		if hit == false then
			if randomsound == 1 then
	      		self:EmitSound( self.attackmiss1)
			elseif randomsound == 2 then
	      		self:EmitSound( self.attackmiss2)
			elseif randomsound == 3 then
	      		self:EmitSound( self.attackmiss3)
			end
		else
			//make the sound
			if randomsound == 1 then
	      		self:EmitSound( self.attack1,430,math.random(80,120))
			elseif randomsound == 2 then
	      		self:EmitSound( self.attack2,430,math.random(80,120))
			elseif randomsound == 3 then
	      		self:EmitSound( self.attack3,430,math.random(80,120))
			end
		end
		timer.Create( "melee_done_timer" .. self.Entity:EntIndex( ), 1.7, 1, setmeleefalse )
	end
        //---------------


    //---------------
    if GetConVarNumber("ai_disabled") == 0 then
		if self:GetEnemy() != nil then
		self:UpdateEnemyMemory(self:GetEnemy(),self:GetEnemy():GetPos())
		end

		//make the sound
		local randomsound = math.random(1,120)
		if randomsound == 1 then
	      	self:EmitSound( self.idle1)
		elseif randomsound == 2 then
	      	self:EmitSound( self.idle2)
		elseif randomsound == 3 then
	      	self:EmitSound( self.idle3)
		elseif randomsound == 4 then
	      	self:EmitSound( self.idle4)
		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,10) == 1) then
				self:FindCloseEnemies()//get guys close to me
			//end
		end//Hit them.
		
		if self:GetEnemy() != nil then
				if 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(SCHED_RANGE_ATTACK1 )
					self:EmitSound( self.attackleap)
					self.Leaping = true
  					self:SetVelocity( (self:GetEnemy():GetPos()-self:GetPos() + Vector(0,0,64)):Normalize() * self.LeapSpeed )
					timer.Simple(2,setmeleefalse)
				end
				if (self:GetEnemy():GetPos():Distance(self:GetPos()) < 70) then
					if self.MeleeAttacking == false then
						if self.Leaping == false then
							//self:SetSchedule( SCHED_MELEE_ATTACK1 )
						else
							timer.Create( "melee_attack_timer" .. self.Entity:EntIndex( ), 0.25, 1, Attack_Melee )
							self.MeleeAttacking = true;
							self:SetLocalVelocity( Vector( 0, 0, 0 ) )
						end
					end
				end
		else
			self.MeleeAttacking = false
			self:FindEnemyDan()
		end
    end
    //---------------
    print(self:GetEnemy())
    print(self.Alerted)
    print(self.Chasing)

end

function ENT:SelectSchedule()
	if self:GetEnemy() != nil then
	if self:GetEnemy():GetPos():Distance(self:GetPos()) > 1750 then
		self:SetEnemy(NULL)
		alerted = true
	end
	end

	local function setleapfalse()
		self.Leaping = true
	end

	if self.Alerted == true && self:GetEnemy() != nil then
			self:UpdateEnemyMemory(self:GetEnemy(),self:GetEnemy():GetPos())
			self:SetSchedule(SCHED_CHASE_ENEMY)
			self.Chasing = true
	elseif self.Alerted == true then
		alerted = false
		self:SetSchedule(SCHED_IDLE_STAND)
	else
		self:SetSchedule(SCHED_RUN_RANDOM)
	end
end

function ENT:OnTakeDamage(dmg)
   if (self.TakingCover == false) && self.Flinches == true then
   	self:SetSchedule(SCHED_SMALL_FLINCH)//
   end 
   if self.Bleeds == true then
	self:SpawnBlood(dmg)
   end
   self:SetHealth(self:Health() - dmg:GetDamage())
   if math.random(4) == 1 then
	local sound_seed = math.random(1,7)
	if sound_seed == 1 then
	self:EmitSound( self.hurt1)
	elseif sound_seed == 2 then
	self:EmitSound( self.hurt2)
	elseif sound_seed == 3 then
	self:EmitSound( self.hurt3)
	end	
   end
   if dmg:GetAttacker():GetClass() != self:GetClass() && math.random(1,7) == 1 then
   	self:ResetEnemy()
   	self:AddEntityRelationship( dmg:GetAttacker(), 1, 10 )
   	self:SetEnemy(dmg:GetAttacker())
	self:SetSchedule(SCHED_CHASE_ENEMY)
	self.Chasing = true
   end
   if self:Health() <= 0 && !self.dead then //run on death
	self.dead = true;
	self:KilledDan()
   end
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:SetEnemy(v)
		self:UpdateEnemyMemory(v,v:GetPos())
		local distance = self:GetPos():Distance(v:GetPos())
	      	local randomsound = math.random(1,5)
		if self.Alerted == false then
			if randomsound == 1 then
	      		self:EmitSound( self.alert1)
			elseif randomsound == 2 then
	      		self:EmitSound( self.alert2)
			elseif randomsound == 3 then
	      		self:EmitSound( self.alert3)
			end
		end
		self.Alerted = true
	      	return
	    end
	end
	//if ClosestDistance == 4000 then
	//self:SetEnemy(NULL)
	//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


function ENT:FindCloseEnemies()
	local MyNearbyTargets = ents.FindInCone(self:GetPos(),self:GetForward(),250,45)
	//local ClosestDistance = 3000
	if (!MyNearbyTargets) then print( "No Targets!" ); return end
	for k,v in pairs(MyNearbyTargets) do
	    if v:Disposition(self) == 1 || v:IsPlayer() then
		print(v:GetClass())

		self:ResetEnemy()
   		self:AddEntityRelationship( v, 1, 10 )
	      	self:SetEnemy(v)
		
		self.Alerted = true
	      	return
	    end
	end
end


function ENT:HasLOS()
	if self:GetEnemy() != nil then
	//local shootpos = self:GetAimVector()*(self:GetPos():Distance(self:GetEnemy():GetPos())) + self:GetPos()
	//local shootpos = self:GetEnemy():GetPos()
	local tracedata = {}

	tracedata.start = self:GetPos()
	tracedata.endpos = self:GetEnemy():GetPos()
	tracedata.filter = self

	local trace = util.TraceLine(tracedata)
	if trace.HitWorld == false then
		print("returned true!")
		return true
	else 
		return false
	end
	end
	print ("no enemy!")
	return false
end


function ENT:SpawnBlood(dmg)
   if self.AcidBlood then
	local entstoattack = ents.FindInSphere(self:GetPos(),75)
	for _,v in pairs(entstoattack) do
		if ( (v:IsNPC() || ( v:IsPlayer() && v:Alive())) && (v != self) && (v:GetClass() != self:GetClass()) || (v:GetClass() == "prop_physics")) && v.AcidBlood != true then
			v:TakeDamage( 3, self ) 
		end
	self:EmitSound( "alien/alien_acid.wav" ,430,math.random(80,120))
	end
   end
   if (self.Bleeds == true) then
   	local bloodeffect = ents.Create( "info_particle_system" )
	if self.BleedsRed == true then
   		bloodeffect:SetKeyValue( "effect_name", "blood_impact_red_01" )
	else
		bloodeffect:SetKeyValue( "effect_name", "blood_impact_yellow_01")
	end
        bloodeffect:SetPos( dmg:GetDamagePosition() ) 
	bloodeffect:Spawn()
	bloodeffect:Activate() 
	bloodeffect:Fire( "Start", "", 0 )
	bloodeffect:Fire( "Kill", "", 0.1 )
   end
   
end

function ENT:KilledDan()
	/*I Took some of silverlan's code for ragdolling, cause I didn't want to recode it :P*/
	//emit cry of death
	local deathseed = math.random(1,3)
	if     deathseed == 1 then
	  self:EmitSound( self.die1)
	elseif deathseed == 2 then
	  self:EmitSound( self.die2)
	elseif deathseed == 3 then
	  self:EmitSound( self.die3)
	end

	//create ragdoll
	local ragdoll = ents.Create( "prop_ragdoll" )
	ragdoll:SetModel( self:GetModel() )
	ragdoll:SetPos( self:GetPos() )
	ragdoll:SetAngles( self:GetAngles() )
	ragdoll:Spawn()
	ragdoll:SetSkin( self:GetSkin() )
	ragdoll:SetColor( self:GetColor() )
	ragdoll:SetMaterial( self:GetMaterial() )
	
	//my code
	undo.ReplaceEntity(self,ragdoll)
	cleanup.ReplaceEntity(self,ragdoll)

	//ignight ragdoll if on fire.
	if self:IsOnFire() then ragdoll:Ignite( math.Rand( 8, 10 ), 0 ) end

	//position bones the same way.
        for i=1,128 do
		local bone = ragdoll:GetPhysicsObjectNum( i )
		if IsValid( bone ) then
			local bonepos, boneang = self:GetBonePosition( ragdoll:TranslatePhysBoneToBone( i ) )
			bone:SetPos( bonepos )
			//bone:SetAngle( boneang )
		end
	end
	self:Remove()
end

function ENT:PregnateTarget()
	local target = self:GetEnemy()
	local targetragdoll = nil
	
	if target != nil && target != NULL && target != player && target:IsNPC() then 
		
		
		//create ragdoll
		local position = Vector(0,0,0)
		local targetragdoll = ents.Create( "prop_ragdoll" )
		targetragdoll:SetModel( target:GetModel() )
		targetragdoll:SetPos( target:GetPos() )
		targetragdoll:SetAngles( target:GetAngles() )
		targetragdoll:Spawn()
		targetragdoll:SetSkin( target:GetSkin() )
		targetragdoll:SetColor( target:GetColor() )
		targetragdoll:SetMaterial( target:GetMaterial() )
	
		//my code
		undo.ReplaceEntity(target,targetragdoll)
		cleanup.ReplaceEntity(target,targetragdoll)

		//position bones the same way.
        	for i=1,128 do
			local bone = targetragdoll:GetPhysicsObjectNum( i )
			if ValidEntity( bone ) then
				local bonepos, boneang = target:GetBonePosition( targetragdoll:TranslatePhysBoneToBone( i ) )
				if i == 1 then	
					position = bonepos
				end
				bone:SetPos( bonepos )
				bone:SetAngle( boneang )
			end
		end
		target:Remove()

		local chestburster_embryo = ents.Create("npc_chestburster_dormant")
		chestburster_embryo:SetPos(position)
		//constraint.Weld( chestburster_embryo, targetragdoll, 0, 1, 0, true )
		chestburster_embryo:Spawn()
		chestburster_embryo:Activate()
		print("created a npc_chestburster_dormant")
	else 
		return 
	end


   	local attachmentID=target:LookupAttachment("eyes");
	local attachment = target:GetAttachment(attachmentID) 

	/*I Took some of silverlan's code for ragdolling, cause I didn't want to recode it :P*/
	//emit cry of death
	local deathseed = math.random(1,3)
	if     deathseed == 1 then
	  self:EmitSound( self.die1)
	elseif deathseed == 2 then
	  self:EmitSound( self.die2)
	elseif deathseed == 3 then
	  self:EmitSound( self.die3)
	end

	//create ragdoll
	local ragdoll = ents.Create( "prop_ragdoll" )
	ragdoll:SetModel( self:GetModel() )
	ragdoll:SetPos( attachment.Pos )
	ragdoll:SetAngles( attachment.Ang + Angle(90,0,0) )
	ragdoll:Spawn()
	ragdoll:SetSkin( self:GetSkin() )
	ragdoll:SetColor( self:GetColor() )
	ragdoll:SetMaterial( self:GetMaterial() )
	
	//my code
	undo.ReplaceEntity(self,ragdoll)
	cleanup.ReplaceEntity(self,ragdoll)

	//ignight ragdoll if on fire.
	if self:IsOnFire() then ragdoll:Ignite( math.Rand( 8, 10 ), 0 ) end

	//position bones the same way.
        for i=1,128 do
		local bone = ragdoll:GetPhysicsObjectNum( i )
		if ValidEntity( bone ) then
			local bonepos, boneang = self:GetBonePosition( ragdoll:TranslatePhysBoneToBone( i ) )
			bone:SetPos( bonepos )
			bone:SetAngle( boneang )
		end
	end
	if( GetConVarNumber("ai_keepragdolls") == 0 ) then
		ragdoll:SetCollisionGroup( 1 )//COLLISION_GROUP_DEBRIS )
		ragdoll:Fire( "FadeAndRemove", "", 7 )
	end
	self:Remove()
end

Replace:


if v:Disposition(self) == 1 || v:IsPlayer() then

with


if self:Disposition( v ) == D_HT || v:IsPlayer() then

in 2 places to fix the error. It’s allowing the player to be targeted but Disposition is NPC function, not a player function.

Alternatively, you could use:


local META_PLAYER = FindMetaTable( "Player" );
local META_NPC = FindMetaTable( "NPC" );

function META_PLAYER:Disposition( _ent )
	return META_NPC.Disposition( _ent, self ) || D_ER;
end

or simply:


local META_PLAYER = FindMetaTable( "Player" );

function META_PLAYER:Disposition( _ent )
	return ( IsValid( _ent ) && _ent:IsNPC( ) ) && _ent:Disposition( self ) || D_ER;
end

in addons/acecool/lua/autorun/server/sv_fix_player_calling_npc_disposition.lua

-edit- changed 1 with D_HT from http://wiki.garrysmod.com/page/Enums/D

Hey thanks man it works again Nice!!
thanks for the help :wink: