Combat Scripting LUA Functions

EQ2Emulator Development forum.

Moderator: Team Members

Post Reply
User avatar
alfa
Team Member
Posts: 550
Joined: Fri Jul 27, 2007 6:24 pm
Location: France
Contact:

Combat Scripting LUA Functions

Post by alfa » Mon Aug 06, 2012 5:16 pm

After talking a bit with Jab, there is the list of what is needed for combat scripting (it's a start, I will complete the list)
Before all I assume all LUA Get Functions can be used for NPC.

Code: Select all

GetAttackersList --> return an iterator of all player in group / raid (should be optionnal) of attackers

Options:
 - list by archetype
 - list by class
 - only who are alive
 - only who are in aggro list (can be used to have only ppl alive)
 - only who ahve/don't have an item or equiped item
 - only who have more or less than a percentage of health
 - only who have more or less than a percentage of power
 - only who have a specific buff active

GetNPCGroupList --> return an iterator of all npcs in group / raid of current npc

Options:
 - list by archetype or class
 - list only alive npc

GetSpellsList --> return an iterator of all Spell player have

GetBuffsList --> return an iterator of all active buff player have

Option:
 - sort by type

Options:
 - list by archetype or class
 - only who are in aggro list (can be used to have only ppl alive)

GetEquipedItems --> return an iterator of equiped items

Option:
 - Slot

Possibility to have GetHP / GetPrower functions return in % (of max life)

Need possibility to add handler

example:
Handler #1 When NPC life = 50% it run function N° 1 that spawn first add wave
Handler #2 When NPC life = 30% it run function N° 2 that spawn second add wave
Handler #3 When NPC life = 15% it run function N° 3 that cast fury buff

That is all for now Jab ;)
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

Re: Combat Scripting LUA Functions

Post by Jabantiz » Mon Aug 06, 2012 7:37 pm

I will look into these when I get to AI, should be after I get combat (and its related issues) sorted out.

User avatar
alfa
Team Member
Posts: 550
Joined: Fri Jul 27, 2007 6:24 pm
Location: France
Contact:

Re: Combat Scripting LUA Functions

Post by alfa » Tue Aug 07, 2012 2:17 am

When you have time Jab, I start to look at combat routine I have aleready see in game, more request to come
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."

User avatar
John Adams
Retired
Posts: 9684
Joined: Thu Jul 26, 2007 6:27 am
EQ2Emu Server: EQ2Emulator Test Center
Characters: John
Location: Arizona
Contact:

Re: Combat Scripting LUA Functions

Post by John Adams » Tue Aug 07, 2012 12:22 pm

You gotta watch out for those demanding Frenchmen :mrgreen:


Thanks for helping out, alfa! Good to see you, as always.

User avatar
alfa
Team Member
Posts: 550
Joined: Fri Jul 27, 2007 6:24 pm
Location: France
Contact:

Re: Combat Scripting LUA Functions

Post by alfa » Tue Aug 07, 2012 6:44 pm

It's pleasure John, as always.

And it make me so happy to think in few month I can see scripted mob kill you :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."

User avatar
John Adams
Retired
Posts: 9684
Joined: Thu Jul 26, 2007 6:27 am
EQ2Emu Server: EQ2Emulator Test Center
Characters: John
Location: Arizona
Contact:

Re: Combat Scripting LUA Functions

Post by John Adams » Wed Aug 08, 2012 4:32 pm

After carefully reading Alfa's list of LUA functions, I believe some of them are already implemented:
alfa wrote:Possibility to have GetHP / GetPrower functions return in % (of max life)
We already have GetHP, GetPower, and can do calculations in the LUA for %, no?
alfa wrote:Need possibility to add handler

example:
Handler #1 When NPC life = 50% it run function N° 1 that spawn first add wave
Handler #2 When NPC life = 30% it run function N° 2 that spawn second add wave
Handler #3 When NPC life = 15% it run function N° 3 that cast fury buff
We already have functions that are called at various health stages - it is not in LUAFunctions however (grr) but handled elsewhere

