Discussions on development of both the EQ2Emulator LUA Script Engine and Script specifications
Moderator: Team Members
-
Jabantiz
- Lead Developer
- Posts: 2912
- Joined: Wed Jul 25, 2007 2:52 pm
- Location: California
Post
by Jabantiz » 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.
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
wiki pages will come over the next few days
-
John Adams
- Retired
- Posts: 9684
- Joined: Thu Jul 26, 2007 6:27 am
- EQ2Emu Server: EQ2Emulator Test Center
- Characters: John
- Location: Arizona
-
Contact:
Post
by John Adams » Wed Aug 28, 2013 8:45 am
Holy crap! ~screams like a Beatles girl~
Impressive list. I suppose Alfa just got an early Christmas present

-
alfa
- Team Member
- Posts: 550
- Joined: Fri Jul 27, 2007 6:24 pm
- Location: France
-
Contact:
Post
by alfa » Wed Aug 28, 2013 10:38 am
John Adams wrote:Holy crap! ~screams like a Beatles girl~
Impressive list. I suppose Alfa just got an early Christmas present

Jab PM me this yesterday, start some cool things like basic Warrior, Priest, Scout, Mage script... Before start some boss scrit

More to come soon ^^
Fight with me... Or die, like the rest.
J.A. say: "I think Xinux tried to tell me this, but I ignore most things he suggests."
-
Jabantiz
- Lead Developer
- Posts: 2912
- Joined: Wed Jul 25, 2007 2:52 pm
- Location: California
Post
by Jabantiz » Wed Aug 28, 2013 9:44 pm
All lua functions in the original post have been updated to link to their wiki page.
A lot of copy and paste was used so there might be a few errors...
-
John Adams
- Retired
- Posts: 9684
- Joined: Thu Jul 26, 2007 6:27 am
- EQ2Emu Server: EQ2Emulator Test Center
- Characters: John
- Location: Arizona
-
Contact:
Post
by John Adams » Thu Aug 29, 2013 7:01 am
That's a ton of Wiki-work. Thank you for doing that.
-
alfa
- Team Member
- Posts: 550
- Joined: Fri Jul 27, 2007 6:24 pm
- Location: France
-
Contact:
Post
by alfa » Thu Aug 29, 2013 4:16 pm
Thanks Jab

