Tutorial Custom Values + Dummy Caster

Cohadar

master of fugue
Reaction score
209
Ok there will be some ugly math here but don't get frightened.

You don't really need to know math at all to use this tutorial
because i assembled a table of usefull constants
and you can simply copy-paste those

Trigger code is all in 2-3 lines so it is basically really simple
to understand
(there will be a demo map at the end of course)


General Idea:
Lets imagine you want to make some item that gives special ability
to hero when picked up, and looses special ability when dropped.

We will discus 3 template items here:
Orb of Hex - Gives a 33% chance to hero with this item to hex opponents on attack
Orb of Frost - When attacked hero will be protected by Frost Armor
Orb of Shadow - When attacked hero will become invisible

you can make any other items you want that give any ability you want
of course

First idea some people might have is to add the ability directly to hero
Code:
Unit - Add <SomeAbility> to (Triggering unit)
But that is bad for several reasons:
#First what if ability needs to be targeted?
#Second it will clutter your icon space
(you can avoid this with spellbook, but that is lots of ugly code and mapping)
#and last to disable this ability you have to disable it for player
there is no way to disable it for single unit, so if you have 2 units
using same items it will fuck things up

So what is the solution?:
Custom Values, but not any kind of custom values
we will use Binary custom values :D

Basically when hero pick some item we will add some number to his custom value
and when he loses it we will subtract that same number
It is as simple as that

Note: if you don't know what binary numbers are
or don't know how to use them you can simply skip this part,
you don't really need it.
But if you want to understand how this really works read on..

Here are some references for binary numbers:
http://en.wikipedia.org/wiki/Binary_numeral_system

You can also use scientific view of you ordinary windows calculator
to convert binary to ordinary numbers...

Lets do the math:
Custom Values of units are 32 bits long
now one might think that we can use each bit for every special item
we intend to use but there is one small problem
what if hero picks 2 same items and then drops one?

Solution:
Hero can have max of 6 items (that is 110 in binary)
and it takes up 3 bits
So for every item we will use 3 bits
to extract 3 bits we need a Modulo of 8
so every number we add/subtract from hero custom value MUST be a power of 8 (Note 8^0 =1, 8^1=8, 8^2=64 ...)
and since we are using 3 bits per item we can have
32(number of bits in custom vale)/3 = 10 special items

Note: if you just went berserk after reading this don't worry
like I said you don't really need to understand all that

No-Math Section:
Ok so we need to add/subtract some numbers
from our hero to mark his possession/non-possession of certain items

Here are those magic numbers:
Code:
1, 8, 64, 512, 4096, 32768, 262144, 2097152, 16777216, 134217728

Like I said they are all powers of 8
2^0, 2^3, 2^6, 2^9, .... 2^27

Trigger Code:
Code:
Hex Orb Picked
    Events
        Unit - A unit Acquires an item
    Conditions
        (Item-type of (Item being manipulated)) Equal to Orb Of Hex
    Actions
        Unit - Set the custom value of (Triggering unit) to ((Custom value of (Triggering unit)) + 1)
Code:
Hex Orb Dropped
    Events
        Unit - A unit Loses an item
    Conditions
        (Item-type of (Item being manipulated)) Equal to Orb Of Hex
    Actions
        Unit - Set the custom value of (Triggering unit) to ((Custom value of (Triggering unit)) - 1)

For every next item instead of 1 you would place 8, 64, 512...

Code:
Frost Orb Picked
    Events
        Unit - A unit Acquires an item
    Conditions
        (Item-type of (Item being manipulated)) Equal to Orb Of Frost
    Actions
        Unit - Set the custom value of (Triggering unit) to ((Custom value of (Triggering unit)) + 8)

and so on....

Now code for dummy caster:
Note: if you don't know what a dummy caster is there are some really good tutorials on that subject on this forum, search them up

Code:
Hex Orb
    Events
        Unit - A unit Is attacked
    Conditions
        (((Custom value of (Attacking unit)) / 1) mod 8) Greater than 0
        (Random integer number between 1 and 100) Less than or equal to 33
    Actions
        Unit - Add Avatar (Neutral) to (Triggering unit)
        Unit - Order Dummy Caster 0006 <gen> to Orc Shadow Hunter - Hex (Attacked unit)

wrf division by 1?
that 1 is a place holder here,
for every special item after this you will place
guess what numbers instead of 1
yes yes 8, 64, 512.. the magic numbers :D

Code:
Frost Orb
    Events
        Unit - A unit Is attacked
    Conditions
        (((Custom value of (Attacked unit)) / 8) mod 8) Greater than 0
        ((Attacked unit) has buff Frost Armor) Equal to False
    Actions
        Unit - Order Dummy Caster 0006 <gen> to Undead Lich - Frost Armor (Attacked unit)

Code:
Shadow Orb
    Events
        Unit - A unit Is attacked
    Conditions
        (((Custom value of (Attacked unit)) / 64) mod 8) Greater than 0
        ((Attacked unit) has buff Invisibility) Equal to False
    Actions
        Wait 1.00 seconds
        Unit - Order Dummy Caster 0006 <gen> to Human Sorceress - Invisibility (Attacked unit)

