• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Using Custom Values in Triggers

Level 13
Joined
Aug 31, 2005
Messages
823
In this tutorial I will explain the following:
-What are Custom Values?
-The Purpose of using Custom Values
-How to change Custom Values in-game
-How to use Custom Values in abilitys and other triggers


Introduction:
For those of you not familiar with the Custom Value system, it can be very helpful and prevent you from writing long strips of code. For example, have you ever seen a trigger like this?
  • Events: Unit - A unit Finishes casting an ability
  • Conditions: (Ability being cast) equal to Sell
  • Actions:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Unit-type of (Triggering unit)) Equal to Icicle Tosser
    • Then - Actions
      • Player - Add 7 to (Owner of (Triggering unit)) Current gold
      • Unit - Remove (Triggering unit) from the game
    • Else - Actions
      • Do nothing
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Unit-type of (Triggering unit)) Equal to Spark Tower
    • Then - Actions
      • Player - Add 6 to (Owner of (Triggering unit)) Current gold
      • Unit - Remove (Triggering unit) from the game
    • Else - Actions
      • Do nothing
What a mess huh? Poor Duke Wintermaul's copycat wrote a If-Then condition for every single tower in his map. An alternative to this would be to write a very small trigger and use Custom Values (as I will explain how to do through the course of this tutorial).

What Are Custom Values?
Custom Values are numbers set up by Blizzard with a default of 100. Unlike Point Values they can only be edited in-game. Changing these values will not affect the unit/item directly in any way.

The Purpose of Using Custom Values
The purpose of using Custom Values is simple really: It reduces the time it takes for you to create your map, and (more importantly) it saves you from writing the same GUI trigger 1,000 times. However, the uses for Custom Values are nearly endless. You could set up a map to recognize a unit because of its Custom Value, kill a unit because of it, change their size/color, add/remove them from certain groups etc.

How to Change Custom Values In-Game
Ok, now that you know the basics of changing Custom Values lets apply them to a in-game situation. Place a unit on the map (It doesnt matter what unit it is). Now draw a region somewhere so that our unit can walk into it.
Alright, now that you have your unit and region drawn its time to write a small trigger.
  • Unit Enters Region
    • Events
      • Unit - A unit enters Region 001<gen>
    • Conditions
    • Actions
      • Unit - Set the Custom Value of (Triggering unit) to ((Custom Value of (Triggering unit)) + 1)
      • Game - Display to (All players) the text: ((Name of (Triggering unit)) + ('s value is + (String((Custom Value of (Triggering unit))))))
Now you may run the map and test it. The first time you enter the region it should tell you that the units Custom Value is 101, then 102 and so on (providing you havnt changed the units Custom Value in the object editor).

How to Use Custom Values in Abilities and other Triggers
Now that you understand how to manipulate Custom Values both in-game and in the editor, you should find it easy to apply them to a useable scenario. Remember our friend who made a copy of Wintermaul at the beginning of this tutorial?
  • Events: Unit - A unit Finishes casting an ability
  • Conditions: (Ability being cast) equal to Sell
  • Actions:
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Unit-type of (Triggering unit)) Equal to Icicle Tosser
    • Then - Actions
      • Player - Add 7 to (Owner of (Triggering unit)) Current gold
      • Unit - Remove (Triggering unit) from the game
    • Else - Actions
      • Do nothing
  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Unit-type of (Triggering unit)) Equal to Spark Tower
    • Then - Actions
      • Player - Add 6 to (Owner of (Triggering unit)) Current gold
      • Unit - Remove (Triggering unit) from the game
    • Else - Actions
      • Do nothing
Now that you know how to use Custom Values, you should find it easy to rewrite this and only use 1 trigger instead of 190 (one for every tower).

  • Events: Unit - A unit Finishes casting an ability
  • Conditions: (Ability being cast) equal to Sell
  • Actions: Player - Add (Custom Value of (Triggering unit)) to (Owner of (Triggering unit)) Current gold
  • Unit - Remove (Triggering unit) from the game