Admit you just do Wiki Page for stopping me spam you for explain about it :p
And quick question, is GetHateList() return Player in order or randomly ? I know there is GetMostHated() but only return #1 in hate list and if I need the #2 :p
Fight with me... Or die, like the rest.
J.A. say: "I think Xinux tried to tell me this, but I ignore most things he suggests."
-
Jabantiz
- Lead Developer
- Posts: 2912
- Joined: Wed Jul 25, 2007 2:52 pm
- Location: California
Post
by Jabantiz » Thu Aug 29, 2013 10:06 pm
Updated the
AI wiki page and added the
lua page.
I accidently clicked a link while editing the lua page and lost a lot of my work so the last portion may seem half assed and that is probably because it is from trying to remember and retype it all out. Hopefully the page will be useful to some of you though.
-
John Adams
- Retired
- Posts: 9684
- Joined: Thu Jul 26, 2007 6:27 am
- EQ2Emu Server: EQ2Emulator Test Center
- Characters: John
- Location: Arizona
-
Contact:
Post
by John Adams » Sun Sep 01, 2013 12:52 pm
Jabantiz wrote:I accidently clicked a link while editing the lua page and lost a lot of my work
I cannot tell you how many times I've done that same thing. That sucks, man.
-
John Adams
- Retired
- Posts: 9684
- Joined: Thu Jul 26, 2007 6:27 am
- EQ2Emu Server: EQ2Emulator Test Center
- Characters: John
- Location: Arizona
-
Contact:
Post
by John Adams » Tue Sep 03, 2013 5:36 pm
Btw, all 3 linux services fail to compile because of Brain.
Code: Select all
In file included from ../common/../common/../WorldServer/Combat.h:24,
from ../common/../common/../WorldServer/zoneserver.h:34,
from ../common/../common/../WorldServer/client.h:26,
from ../common/../common/Log.h:24,
from ../common/Mutex.cpp:22:
../common/../common/../WorldServer/NPC_AI.h:75: error: extra qualification ‘Brain::’ on member ‘GetHateList’
In file included from ../common/../common/../WorldServer/Combat.h:24,
from ../common/../common/../WorldServer/zoneserver.h:34,
from ../common/../common/../WorldServer/client.h:26,
from ../common/../common/Log.h:24,
from ../common/MiscFunctions.cpp:21:
../common/../common/../WorldServer/NPC_AI.h:75: error: extra qualification ‘Brain::’ on member ‘GetHateList’
No idea why NPC_AI is affecting Login and Patcher.
Commit 2217 is where it breaks. The addition of vector<Entity*>* Brain::GetHateList(); in NPC_AI.h
-
John Adams
- Retired
- Posts: 9684
- Joined: Thu Jul 26, 2007 6:27 am
- EQ2Emu Server: EQ2Emulator Test Center
- Characters: John
- Location: Arizona
-
Contact:
Post
by John Adams » Tue Sep 03, 2013 5:53 pm
Oh, duh?
Code: Select all
vector<Entity*>* Brain::GetHateList();
should be
?
Still boggles me why this is touching common code.
-
Jabantiz
- Lead Developer
- Posts: 2912
- Joined: Wed Jul 25, 2007 2:52 pm
- Location: California
Post
by Jabantiz » Tue Sep 03, 2013 5:53 pm
My bad
Code: Select all
vector<Entity*>* Brain::GetHateList();
NPC_AI.h, forgot to take out the brain:: from a copy and paste....
Will commit to SVN in a sec
EDIT: And john found my issue, still will commit
EDIT2: Fix on svn
-
John Adams
- Retired
- Posts: 9684
- Joined: Thu Jul 26, 2007 6:27 am
- EQ2Emu Server: EQ2Emulator Test Center
- Characters: John
- Location: Arizona
-
Contact:
Post
by John Adams » Tue Sep 03, 2013 6:02 pm
haha JABANTIZ!!
Code: Select all
Entity.cpp:979: error: no matching function for call to ‘max(float, double)’
lol you min/max'd me again
You really need a linux box

-
thefoof
- Retired
- Posts: 630
- Joined: Wed Nov 07, 2012 7:36 pm
- Location: Florida
Post
by thefoof » Tue Sep 03, 2013 6:09 pm
John Adams wrote:haha JABANTIZ!!
Code: Select all
Entity.cpp:979: error: no matching function for call to ‘max(float, double)’
lol you min/max'd me again
You really need a linux box

Lol that one was probably me.
-
Jabantiz
- Lead Developer
- Posts: 2912
- Joined: Wed Jul 25, 2007 2:52 pm
- Location: California
Post
by Jabantiz » Tue Sep 03, 2013 6:10 pm
Code: Select all
float Entity::CalculateCastingSpeedMod() {
float cast_speed = info_struct.casting_speed;
if(cast_speed > 0)
return 100 * max((float) 0.5, 1 + (1 - (1 / (1 + (cast_speed * .01)))));
else if (cast_speed < 0)
return 100 * min((float) 1.5, 1 + (1 - (1 / (1 + (cast_speed * -.01)))));
return 0;
}
WOOT not me this time. I will add the float to the second portion of it though and commit
EDIT: Fix on dev svn
-
John Adams
- Retired
- Posts: 9684
- Joined: Thu Jul 26, 2007 6:27 am
- EQ2Emu Server: EQ2Emulator Test Center
- Characters: John
- Location: Arizona
-
Contact:
Post
by John Adams » Tue Sep 03, 2013 6:11 pm
lol you guys are aging me faster than normal.
Who is online
Users browsing this forum: No registered users and 0 guests