Discussions on development of both the EQ2Emulator LUA Script Engine and Script specifications
Moderator: Team Members
-
alfa
- Team Member
- Posts: 550
- Joined: Fri Jul 27, 2007 6:24 pm
- Location: France
-
Contact:
Post
by alfa » Wed Oct 10, 2012 3:21 pm
Was working on LUA for somes generic script (fighter, mage, scout, priest). First want to use healthchanged for check but thinkings about it, it will be too mutch check (and on big script can be realy hudge load) and not easy to set percent of chance so that why I have search on Wiki for a fonction like healthchanged but happen at autoattck timer tick of NPC, not found it so request it cause I'm not able to do it myself
So request:
AutoAttackTick, happend at auto attack timer tick of npc
Thanks ;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 » Wed Oct 10, 2012 3:26 pm
So you want the server to call the function every time autto attack goes off? Kind of like hailed()?
If that is what you want that would be easy to add in.
-
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 Oct 10, 2012 3:37 pm
I guess I never noticed, I thought auto-attack was just a toggle. Turn on attack, it's on til you shut it off or combat ends. At least that's what I saw in the console window while attacking something.
What is the point of a tick? What use case can we use to understand the purpose? Mob attacks every second, so "flurry" or "enrage" or something? If it's health-based events, healthchanged() should be good enough. Like, 10%, complete heal self.
-
Jabantiz
- Lead Developer
- Posts: 2912
- Joined: Wed Jul 25, 2007 2:52 pm
- Location: California
Post
by Jabantiz » Wed Oct 10, 2012 3:42 pm
I think he means every time the mob makes a melee attack he wants that function called. If that is the case it would be really simple to implement (5mins tops if even that). But you are right auto attack is a toggle and once it is on the spawn will melee attack until it is turned off.
-
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 Oct 10, 2012 3:45 pm
Or wins
If you think it's a viable add, and it's an easy one, probably no reason not to do it. My only hesitation is adding too many functions that do the same thing. We do not want our code to become a mess of "well I can do it any one of 12 ways". That will be hell to document or explain.
But, this sounds like something different than a health monitor.
-
alfa
- Team Member
- Posts: 550
- Joined: Fri Jul 27, 2007 6:24 pm
- Location: France
-
Contact:
Post
by alfa » Wed Oct 10, 2012 4:28 pm
Jabantiz wrote:I think he means every time the mob makes a melee attack he wants that function called.
Exactly !
J.A. Be sure it's needed it's base of combat so npc need it too
Another thing but maybe cause I'm tired, there is an LUA function for Cast Spell for NPC ?
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."
-
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 Oct 10, 2012 4:59 pm
alfa wrote:Another thing but maybe cause I'm tired, there is an LUA function for Cast Spell for NPC ?
NPCs have their own spell casting AI, yes. Check the code for GetNPCSpells, GetNPCSkills, and SetNPCEquipment - each of these come from spawn tables that are linked to spawn_npcs (spell lists, skill lists and equipment setups). Again, equipment in this fashion is NOT visual, only bonus attributes of the items (ie., give an NPC +200 cold resist cuz it's on a BP)
-
Jabantiz
- Lead Developer
- Posts: 2912
- Joined: Wed Jul 25, 2007 2:52 pm
- Location: California
Post
by Jabantiz » Wed Oct 10, 2012 5:15 pm
There is also a lua function to cast a spell that is not in the spell list for that spawn, useful if it is a spell cast only for certain events.
Code: Select all
CastSpell(Target, spell_id, spell_tier, Caster)
Target and Caster are of type Spawn
spell_id is int32
spell_tier is int8
-
alfa
- Team Member
- Posts: 550
- Joined: Fri Jul 27, 2007 6:24 pm
- Location: France
-
Contact:
Post
by alfa » Wed Oct 10, 2012 6:12 pm
John Adams wrote:NPCs have their own spell casting AI, yes. Check the code for GetNPCSpells, GetNPCSkills, and SetNPCEquipment - each of these come from spawn tables that are linked to spawn_npcs (spell lists, skill lists and equipment setups). Again, equipment in this fashion is NOT visual, only bonus attributes of the items (ie., give an NPC +200 cold resist cuz it's on a BP)
What are the frequency and conditions of NPC AI Spell / Skill cast ??
Jabantiz wrote:There is also a lua function to cast a spell that is not in the spell list for that spawn, useful if it is a spell cast only for certain events.
Code: Select all
CastSpell(Target, spell_id, spell_tier, Caster)
Target and Caster are of type Spawn
spell_id is int32
spell_tier is int8
Thanks again Jab I was looking for it

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."
-
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 Oct 10, 2012 6:20 pm
alfa wrote:What are the frequency and conditions of NPC AI Spell / Skill cast ??
There is a field in `spawn_npcs` called `cast_percentage` which I believe is where you set the chance to cast any of the spells in the NPC's spell list set.
There is also a field for `ai_strategy` (Balanced, Offensive, Defensive) but that was implemented so long ago, I didn't know enough about spawn behavior to test it thoroughly.
Lastly, there is a field `attack_type` which honestly, I have no idea what that is for, as it is only ever set to attack_type = 0 during NPC::Initialize() (far as I can tell).
-
alfa
- Team Member
- Posts: 550
- Joined: Fri Jul 27, 2007 6:24 pm
- Location: France
-
Contact:
Post
by alfa » Wed Oct 10, 2012 6:25 pm
Ok, I will take an eye in code tomorow for find what fields mean and frequency of cast spell rand call

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."
-
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 Oct 10, 2012 6:29 pm
It is in NPC_AI.cpp -
Code: Select all
bool NPC_AI::ProcessSpell(NPC* npc, Entity* target, float distance){
if(rand()%100 > npc->GetCastPercentage() || npc->IsMezzed() || npc->IsStifled())
return false;
-
alfa
- Team Member
- Posts: 550
- Joined: Fri Jul 27, 2007 6:24 pm
- Location: France
-
Contact:
Post
by alfa » Wed Oct 10, 2012 6:35 pm
Yes but what frequency code call this function in combat ? :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 » Wed Oct 10, 2012 6:47 pm
It will check to see if it can cast a spell every time the combat loops in the server (20milli secs I think, 50 times a sec). As for the AI behavior, it will just try to favor that type of spell over the other. It only effects spell casting, so offensive behavior means it will cast a nuke over a heal.
As for the original requested function I have already coded it and am testing it right now, it will only be triggered when the primary weapon swings right now, it can be changed to every melee attack but that would mean the function is triggered on riposte, off hand, multiple times for a multi attack. It is easy to change if need be but for now I have it for primary swing.
-
Jabantiz
- Lead Developer
- Posts: 2912
- Joined: Wed Jul 25, 2007 2:52 pm
- Location: California
Post
by Jabantiz » Wed Oct 10, 2012 7:07 pm
Commited this to Dev SVN, following script is what I used to test this. NPC is the spawn attacking, Spawn is the target.
Code: Select all
function hailed(NPC, Spawn)
Attack(NPC, Spawn)
end
function auto_attack_tick(NPC, Spawn)
Say(NPC, "I am attacking " .. GetName(Spawn) .. "!")
end
Let me know if this needs to be renamed to something simpler, or needs to be triggered more then it currently is.
Last edited by
Jabantiz on Wed Oct 10, 2012 7:52 pm, edited 1 time in total.
Reason: fixed my typo, in this post and in the code...
Who is online
Users browsing this forum: No registered users and 0 guests