• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Casting spells from item abilities

Level 4
Joined
Dec 26, 2021
Messages
45
Hello,


something i never understood is how to cast spells from item based abilities such as moonstone and or wand of mirror image?

I would appreciate this as I am trying to make abilities based on these and it is not clear how i shall proceed once i convert them to unit abilities and add toa dummy.


Muchos gracias
 
Level 25
Joined
Sep 26, 2009
Messages
2,378
What you should understand first is that all skills, abilities and commands that you can issue to a unit have an "order". A unit that has been given this "order" will try to successfully execute it.
When you for example click the Mountain King's Storm Bolt ability and select a target, the Mountain King will be issued a specific order. As part of executing the order, the hero will run towards the target to get within the spell's range and then cast the spell. After that the order has been finished.

Most spells and commands have a string-type order. For example clicking 'S' key or clicking the 'Stop' ability will issue "stop" order. Right-clicking a unit will issue "smart" order and ordering human priest to cast Inner Fire ability will issue "innerfire" order.
But not all spells have string-type order. The prime example are many of the item abilities, like the 'Change Time of Day' ability used by Moonstone.
What all abilities and commands do have, however, is order ID - a number that uniquely identifies an order. So while there is no string-type order for 'Change Time of Day' ability, there is an Order ID for it.

The GUI does not really allow you to issue an order to unit using order Ids, but it can be done via jass/lua.

So what you can do is first find out the order Id of the ability. I recommend a trigger like below in an empty/new map:
  • Print Order
    • Events
      • Unit - Footman 0000 <gen> Is issued an order targeting an object
      • Unit - Footman 0000 <gen> Is issued an order targeting a point
      • Unit - Footman 0000 <gen> Is issued an order with no target
    • Conditions
    • Actions
      • Custom script: set udg_orderId = GetIssuedOrderId()
      • Game - Display to (All players) the text: (Order id: + (String(orderId)))
The 'orderId' is an integer variable. Do note that all variables defined in the Trigger Editor must have a 'udg_' prefix inside the 'Custom script' action.
Then just give the spell in question to some unit, start the map and cast the spell manually - it should print the order Id.
In this case, the 'Change Time of Day' has order id 852621.

Next thing is to order some unit to cast the spell using the order id. There are jass functions that are equivalent to the GUI 'Unit - Issue Order ...' actions but allow you to specify order Ids:
JASS:
call IssueImmediateOrderById(whichUnit, whichOrder)  //equivalent to 'Unit - Issue Order With No Target'
call IssueTargetOrderById(whichUnit, whichOrder, targetUnit) //equivalent to 'Unit - Issue Order Targeting A Unit'
call IssuePointOrderByIdLoc(whichUnit, whichOrder, targetPoint) //equivalent to 'Unit - Issue Order Targeting A Point'

Finally, in GUI, this would look like this:
  • Order Test
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Set VariableSet u = Footman 0000 <gen>
      • Custom script: call IssueImmediateOrderById(udg_u, 852621)
The 'u' variable is of type 'unit'. The trigger will order the Footman unit to cast 'Change Time Of Day' spell.
 
Top