And finally the demo map:
 
U

Ur-Quan

Guest
Why complicate it so much.
You could just check if the unit has the item like:
Code:
Shadow Orb
    Events
        Unit - A unit Is attacked
    Conditions
        Or - Any (Conditions) are true
            Conditions
                (Item-type of (Item carried by (Attacked unit) in slot 1)) Equal to Shadow Orb +1
                (Item-type of (Item carried by (Attacked unit) in slot 2)) Equal to Shadow Orb +1
                (Item-type of (Item carried by (Attacked unit) in slot 3)) Equal to Shadow Orb +1
                (Item-type of (Item carried by (Attacked unit) in slot 4)) Equal to Shadow Orb +1
                (Item-type of (Item carried by (Attacked unit) in slot 1)) Equal to Shadow Orb +1
                (Item-type of (Item carried by (Attacked unit) in slot 1)) Equal to Shadow Orb +1
    Actions
        Set P = (Position of (Attacked unit))
        Unit - Create 1 Sorceress for (Owner of (Attacked unit)) at P facing Default building facing degrees
        Unit - Add Invisibility to (Last created unit)
        Unit - Order (Last created unit) to Human Sorceress - Invisibility (Attacked unit)
        Unit - Add a 3.00 second Generic expiration timer to (Last created unit)
        Custom script:   call RemoveLocation (udg_P)

See it is a lot better, it is a single trigger, it doesn't include custom values, and absolute no math.
And it could be used in every your trigger.
 

Cohadar

master of fugue
Reaction score
209
Now look at the size of your trigger and tell me witch one is more complicated?
Also tell me witch one is faster and uses a LOT less cpu speed

And like I said, you don't need math all you need is magic numbers :D
 
U

Ur-Quan

Guest
If you consider my trigger big and complicated then mapping ain't for you.
Your trigger is shorter because you didn't Created and added ability to dummy unit which is bad.
At least I got teached that preplaced dummys are bad.
You do 2 triggers instead of one, what is bad.
 

Cohadar

master of fugue
Reaction score
209
Code:
Conditions
                (Item-type of (Item carried by (Attacked unit) in slot 1)) Equal to Shadow Orb +1
                (Item-type of (Item carried by (Attacked unit) in slot 2)) Equal to Shadow Orb +1
                (Item-type of (Item carried by (Attacked unit) in slot 3)) Equal to Shadow Orb +1
                (Item-type of (Item carried by (Attacked unit) in slot 4)) Equal to Shadow Orb +1
                (Item-type of (Item carried by (Attacked unit) in slot 1)) Equal to Shadow Orb +1
                (Item-type of (Item carried by (Attacked unit) in slot 1)) Equal to Shadow Orb +1

VS

Code:
Condition
(((Custom value of (Attacked unit)) / 64) mod 8) Greater than 0

The length of triggers itself does not matter it is the length of condition that matters, because this triggers check Every
attack on the map it is essential that conditions be as small as possible.

And no I don't have 2 triggers for 1 ability
I have 2 sets of triggers and first set is used only when hero picks/drops items

>>If you consider my trigger big and complicated then mapping ain't for you.
Please spare me comments like this,
the essence of good tutorials is to keep it simple
as for the things you think are bad, well you are just plain wrong
 
Reaction score
65
Code:
Shadow Orb
    Events
        Unit - A unit Is attacked
    Conditions
        Or - Any (Conditions) are true
            Conditions
                (Item-type of (Item carried by (Attacked unit) in slot 1)) Equal to Shadow Orb +1
                (Item-type of (Item carried by (Attacked unit) in slot 2)) Equal to Shadow Orb +1
                (Item-type of (Item carried by (Attacked unit) in slot 3)) Equal to Shadow Orb +1
                (Item-type of (Item carried by (Attacked unit) in slot 4)) Equal to Shadow Orb +1
                (Item-type of (Item carried by (Attacked unit) in slot 1)) Equal to Shadow Orb +1
                (Item-type of (Item carried by (Attacked unit) in slot 1)) Equal to Shadow Orb +1
Could be done with For each integer A loop, much simpler. This way it's much easier to understand.
The custom values could be used for something more important instead of this, too.
 

Cohadar

master of fugue
Reaction score
209
More important? for example?

Besides if there is really need to use custom values for something else
you can always reserve one of the magic numbers for that something else whatever that might be

For example if you don't use last 5 magic numbers you have last
32-5*3=18 bits (262144 numbers) to use for whatever purpose you want.

now tell me is there some important value you need to use that cannot fit into 0..262144 ?

Besides division of custom value to different bit segments
makes it possible for you to store multiple custom values into same number
So this is basically a general approach
and a great advantage to standard methods
and not a handicap as it might look at first sight

Also someone might think that this method makes it impossible to store negative custom values
This is also not true, a little knowledge of binary arithmetics will tell you that
every negative number is represented as 2-complement of its absolute value

This part of binary arythmetics is a must-know for any serious software developer,
and since advanced map-making is basically a programming i recommend people to learn it

It just takes some brainwork :banghead:
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top