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 The Helper:
    Actually I was just playing with having some kind of mention of the food forum and recipes on the main page to test and see if it would engage some of those people to post something. It is just weird to get so much traffic and no engagement
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top