A hard trigger to trigger. Item to ability vice versa

onejube

New Member
Reaction score
1
Can anyone help me find an easier way to make a trigger that;
-When unit x uses an item then an ability will be added to that unit x and the item removed.

- To remove the ability, there's another unit y with an ability that removes the ability from unit x and adds the item to unit x's inventory that the ability originally came from.

-I need unit x to be able to have 4 abilities in the following button positions;
0,2 1,2 2,2 3,2. All of them removable.

-unit y also has 4 abilities (in the same button positions as unit x) but these are to remove each of unit x's abilities.

I've tried it for one ability and it works fine, but as soon as i try to add a second ability from an item nothing happens.


Here are my triggers so far
TO ADD THE ABILITY
Trigger:
  • Bowgun add
    • Events
      • Unit - A unit Uses an item
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 15, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Item-type of (Item being manipulated)) Equal to Bowgun[(Integer A)]
            • Then - Actions
              • Unit - Add Bowguns[(Integer A)] to (Triggering unit)
            • Else - Actions


TO REMOVE THE ABILITY
Trigger:
  • Bowgun remove
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to Weapon to Item
    • Actions
      • For each (Integer A) from 1 to 15, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
            • Then - Actions
              • Unit - Remove Bowguns[(Integer A)] from Heros[(Player number of (Owner of (Triggering unit)))]
              • Hero - Create Bowgun[(Integer A)] and give it to Heros[(Player number of (Owner of (Triggering unit)))]
            • Else - Actions


Let me know if you need anymore information :O.
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
I imagine you first need to set the items, the "removal-adding" abilities and the real abilities to arrays, like so:

Trigger:
  • init
    • Events
      • Map initialization
    • Conditions
    • Actions
      • -------- real abilities --------
      • Set abilities[0] = ...
      • Set abilities[1] = ...
      • Set abilities[N] = ...
      • -------- abilities to remove item and add real ability --------
      • Set itemSpells[0] = ...
      • Set itemSpells[N] = ...
      • -------- items --------
      • Set item[0] = ...
      • Set item[N] = ...

Once you're done with that, you need to run a loop once a "removal" ability has been casted:

Trigger:
  • abil
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
    • Actions
      • For each (Integer A) from 0 to N, do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Ability being cast) Equal to itemSpells[(Integer A)]
            • Then - Actions
              • Unit - Add abilities[(Integer A)] to (...)
              • Item - Remove (Item carried by (...) of type item[(Integer A)])
            • Else - Actions

Lastly, you need a need a similar trigger to remove the real ability and re-add the right item (it can be blended with the trigger above).
 

rotten

New Member
Reaction score
2
You're making your life harder for no good reason. This is a simple matter, you don't need to go into arrays and all that excrement.

Step 1: Make all the abilities available through this system have the button position (0,2). I have tested this and know for a fact that additional abilities will try to find space to the right of this spot which is exactly the other spots you want.

I might be wrong here but I think this will create a sort of FIFO distribution of your abilities, with the oldest ability always to the left and the newest always to the right. In any event, your abilities will not overlap or anything like that.

Step 2: Binding an ability to an item. Note that you do not need any array variables or any variables at all to do this.
Trigger:
  • Untitled Trigger 001
    • Events
      • Unit - A unit Uses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Torpor
    • Actions
      • Unit - Add Torpor to (Triggering unit)


Replace Torpor with your own item and skill names of course.

Also, if you want these to be Hero skills with leveling capability, you've got a lot of extra work on your hands with spell books and the engineering upgrade. I resisted using these for a long time to no avail :eek:

Step 3: Removing abilities. You do not need another unit or any custom ability to do this, nor do you need a new trigger! There is no actual function to check if a unit has an actual ability, but I believe checking if the level is 0 is a sound workaround. Since even unit abilities actually have 1 level. With that in mind, even if you give your abilities levels do NOT make them hero abilities.
Again, this won't work if you intend the units to be able to LEVEL them, but the spell book system has its own ways to cover for this. Therefore:
Trigger:
  • Untitled Trigger 001
    • Events
      • Unit - A unit Uses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Torpor
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Torpor for (Triggering unit)) Equal to 0
        • Then - Actions
          • Unit - Add Torpor to (Triggering unit)
        • Else - Actions
          • Unit - Remove Torpor from (Triggering unit)


