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

[Trigger] Multiple Custom Unit Values

Status
Not open for further replies.
Level 2
Joined
Jan 2, 2014
Messages
8
[SOLVED] Checking if unit already have ability X

Ok so I have this item that will sometimes give the hero carrying it an ability when hit. Everything is working as intended, that is, the ability should not be added to the hero if the hero in question already has the ability, and after 10 seconds the ability should be removed.

Now, my problem is that to achieve this, I'm using the custom value of the unit to detect whether the unit already has the ability or not and each unit only has one custom value (I want each unit to be able to benefit from more than one item that gives abilities/buffs upon being hit or upon striking other units etc. at once). I do not want to use buffs to detect this, because those are limited to the number of different spells that exist in the game and they do not stack.

For example, if I were to use Inner Fire as a dummy ability to apply a buff for this item, then this is going to create problems with my other item that is also based of off Inner Fire and the actual Inner Fire spell.

So my question is, how do I best create multi-instanceability here without using buffs? Is there some way to use arrays to store multiple custom values for units? Or is there some other better way of doing this?

NOTE: I'm not proficient in JASS, so I will need the solution to be either 100% GUI or partially GUI and partially JASS.

My current GUI code for the trigger in question looks like this:
  • Force of Will
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Attacked unit) is A Hero) Equal to True
      • ((Attacked unit) has an item of type |cff0066ccForce of Will|r) Equal to True
      • (Custom value of (Attacked unit)) Equal to 0
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 1 and 100) Less than or equal to 100
        • Then - Actions
          • Set TempUnit = (Attacked unit)
          • Special Effect - Create a special effect attached to the origin of TempUnit using Abilities\Spells\Items\AIim\AIimTarget.mdl
          • Special Effect - Destroy (Last created special effect)
          • Unit - Add Force of Will to (Attacked unit)
          • Unit - Set the custom value of (Attacked unit) to 1
          • Wait 10.00 seconds
          • Unit - Remove Force of Will from (Attacked unit)
          • Unit - Set the custom value of (Attacked unit) to 0
        • Else - Actions
Thanks in advance. Oh and feel free to point out any memory leaks.
 
Last edited:
Level 29
Joined
Oct 24, 2012
Messages
6,543
Never use attacked unit. Use triggering unit.
This spell is not MUI. So if it is cast more than once before the other one ends it will bug. Changing attacked unit to triggering unit will fix this.
To make this exactly how you want you will need to make this MUI.

You should look at my tutorial Things you should know when using triggers / gui.
It will show you how to make MUI spells in the chapter how to index.
Also waits are very bad. Look at the chapter on waits to see why.
 
Level 2
Joined
Jan 2, 2014
Messages
8
So if it is cast more than once before the other one ends it will bug.

Yes, that's what happened before I added the custom value parts. After having added the custom value parts subsequent calls to the trigger never got to the Actions part of the trigger, and thus subsequent calls to the trigger didn't remove the ability that was added by the previous call(s) to the trigger. So I'm not sure what you're saying using Triggering Unit will fix, but I can see how "Triggering Unit" is more MUI than "Attacked Unit".
I have not checked your tutorial yet, I shall start reading it immediately.

Thanks.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
Yes, that's what happened before I added the custom value parts. After having added the custom value parts it never got to the rest of the trigger, and thus subsequent calls to the trigger didn't remove the ability that was added by the previous call to the trigger. So I'm not sure what you're saying using Triggering Unit will fix, but I can see how "Triggering Unit" is more MUI than "Attacked Unit".
I have not checked your tutorial yet, I shall start reading it immediately.

Thanks.

Triggering unit is treated as a local variable. ( Can't get overwritten by another instance of the spell.)
Attacked Unit is treated as a global variable. ( Can get overwritten by another instance of the spell.)
 
Level 2
Joined
Jan 2, 2014
Messages
8
Ugh, the more I read GUI tutorials and the like the more I feel like just learning all that is JASS instead (as I am proficient in other languages) ...

Anyway, that's a really good tutorial you have there, I think I'm getting the hang of things. :)

Just a quick question; how does the "Nova spell Damaging" trigger work if another unit cast the Nova spell while the Nova spell Damaging trigger is already at work?
I know that the maxIndexNova variable is global, but will the loop continue to I.e. 3 if it initially only was "supposed" to go up to 2 (because of another unit casting Nova while it is running)?

Sorry if I make no sense ;p
 
Last edited:
Level 29
Joined
Oct 24, 2012
Messages
6,543
Warcraft 3 only runs one trigger at a time so if a unit casts the spell the instance will be created before or after the loop trigger has already ran. So as more units cast it the loop will loop through more instances until those instances end then it will remove the spell instances and de-index when needed.

Is that what you were asking ? If not pleased try to explain more.

Also please do not double post it is against the rules instead hit the edit button on your last post to add more info / ask questions.
 
