Skip to content

AI Scripting

MorkfelMorkfel 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:
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

Comments

  • BubbBubb Member Posts: 1,001
    edited April 2019
    You can use:
    UseItemSlotAbility(LastSeenBy(Myself),SLOT_MISC0,1)
    

    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.
  • MorkfelMorkfel Member Posts: 27
    Thanks for your comment Bubb. That actually reminds me of another question.

    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:
    	Or(3)
    	  HasItemInSlot(MISC0,"WAND03")
    	  HasItemInSlot(MISC1,"WAND03")
    	  HasItemInSlot(MISC2,"WAND03")
    

    Is there an index for all scripting fuctions online somewhere?
  • BubbBubb Member Posts: 1,001
    edited April 2019
    Morkfel wrote: »
    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.



    CheckItemSlot(Myself,"WAND03",SLOT_MISC0)
    

    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:
    34 UseItemAbility(S:Object*,O:Target*,I:Slot*SLOTS,I:Ability*)
    

    You can then use:
    UseItemAbility("WAND03",LastSeenBy(Myself),SLOT_AMMO3,1)
    

    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.
    Post edited by Bubb on
  • kjeronkjeron Member Posts: 2,367
    edited April 2019
    Bubb wrote: »
    UseItemAbility("WAND03",LastSeenBy(Myself),SLOT_AMMO3,1)
    

    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 "SLOTS" index dictates which icon is displayed over the character's portrait as their current/queued action.
    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.
  • MorkfelMorkfel Member Posts: 27
    Thanks for the help guys. I had totally forgotten about gibberlings3.github.io/iesdp/ and was just searching the data files using Near Infinity.

    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.
    	...
    	!InParty(LastSeenBy(Myself))
    	!Allegiance(LastSeenBy(Myself),ALLY)
    	!Allegiance(LastSeenBy(Myself),PC)
    THEN
    	RESPONSE #100
    		AttackOneRound(LastSeenBy(Myself))
    END
    
  • _Luke__Luke_ Member, Mobile Tester Posts: 1,535
    edited May 2019
    Bubb wrote: »
    Only caveat is that you have to know what slot the item is in, instead of referencing it by the resref.

    The same holds for SelectWeaponAbility()...

    Do you know if it's possible to tweak it in the following way?
    94 SelectWeaponAbilityRES(S:Object*,I:AbilityNum*)
    

    You can then use:
    SelectWeaponAbilityRES("AROW09",0)
    
  • BubbBubb Member Posts: 1,001
    @Luke93: SelectWeaponAbility does not include any code to process string args, so unfortunately it won't work. Only reason why UseItemAbility was able to be bent is because it has a RES version which already had the correct logic in place.
Sign In or Register to comment.