And thats it. But remember, Custom Values are much more powerful than these examples show, so try them out and use them to your advantage. Thanks for reading this tutorial and good luck in your future map making projects!


Chao-san Website----------Vote----------Need a sig?
 
Last edited by a moderator:
Level 40
Joined
Dec 14, 2005
Messages
10,532
By the way, just a suggestion, please indent your GUI triggers so they look right.

It's 4 indents per statement. (events/conditions/actions adds 4, an if statement adds 4, a group adds 4, and a loop adds 4)

Also, remove ye old Do Nothing

Edit: Point values aren't the same thing as Custom Values...

Edit2:
You can change this number to anything between -1,000,000,000 and 100,000 (Although I wouldnt recomend using negative numbers)
It's actually between -2^31 and 2^31 (which becomes -2147483648 to 2147483648)

Unless I'm forgetting myself and it's -2^30 to 2^30, in which case it's from -1073741824 to 1073741824
 
Level 13
Joined
Aug 31, 2005
Messages
823
Thanks PurplePoot, its gettin late here (12:00) and I didnt realize I was switching my wording back and forth from custom value to Point value. About the numbers, all i did was go under it and hold down 9 until it wouldnt let me place anymore numbers (in the object editor). Then I clicked ok and copied the number it gave me. In both cases, id have to say your probably right. Where did you get that 2^31/30? (Just curious)
 
Level 13
Joined
Aug 31, 2005
Messages
823
Alright, ill update that in the tutorial. Thanks PurplePoot :wink:

Edit: I just realized I made a mistake through the tuturial. I belive the tutorial should have been setting custom values for units.. I must have lost track while i was doing it. I'll look at it and try to fix it.

Edit: Finished fixing the tutorial (it should all work now) sorry for my dislexic mistakes :wink: Now all I need is a mod or admin to change the title to 'Using Custom Values in Triggers' rather than what it is now...
 
Last edited:
Level 13
Joined
Aug 31, 2005
Messages
823
Nah, not really confusing myself. Just kinda trying to figure out what I was thinking when I wrote it lol. I did want it to be about point values (hence the td reference) but then I messed up on the triggers saying set point value. Point values can be set in the triggers also right? Ill just fix it all tonight. (back to point values with the correct information, etc.)
 
Level 32
Joined
Oct 23, 2006
Messages
5,291
No problem Herio-san, you have plenty of time to get it all straightened out while it's here in the » Tutorial Submission « forum.

[self="http://hiveworkshop.com/forums/announcement.php?f=283"]Please detach your signature from the post.[/self]

As the tutorial is further developed, hopefully more trigger editors will comment on it. So far it looks really helpful, can you include additional (more advanced/powerful) examples of the use of custom values?
 
Level 5
Joined
Jun 23, 2004
Messages
126
By the way, just a suggestion, please indent your GUI triggers so they look right.

It's 4 indents per statement. (events/conditions/actions adds 4, an if statement adds 4, a group adds 4, and a loop adds 4)

Just had to say that it's 5 spaces for an indentation, as seen when you Copy As Text from an actual trigger. You can use as little as 3 spaces but if they're less than 5 you'll start to get problems with heavily indented triggers.

Question for the tutorial maker: Are you going to get into Custom Values of Items and their applications, such as for ownership of an item? (Set CV of Item to Player Number of Owner, match the CV when item is picked up, else drop.)
 
Level 32
Joined
Oct 23, 2006
Messages
5,291
I just need someone to change the title to 'Using Custom Values in Triggers'
~ Using Point Values In Triggers renamed to Using Custom Values in Triggers

Question for the tutorial maker: Are you going to get into Custom Values of Items and their applications, such as for ownership of an item? (Set CV of Item to Player Number of Owner, match the CV when item is picked up, else drop.)
Do you wish to make further additions or revisions Herio-san?
 
Top