Level 2
Joined
Jan 2, 2014
Messages
8
Warcraft 3 only runs one trigger at a time so if a unit casts the spell the instance will be created before or after the loop trigger has already ran. So as more units cast it the loop will loop through more instances until those instances end then it will remove the spell instances and de-index when needed.

Is that what you were asking ? If not pleased try to explain more.

Also please do not double post it is against the rules instead hit the edit button on your last post to add more info / ask questions.

Yes that's exactly what I meant, thank you. :)

And thanks for telling me about the rule, I was unaware. *hide*
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
Triggering unit is treated as a local variable. ( Can't get overwritten by another instance of the spell.)
Attacked Unit is treated as a global variable. ( Can get overwritten by another instance of the spell.)

No, they are SAME thing.GetAttackedUnitBJ returns GetTriggerUnit.Only difference is another call.
 
Level 2
Joined
Jan 2, 2014
Messages
8
They are same thing.


The override problem only occurs with event response "Casting Unit", and also "Target unit" has different kind of problem.Others are fine.

Care to enlighten us (or me at least) then? I am curious and need to learn all I can. I mean, what are these problems and whats their difference?
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
They are same thing.


The override problem only occurs with event response "Casting Unit", and also "Target unit" has different kind of problem.Others are fine.

The override problem still occurs otherwise this spell would be MUI with the wait.
It is also just bad practice as triggering unit is faster and more efficient to start.
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
I believe your trigger should look like this.

  • Force of Will
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Attacked unit) is A Hero) Equal to True
      • ((Attacked unit) has an item of type |cff0066ccForce of Will|r) Equal to True
      • (Random integer number between 1 and 100) Less than or equal to 25
      • (Level of Force of Will for (Attacked unit)) greater than 0
    • Actions
      • Special Effect - Create a special effect attached to the origin of (Attacked unit) using Abilities\Spells\Items\AIim\AIimTarget.mdl
      • Special Effect - Destroy (Last created special effect)
      • Unit - Add Force of Will to (Attacked unit)
      • Wait 10.00 seconds
      • Unit - Remove Force of Will from (Attacked unit)
(Random integer number between 1 and 100) Less than or equal to 25
This line makes there is %25 chance the attacked unit will gain Force of Will bonus.

(Level of Force of Will for (Attacked unit) greater than 0
This line prevents target unit from gaining bonus if it already has.

You don't need to use any variables or custom value things.

Some people will say Use triggering unit instead of Attacked unit because it is faster(they are right), some will say don't use waits use timers instead.I won't comment on these.
 
Level 2
Joined
Jan 2, 2014
Messages
8
I believe your trigger should look like this.

  • Force of Will
    • Events
      • Unit - A unit Is attacked
    • Conditions
      • ((Attacked unit) is A Hero) Equal to True
      • ((Attacked unit) has an item of type |cff0066ccForce of Will|r) Equal to True
      • (Random integer number between 1 and 100) Less than or equal to 25
      • (Level of Force of Will for (Attacked unit)) greater than 0
    • Actions
      • Special Effect - Create a special effect attached to the origin of (Attacked unit) using Abilities\Spells\Items\AIim\AIimTarget.mdl
      • Special Effect - Destroy (Last created special effect)
      • Unit - Add Force of Will to (Attacked unit)
      • Wait 10.00 seconds
      • Unit - Remove Force of Will from (Attacked unit)
(Random integer number between 1 and 100) Less than or equal to 25
This line makes there is %25 chance the attacked unit will gain Force of Will bonus.

(Level of Force of Will for (Attacked unit) greater than 0
This line prevents target unit from gaining bonus if it already has.

You don't need to use any variables or custom value things.

Some people will say Use triggering unit instead of Attacked unit because it is faster(they are right), some will say don't use waits use timers instead.I won't comment on these.

Thank you! That is exactly what I was looking for. So simple and obvious, how did that not cross my mind ...

I know about the random integer part, I just set it to 100% for testing purposes. :)

Thank you both for your time and input.
 
Level 2
Joined
Jan 2, 2014
Messages
8
Be careful when the waits bug. Also I posted a working version in a map already. That is efficient and MUI and will not bug due to waits.

I tried implementing the indexing system explained in your tutorial, but couldn't quite get it to work. It somehow ignored some units when supposed to subtract from the TimeLeft variable in the loop trigger so the ability was never removed from some units at the end of the unit array.
I will try more sometime later.

Oh and what is this map you speak of? Where can I download it? If possible at all.
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
I tried implementing the indexing system explained in your tutorial, but couldn't quite get it to work. It somehow ignored some units when supposed to subtract from the TimeLeft variable in the loop trigger so the ability was never removed from some units at the end of the unit array.
I will try more sometime later.

Oh and what is this map you speak of? Where can I download it? If possible at all.

Sorry I was thinking about something else.
If you want show me the triggers you have tried and I can help you to get them to work.
 
Status
Not open for further replies.
Top