Edit: It actually may be sounder to check if the level of the ability is greater than or equal to 1, and reverse the adding and removing.

Step 4: Limiting to 4 Abilities. This is best achieved by using the Custom Value of Unit (it should be 0 by default), unless of course you're using it for something else (like...?)
All you have to do is increment it whenever a unit activates an ability and decrement it when a unit deactivates an ability, as well as check if it's going to cross over 4. This is more IF work:
Trigger:
  • Untitled Trigger 001
    • Events
      • Unit - A unit Uses an item
    • Conditions
      • (Item-type of (Item being manipulated)) Equal to Torpor
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Level of Torpor for (Triggering unit)) Equal to 0
        • Then - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Custom value of (Triggering unit)) Greater than or equal to 4
            • Then - Actions
              • Floating Text - Create floating text that reads You already have 4 ... above (Triggering unit) with Z offset 100.00, using font size 12.00, color (100.00%, 0.00%, 0.00%), and 20.00% transparency
              • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
              • Floating Text - Change (Last created floating text): Disable permanence
              • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
              • Floating Text - Change the fading age of (Last created floating text) to 1.50 seconds
            • Else - Actions
              • Unit - Add Torpor to (Triggering unit)
              • Unit - Set the custom value of (Triggering unit) to ((Custom value of (Triggering unit)) + 1)
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Custom value of (Triggering unit)) Less than or equal to 0
            • Then - Actions
              • Floating Text - Create floating text that reads ERROR! You seem to ... above (Triggering unit) with Z offset 100.00, using font size 12.00, color (100.00%, 0.00%, 0.00%), and 20.00% transparency
              • Floating Text - Set the velocity of (Last created floating text) to 64.00 towards 90.00 degrees
              • Floating Text - Change (Last created floating text): Disable permanence
              • Floating Text - Change the lifespan of (Last created floating text) to 3.00 seconds
              • Floating Text - Change the fading age of (Last created floating text) to 1.50 seconds
            • Else - Actions
              • Unit - Remove Torpor from (Triggering unit)
              • Unit - Set the custom value of (Triggering unit) to ((Custom value of (Triggering unit)) - 1)


Customize the error text messages to your convenience. Note that you do NOT need to define any variable.

You'll need to copy this trigger for every ability, or just create an IF chain within one trigger if you feel like getting carpal tunnel syndrome.

Step 5: If the Custom Variable is not 0 by default do this:

Trigger:
  • Untitled Trigger 002
    • Events
      • Unit - A unit enters (Playable map area)
    • Conditions
    • Actions
      • Unit - Set the custom value of (Entering unit) to 0
 

onejube

New Member
Reaction score
1
Thanks for both of your in depth answers.

Thank you, but the reason why i have the arrays is because I need to make a similar trigger to another ability that has 15 types (not levels but upgrades if you like) so 6 "weapons" and each of them have 15 types.

Thanks so far
 

rotten

New Member
Reaction score
2
OK, I don't really get this. An ability with 15 types means what exactly? Because it can either be 1 ability with 15 levels or 15 abilities.

The way I understand arrays is they are strings of variables, kind of like a word where you reference an individual letter within it by its number. I do not see any reason why you'd want to do that, it will just lag your map and you will still need to make all the abilities and reference them in your triggers. To my understanding, variables are usually employed when you need to reference the exact same object through multiple triggers. This is not really needed with abilities.

Note that an ability with 15 levels does not have to mean that the latter levels are more powerful. Also, again, a unit ability with 15 levels is unaffected by hero levels and I believe the only way to access any level after 1 is by trigger. There is no reason not to use levels, they're a great tool.

You can just use editor suffixes to navigate among your abilities if you want a lot of them with the same name.
 

onejube

New Member
Reaction score
1
Sorry I mean

I mean 15 different abilities all similar to bowgun
bowgun is a unit ability and the type of game i'm making requires the abilities to be that way.
There will be in total about 60 or more abilities i need to do this for. That's why i felt i needed few arrays.
The way i see you want me to do it will require 60 or more triggers for every ability.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top