New LUA AI Functions
Posted: Tue Aug 27, 2013 11:05 pm
A lot of AI related functions have now been exposed thanks mostly to thefoof, here is the list of all new lua functions added over the past 2 nights
SetTarget(Spawn, Spawn)
IsPet(Spawn)
GetOwner(Spawn)
SetInCombat(Spawn, bool)
CompareSpawns(Spawn, Spawn)
Runback(Spawn)
GetRunbackDistance(Spawn)
IsCasting(Spawn)
IsMezzed(Spawn)
IsStunned(Spawn)
IsMezzedOrStunned(Spawn)
ClearEncounter(Spawn)
ClearHate(Spawn, [Spawn])
GetMostHated(Spawn)
GetEncounterSize(Spawn)
HasRecovered(Spawn)
ProcessMelee(Spawn, Spawn, float)
ProcessSpell(Spawn, Spawn, float)
GetEncounter(Spawn)
GetHateList(Spawn)
HasGroup(Spawn)
The following spawn script will use lua AI that will duplicate what we have in the server core.
wiki pages will come over the next few days
SetTarget(Spawn, Spawn)
IsPet(Spawn)
GetOwner(Spawn)
SetInCombat(Spawn, bool)
CompareSpawns(Spawn, Spawn)
Runback(Spawn)
GetRunbackDistance(Spawn)
IsCasting(Spawn)
IsMezzed(Spawn)
IsStunned(Spawn)
IsMezzedOrStunned(Spawn)
ClearEncounter(Spawn)
ClearHate(Spawn, [Spawn])
GetMostHated(Spawn)
GetEncounterSize(Spawn)
HasRecovered(Spawn)
ProcessMelee(Spawn, Spawn, float)
ProcessSpell(Spawn, Spawn, float)
GetEncounter(Spawn)
GetHateList(Spawn)
HasGroup(Spawn)
The following spawn script will use lua AI that will duplicate what we have in the server core.
Code: Select all
local MAX_CHASE_DISTANCE = 80
function Think(Spawn)
-- Make sure the NPC is not mezzed or stunned
if not IsMezzedOrStunned(Spawn) then
-- Get the most hated spanw
local Target = GetMostHated(Spawn)
-- Get runback distance
local runback_distance = GetRunbackDistance(Spawn)
-- Check to see if we got a target
if Target ~= nil then
if GetTarget(Spawn) == nil or not CompareSpawns(Target, GetTarget(Spawn)) then
SetTarget(Spawn, Target)
FaceTarget(Spawn, Target)
end
if not IsInCombat(Spawn) then
SetInCombat(Spawn, true)
end
-- Check distance to run back location
if runback_distance > MAX_CHASE_DISTANCE then
-- Clear the hate list
ClearHate(Spawn)
-- Clear the encounter list
ClearEncounter(Spawn)
else
local distance = GetDistance(Spawn, GetTarget(Spawn), 1)
if not IsCasting(Spawn) and (not HasRecovered(Spawn) or not ProcessSpell(Spawn, Target, distance)) then
FaceTarget(Spawn, Target)
ProcessMelee(Spawn, Target, distance)
end
end
else
-- nothing in hate list
-- check to see if the NPC is still flagged in combat
if IsInCombat(Spawn) then
SetInCombat(Spawn, false)
if not IsPet(Spawn) or not IsPlayer(GetOwner(Spawn)) then
SetHP(Spawn, GetMaxHP(Spawn))
end
end
if runback_distance > 0 then
Runback(Spawn)
end
if GetEncounterSize(Spawn) > 0 then
ClearEncounter(Spawn)
end
end
end
end
function spawn(NPC)
SetLuaBrain(NPC)
SetBrainTick(NPC, 200)
end
function respawn(NPC)
spawn(NPC)
end
function hailed(NPC, Player)
local target = GetTarget(Player)
if CompareSpawns(NPC, target) then
Say(NPC, "Same")
else
Say(NPC, "Not the same")
end
end