• 🏆 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!

[JASS] Running functions when unit is selected

Level 4
Joined
Apr 3, 2012
Messages
31
So I'm working on a map using BPower's Equipment System, and for the most part the system works well. However I have a couple of things I'd like to change, but I'm not super JASS-savvy.

The system works by giving a designated hero an ability, which when used selects a dummy equipment-unit that has a "button-ability" corresponding to each item the hero has "equipped". Using the ability also syncs the inventories of the dummy and the hero. The inventories are also synced when the hero or the dummy uses an item to "equip" it, or the dummy uses a button-ability to unequip that item.

I'd like to free up an ability slot on the hero, and the way I want to do this is by making the equipment dummy selectable through the hero interface buttons. However, the inventories of the hero and the dummy unit are synced when the ability is used, not when the dummy is selected. Basically, I'm just looking to call sync() when the dummy unit is selected, rather than when the ability is used (but I don't know the syntax):

1697280216637.png


It's worth noting that I don't need it to be MUI, just MPI. I have an array variable named Hero[1..8] (player number) for the hero controlled by each player, which would presumably replace eventUnit here.



Another unrelated minor issue occurs when equipping an item in a slot that already has an item equipped. This will run the unequip function for that slot, then the equip function for the used item. This obviously makes sense as you need to unequip an item before equipping a new one, however equipping an item when you have a full inventory will drop the previously equipped item on the floor, instead of putting it in your inventory in place of the used item (since the unit still has a full inventory when the unequip function is called).
This is not a huge issue and probably a bit more complex than the selection event, but if anyone feels like downloading the system and taking a look at it, I would appreciate it.


Thanks in advance!
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,543
Find the function that creates the trigger which registers this unitSpellCast function. It's most likely done in an Init function. Follow that design pattern to create a new trigger which calls a new function which has the same code that you've highlighted above (excluding the elseif at the start).

So basically add something like this code to the Init function:
vJASS:
local trigger t = CreateTrigger()
call TriggerRegisterPlayerSelectionEventBJ(t, Player(0), true)
call TriggerAddAction(t, function playerSelectedDummy)
Then modify it to register the Event for Players 0-7 (1 to 8) and make sure it works with this method design pattern.

Then create a new function that should look something like this:
vJASS:
private static method playerSelectedDummy takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local integer id = GetPlayerId(p) + 1
    local unit eventUnit = GetTriggerUnit()
    if dummy == eventUnit then
        call SetUnitX(dummy, GetUnitX(eventUnit))
        call SetUnitY(dummy, GetUnitY(eventUnit))
        call sync()
     endif
     set p = null
     set eventUnit = null
endmethod
 
Last edited:
Top