I recently downloaded an addon called NPC ai. It should make npcs target me and chase me on custom maps. Sorry if I'm putting this in the wrong section(Developer Discussion(since I'm using lua)/Help and support). Also, sv_init.lua has line 237 bolded and underlined
My error is:[CODE][ERROR] addons/npcai (chase you on custom maps)/lua/npcai/sv_init.lua:237: attempt to call method 'IsPlayer' (a nil value)
1. v - addons/npcai (chase you on custom maps)/lua/npcai/sv_init.lua:237
2. unknown - lua/includes/modules/hook.lua:82
[/CODE]
And sv_init.lua:[CODE]/*NPC AI MOD
BY: TB
File version 1.2 <- ill probably forget to change this so dont worry bout it*/
function AISetup.SetupSettings()
if(!sql.TableExists("aisetup3")) then
sql.Query("CREATE TABLE aisetup3(Active INTEGER NOT NULL, Reuse INTEGER NOT NULL, Turn INTEGER NOT NULL, Manh INTEGER NOT NULL, Grenades INTEGER NOT NULL, ManhA INTEGER NOT NULL, GrenadesA INTEGER NOT NULL, SquadsA INTEGER NOT NULL, Squads INTEGER NOT NULL, SquadsP INTEGER NOT NULL, SquadsJ INTEGER NOT NULL, SquadsF INTEGER NOT NULL, ChaseThink INTEGER NOT NULL);")
sql.Query("INSERT INTO aisetup3(Active, Reuse, Turn, Manh, Grenades, ManhA, GrenadesA, SquadsA, Squads, SquadsP, SquadsJ, SquadsF, ChaseThink) VALUES(1, 1, 1, 0, 1, 1, 5, 5, 1, 1, 1500, 500, 0.3)")
end
return sql.QueryRow("SELECT * FROM aisetup3 LIMIT 1")
end
AISetup.Config = AISetup.SetupSettings()
function AISetup.ApplySettings(ply, cmd, args)
if(!ply:IsAdmin()) then
return
end
local Active = tonumber(ply:GetInfo("NPC2_ai_Active") or 1)
local Reuse = tonumber(ply:GetInfo("NPC2_ai_Reuse") or 1)
local Turn = tonumber(ply:GetInfo("NPC2_ai_Turn") or 1)
local Manh = tonumber(ply:GetInfo("NPC2_ai_Manh") or 0)
local Grenades = tonumber(ply:GetInfo("NPC2_ai_Grenades") or 1)
local ManhA = tonumber(ply:GetInfo("NPC2_ai_ManhA") or 2)
local GrenadesA = tonumber(ply:GetInfo("NPC2_ai_GrenadesA") or 5)
local SquadsA = tonumber(ply:GetInfo("NPC2_ai_SquadsA") or 5)
local Squads = tonumber(ply:GetInfo("NPC2_ai_Squads") or 1)
local SquadsP = tonumber(ply:GetInfo("NPC2_ai_SquadsP") or 1)
local SquadsJ = tonumber(ply:GetInfo("NPC2_ai_SquadsJ") or 1500)
local SquadsF = tonumber(ply:GetInfo("NPC2_ai_SquadsF") or 500)
local ChaseThink = tonumber(ply:GetInfo("NPC2_ai_ChaseThink") or 0.3)
local zero=0
sql.Query("UPDATE aisetup3 SET Active = "..Active..", Reuse = "..Reuse..", Turn = "..Turn..", Manh = "..Manh..", Grenades = "..Grenades..", ManhA = "..ManhA..", GrenadesA = "..GrenadesA..", SquadsA = "..SquadsA..", Squads = "..Squads..", SquadsP = "..SquadsP..", SquadsJ = "..SquadsJ..", SquadsF = "..SquadsF..", ChaseThink = "..ChaseThink)
AISetup.Config = sql.QueryRow("SELECT * FROM aisetup3 LIMIT 1")
print(ply:Nick().." Changed the AI Settings.")
end
concommand.Add("NPC2_ai_apply", AISetup.ApplySettings)
//my attempt at something faster then findinsphere
local everything={}
local amount=1
local Squads = {}
local SquadsA = 0
local donts={}
donts[0]="npc_cscanner"
donts[1]="npc_hunter"
donts[2]="npc_rollermine"
donts[3]="npc_antlion"
donts[4]="npc_antlionguard"
donts[5]="npc_antlion_worker"
donts[6]="npc_fastzombie_torso"
donts[7]="npc_headcrab_fast"
donts[8]="npc_fastzombie"
donts[9]="npc_headcrab"
donts[10]="npc_headcrab_black"
donts[11]="npc_poisonzombie"
donts[12]="npc_headcrab_poison"
donts[13]="npc_zombie"
donts[14]="npc_zombie_torso"
donts[15]="npc_zombine"
donts[16]="npc_manhack"
function OnEntityCreated2( spawned )
if spawned:IsNPC() && spawned:IsValid() then
--[[
Use one of these to your liking:
WEAPON_PROFICIENCY_POOR
WEAPON_PROFICIENCY_AVERAGE
WEAPON_PROFICIENCY_GOOD
WEAPON_PROFICIENCY_VERY_GOOD
WEAPON_PROFICIENCY_PERFECT
]]
spawned:SetCurrentWeaponProficiency( WEAPON_PROFICIENCY_VERY_GOOD )
if(tonumber(AISetup.Config["Manh"]) == 1) then
if spawned:GetClass()=="npc_metropolice" then
spawned:SetKeyValue("manhacks" , tonumber(AISetup.Config["Manh"]))//gives the metro police manhacks
end
end
if(tonumber(AISetup.Config["Grenades"]) == 1) then
if spawned:GetClass()=="npc_combine_s" then
spawned:SetKeyValue("NumGrenades" , tonumber(AISetup.Config["GrenadesA"])) // gives the combine grenades and ar2 combine balls to shoot
end
end
spawned.wep=nil
spawned.distance=1500
spawned.division=500
spawned.Squad=nil
spawned.IsM=false
spawned.IsL=false
spawned.times=1
spawned.hits=0
spawned.blocked=false
spawned.cansquad=true
if spawned:GetClass()=="npc_fastzombie"||spawned:GetClass()=="npc_antlion" || spawned:GetClass()=="npc_antlion_worker" then
spawned.walkover=155
else
spawned.walkover=17
end
for h,l in pairs(donts) do
if spawned:GetClass()==l then
spawned.cansquad=false
end
end
if(tonumber(AISetup.Config["Reuse"]) == 1) then
local found=false
for i=0, amount do
if found==false then
local e=everything[i]
if e==nil||e:IsValid()==false then
everything[i]=spawned
found=true
end
if e!=nil && i==amount then
if e:IsValid() then
amount=amount+1
everything[amount]=spawned
found=true
end
end
end
end
else
amount=amount+1
everything[amount]=spawned
end
end
end
function MoveToPosition(object, x, y, z, movement)
object:SetLastPosition( Vector(x, y, z))
object:SetSchedule( movement )
end
function Move(v, enemy, finalpos)
//Gather where our npc should move in chunks of 500 or based on a number i gave them
//They can only move in a distance of 500 or less at a time
local divx=math.abs(v:GetPos().x-enemy:GetPos().x)
local divy=math.abs(v:GetPos().y-enemy:GetPos().y)
local perc=v.division/finalpos
xstep=divx*perc
ystep=divy*perc
local action=SCHED_FORCED_GO_RUN
//Make sure were in the right plane
local px=1
local py=1
if (enemy:GetPos().x-v:GetPos().x)<0 && xstep!=nil then
xstep=xstep*-1
px=px*-1
end
if (enemy:GetPos().y-v:GetPos().y)<0 && ystep!=nil then
ystep= ystep*-1
py=py*-1
end
if xstep!=nil && ystep!=nil then
//Set the Coordinate where the npc will be going
local cordx=v:GetPos().x+xstep
local cordy=v:GetPos().y+ystep
local tracedata = {}
tracedata.start = Vector(v:GetPos().x, v:GetPos().y, v:GetPos().z+v.walkover)
tracedata.endpos = Vector(cordx,cordy,v:GetPos().z+v.walkover)
tracedata.filter = v
tracedata.mins = v:OBBMins()
tracedata.maxs = v:OBBMaxs()
local trace = util.TraceHull(tracedata)
local search = trace.Entity
if search!=NULL || search:IsWorld() || v.blocked==true then
v.blocked=true
local move = v:OBBMaxs()*v.times
local right1 = v:GetRight().x*move
local right2 = v:GetRight().y*move
local left1 = v:GetRight().x*move*-1
local left2 = v:GetRight().y*move*-1
if v.blocked==true then
local tracedata2 = {}
tracedata2.start = Vector(v:GetPos().x+right1.x, v:GetPos().y+right2.y, v:GetPos().z+v.walkover)
tracedata2.endpos = Vector(enemy:GetPos().x, enemy:GetPos().y, v:GetPos().z+v.walkover)
tracedata2.filter = enemy
tracedata2.mins = v:OBBMins()
tracedata2.maxs = v:OBBMaxs()
local trace2 = util.TraceHull(tracedata2)
local search2 = trace2.Entity
local tracedata3 = {}
tracedata3.start = Vector(v:GetPos().x+left1.x, v:GetPos().y+left2.y , v:GetPos().z+v.walkover)
tracedata3.endpos = Vector(enemy:GetPos().x, enemy:GetPos().y, v:GetPos().z+v.walkover)
tracedata3.filter = enemy
tracedata3.mins = v:OBBMins()
tracedata3.maxs = v:OBBMaxs()
local trace3 = util.TraceHull(tracedata3)
local search3 = trace3.Entity
if search2==NULL then
MoveToPosition(v, v:GetPos().x+right1.x, v:GetPos().y+right2.y, v:GetPos().z, action)
v.blocked=false
v.times=1
return
end
if search3==NULL then
MoveToPosition(v, v:GetPos().x+left1.x, v:GetPos().y+left2.y, v:GetPos().z, action)
v.blocked=false
v.times=1
return
end
v.times=v.times+1
end
else
end
if v:GetClass()!="npc_manhack" && v:GetClass()!="npc_cscanner" then
if v.blocked==false then
MoveToPosition(v, cordx, cordy, v:GetPos().z, action)
end
else
MoveToPosition(v, cordx, cordy, enemy:GetPos().z+5, action)
end
end
end
function EntityTakeDamage2( ent, inflictor, attacker, amount )
if(tonumber(AISetup.Config["Turn"]) == 1) then
//make friendlys turn a
Make sure the "entity" IsValid... if IsValid( entity ) && entity:IsPlayer( ) ...
Sorry, you need to Log In to post a reply to this thread.