Code: Select all

			case SPAWN_SCRIPT_HEALTHCHANGED:{
				lua_interface->RunSpawnScript(script, "healthchanged", npc, spawn);
				break;
No idea why these are in zoneserver.cpp, but check the CallSpawnScript() function for some additional options.

User avatar
alfa
Team Member
Posts: 550
Joined: Fri Jul 27, 2007 6:24 pm
Location: France
Contact:

Re: Combat Scripting LUA Functions

Post by alfa » Thu Aug 09, 2012 1:02 pm

John Adams wrote:After carefully reading Alfa's list of LUA functions, I believe some of them are already implemented:
alfa wrote:Possibility to have GetHP / GetPrower functions return in % (of max life)
We already have GetHP, GetPower, and can do calculations in the LUA for %, no?
Hardcode function write one time, in some boss script you gonna have to do this calcul 5, 10 times. So yes I'm lazy ^^
John Adams wrote: We already have functions that are called at various health stages - it is not in LUAFunctions however (grr) but handled elsewhere

Code: Select all

			case SPAWN_SCRIPT_HEALTHCHANGED:{
				lua_interface->RunSpawnScript(script, "healthchanged", npc, spawn);
				break;
No idea why these are in zoneserver.cpp, but check the CallSpawnScript() function for some additional options.
Health changed check all time mob life value change ? I have see it in some lua, but I was thinking this is a "one time script". Anw we need more handler, like on dispell cast, on a item used, on a action in zone (widget link like Venekor fight in Cazic Thules)
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."

User avatar
John Adams
Retired
Posts: 9684
Joined: Thu Jul 26, 2007 6:27 am
EQ2Emu Server: EQ2Emulator Test Center
Characters: John
Location: Arizona
Contact:

Re: Combat Scripting LUA Functions

Post by John Adams » Thu Aug 09, 2012 6:21 pm

alfa wrote:So yes I'm lazy ^^
Sorry, I cannot accept more work on us because people don't want to write LUA scripts. Come up with a better excuse, then maybe ;)
alfa wrote:Health changed check all time mob life value change ?
It is checked constantly. Some examples have been at 50%, say something. If at 25%, attempt to heal self. At 0% die.

I agree there are 100's of functions we can add. Just keep making a list, we'll get to them eventually. Raiding, of course, is about the lowest priority we got right now. We have major stability issues that get 100% of our attention until that's resolved, then quite a list of tasks that we're 3 mos behind on delivering. Patience;)

User avatar
alfa
Team Member
Posts: 550
Joined: Fri Jul 27, 2007 6:24 pm
Location: France
Contact:

Re: Combat Scripting LUA Functions

Post by alfa » Fri Aug 10, 2012 9:01 am

I know it John, this is just for keep it up, cause if nobody think to add combat IA when the combat engine is rewrite, It's gonna be longer ^^
Also, advanced functions is for raiding, but atm I work at basic combat AI, this is a big part of combat engine (I think), don't really want to see combat like L2J where mobs only auto attack
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

Re: Combat Scripting LUA Functions

Post by Jabantiz » Sat Oct 06, 2012 9:56 pm

I added GetGroup(Spawn), this will get an array of all group members for the given spawn, this *should* work for both players and NPC's

Arrays in lua were a pain to figure out but now that I got it working it is a good example for future funtions that will return arrays.

User avatar
Zcoretri
Team Member
Posts: 1642
Joined: Fri Jul 27, 2007 12:55 pm
Location: SoCal

Re: Combat Scripting LUA Functions

Post by Zcoretri » Sun Oct 07, 2012 9:19 am

Very nice stuff Jabantiz...I knew lua had arrays but could never really figure out how they worked.

Jabantiz
Lead Developer
Posts: 2912
Joined: Wed Jul 25, 2007 2:52 pm
Location: California

Re: Combat Scripting LUA Functions

Post by Jabantiz » Sun Oct 07, 2012 4:09 pm

Now that I got them working it seems so simple on the c++ side, it took me many tries to figure out and learn how to push an array to lua though. Hopefully this function will be a good example for any one else that wants to push an array to lua.

Jabantiz
Lead Developer
Posts: 2912
Joined: Wed Jul 25, 2007 2:52 pm
Location: California

Re: Combat Scripting LUA Functions

Post by Jabantiz » Fri Aug 30, 2013 3:03 pm

Figured I would bring this up again with the recent work with lua AI
alfa wrote: GetAttackersList --> return an iterator of all player in group / raid (should be optionnal) of attackers
GetHateList() will get an array of every one who has hate with the given spawn

alfa wrote: GetNPCGroupList --> return an iterator of all npcs in group / raid of current npc
GetGroup() will get an array of every one in the group with the given spawn, will work with both a player and a NPC
alfa wrote: GetSpellsList --> return an iterator of all Spell player have
GetBuffsList --> return an iterator of all active buff player have
I assume this is for spells currently active on the player/npc if so then HasSpellEffect() should work for both
alfa wrote: GetEquipedItems --> return an iterator of equiped items
GetEquippedItemsBySlot() and GetEquippedItemByID() will get equipped items by id or by slot
alfa wrote: Possibility to have GetHP / GetPrower functions return in % (of max life)
Have to agree with john (don't faint john) on you can just add a line of code at the top of the function

Code: Select all

local health_pct = GetHP(Spawn) / GetMaxHP(Spawn)
alfa wrote: Need possibility to add handler
Using healthchanged and temp variables you can get this, SetTempVariable() and GetTempVariable()

Code: Select all

function healthchanged(NPC, Spawn)
    local health_pct = (GetHP(Spawn) / GetMaxHP(Spawn)) * 100 -- added " * 100" so .5 = 50

    if health_pct <= 50 then
        local result = GetTempVariable(NPC, "50%Event")
        -- check to see if the even has happened yet
        if result ~= "True" then
            -- code for 50% event here

            -- Set the temp variable so this code won't be triggered again
            SetTempVariable(NPC, "50%Event", "True")
        end
    end
end
You should also clear the variables if the npc wins so the next time the npc goes in combat the events will trigger again

Code: Select all

function CombatReset(NPC)
    -- Clear the event variables
    SetTempVariable(NPC, "50%Event", nil)
end
As for your options on the lists you can check in lua
alfa wrote: - list by archetype
GetArchetypeName()
alfa wrote: - list by class
GetClassName()
alfa wrote: - only who are alive

Code: Select all

if GetHP(NPC) > 0 then
end
alfa wrote: - only who are in aggro list (can be used to have only ppl alive)
GetHateList()
alfa wrote: - only who ahve/don't have an item or equiped item
GetItemByID()
GetEquippedItemBySlot()
GetEquippedItemByID()
alfa wrote: - only who have more or less than a percentage of health
Just check the health percent

Code: Select all

local health_pct = (GetHP(Spawn) / GetMaxHP(Spawn)) * 100 -- added " * 100" so .5 = 50
alfa wrote: - only who have more or less than a percentage of power
Same as above just with the power lua functions
alfa wrote: - only who have a specific buff active
HasSpellEffect()

User avatar
alfa
Team Member
Posts: 550
Joined: Fri Jul 27, 2007 6:24 pm
Location: France
Contact:

Re: Combat Scripting LUA Functions

Post by alfa » Fri Aug 30, 2013 5:17 pm

Thanks again Jab !
Still working on my first Brain Script (using your lua editor)
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."

Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests