AI Scripting
Morkfel
Member Posts: 27
I have a couple questions about scripting. Haven't done any since 2013 so maybe it's just slipped my mind, or maybe it's not possible.
First Question: How can I script to use the 2nd ability of a wand?
Normally a script to use a wand would look like:
How do I alter the UseItem() action to use the second ability instead of defaulting to the first ability - which is just an assumption on my part. BGEE has two wands with two abilities: Wand of Fire (WAND05) which does a Fireball and alternatively an Agannazar's Scorcher and Wand of Spell Striking (WAND18) which does Breach and Pierce Magic. Scripting this latter one would be especially useful in colourful fights.
For those interested in how I would normally code this:
First Question: How can I script to use the 2nd ability of a wand?
Normally a script to use a wand would look like:
IF ActionListEmpty() See([EVILCUTOFF]) HasItem("WAND03",Myself) THEN RESPONSE #100 UseItem("WAND03",LastSeenBy(Myself)) END
How do I alter the UseItem() action to use the second ability instead of defaulting to the first ability - which is just an assumption on my part. BGEE has two wands with two abilities: Wand of Fire (WAND05) which does a Fireball and alternatively an Agannazar's Scorcher and Wand of Spell Striking (WAND18) which does Breach and Pierce Magic. Scripting this latter one would be especially useful in colourful fights.
For those interested in how I would normally code this:
IF ActionListEmpty() // don't interrupt RandomNum(2,1) // 50% chance not to use wand at all See([EVILCUTOFF]) // do I see an enemy? CheckStatLT(LastSeenBy(Myself),34,RESISTMAGIC) // make sure low magic resistance CheckStatGT(LastSeenBy(Myself),1,LEVEL) // don't waste on kobolds HPPercentLT(LastSeenBy(Myself),95) // preferably share targets with teammates HPPercentGT(LastSeenBy(Myself),15) // don't waste it on something about to die !HaveSpell(WIZARD_MAGIC_MISSILE) // why don't I use the spell up first? HasItem("WAND03",Myself) // do I even have a Wand of Magic Missiles? THEN RESPONSE #100 UseItem("WAND03",LastSeenBy(Myself)) // yay I did 4 pts of dmg! END
0
Comments
Only caveat is that you have to know what slot the item is in, instead of referencing it by the resref.
SLOT_MISC0-2 are the quick item slots, if it helps any.
I generally only script for common items (wands and readily available potions). The UseItem() action doesn't care where the item is, so it uses wands out of inventory or quickslots.
Do you know of a way I could script an Or() qualifier to ensure the item is in a quickslot before using it?
Something like:
Is there an index for all scripting fuctions online somewhere?
The IESDP has a ton of information about the engine. Specifically, this page lists out and explains all the actions.
can detect if the item is in the given slot. But, I've found a better way. Turns out that the engine is a little flexible when it comes to action args for UseItem.
Throw this in your ACTION.IDS:
You can then use:
in your script. SLOT_AMMO3 is just a dummy value; doesn't really matter what is there, (as long as it isn't 0, for some reason Near Infinity doesn't like that). Luckily the engine will ignore it and search for the item in the inventory.
The last arg is, naturally, the ability index
Edit: As @kjeron has said below, the slot index actually does influence something; the action icon on a PC's portrait. You should use SLOT_AMMO3 to prevent misleading icons from being displayed.
SLOT_AMMO3 is normally an unused slot, so it won't display any misleading item icon over the character's portrait.
Even though NI can't handle it, the game can, so if you want to use it for SLOT_AMULET (0), you just have to create the script with something other than Near Infinity until it get's fixed.
I have a new problem, but it only shows up in The Black Pits. When a party member "dies" my other party members will start to attack them (but will also keep trying to heal them, too). I've tried to stop it with the following lines but it doesn't work. Does anyone know the flag or indicator for party members that are not-dead on the ground? It doesn't come up in my regular BGEE playtesting because I play with permanent death.
The same holds for SelectWeaponAbility()...
Do you know if it's possible to tweak it in the following way?
You can then use: