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

MUI Using Custom Value

Status
Not open for further replies.
Level 10
Joined
Sep 3, 2009
Messages
458
So I as wondering if this would work.

You first create a integer variable. Let's call it MaxValue which is at the start 0.

Now when a unit (considering conditions; a ground unit, a hero etc.) enters the map you set MaxValue = MaxValue + 1. Then set that unit's custom value to MaxValue. I can describe this as IDing a unit so that you can just use, let's say, FireCaster[customvalueofunit] since the value will always be unique to that unit.

Also when a temporary unit let's say, a creep dies, then we can do MaxValue = MaxValue - 1. Won't this maybe make triggering easier. Haven't tested yet, I was just wondering a few days ago cause it there was a massive blackout.

Your thoughts?
 
Level 10
Joined
Sep 3, 2009
Messages
458
Well the -1 your subracting here won't necessarily be the ID of the unit that died. So the next unit would have the same ID as the last unit that entered the map.

Most people just use unit-handles in hashtables to gain MUI functionality

Well MaxValue is used as a counter here. When a unit dies, is removed yada yada, we minus it by 1. Now when another unit is created we again add +1 to MaxValue then set that value to the new unit's custom value. It's sorta overwrites the previous one.

You are describing a wrong way of indexing. Go to Spells' section and search for indexing systems. You will realise how they work. So yeah, your way is not new; this is what Indexing Systems do. :)

well I already use an indexing system from the spells section just wondered if this would work for something I wanted to do which is technically:

Giving a basic unit (not a hero) stats through triggers. I can technically make use of this I guess. For example I:

Constants for unit type ghoul:

GhoulStr = 1, GhoulMgc = 2 , GhoulDef = 3

So technically the unit is created and enters the map. MaxValue = MaxValue + 1.

Str[custom value of unit] = GhoulStr and so on.

Now I can freely do let's say, a skill that lessens strength. I can do set Str[custom value of unit] = Str[custom value of unit] - 1.

Something like that. So what do you think?
 
Raven0 told you something:
Well the -1 your subracting here won't necessarily be the ID of the unit that died.

I insist that this method is really generic and might meet many troubles. A unit entering the map is way broad. A hero that is created is considered to enter the map, but a hero that revives is also firing the "A unit enters (Playable map area)" event.
 
Level 10
Joined
Sep 3, 2009
Messages
458
Raven0 told you something:


I insist that this method is really generic and might meet many troubles. A unit entering the map is way broad. A hero that is created is considered to enter the map, but a hero that revives is also firing the "A unit enters (Playable map area)" event.

Well for the firing part I can just use a condition to check what units I want to set, can't I?
 
Level 13
Joined
Mar 24, 2010
Messages
950
Idk, i have experienced in the past when a hero revives it doesn't fire off the A unit enters map area again, it only does the first time, because that hero never truly leaves the map area, right.
 
Level 10
Joined
Sep 3, 2009
Messages
458
That would require a hashtable, to save a value on the hero (boolean for easier triggering), to check whether the hero already has the value. That would of course stay out of the indexing systems, because hashtables can do the job just fine, so, we end up using hashtables once again.

well I wont be using it on heroes though, I'll be using it on units.
 
Don't use custom values. Use array variables or hashtables(in normal WE only).
But anyways, you need 2 Integers, eg. MaxValue and TotalValue. MaxValue is the largest array. TotalValue is the integer that you will be decreasing. So, when you create a unit, set both integers to +1, but when one dies, set only TotalValue to -1. When TotalValue reaches 0, then it is safe to assume there are no more arrays, and so you can set MaxValue to 0 when this happens.
 
Level 19
Joined
Feb 4, 2009
Messages
1,313
Don't use custom values. Use array variables or hashtables(in normal WE only).
But anyways, you need 2 Integers, eg. MaxValue and TotalValue. MaxValue is the largest array. TotalValue is the integer that you will be decreasing. So, when you create a unit, set both integers to +1, but when one dies, set only TotalValue to -1. When TotalValue reaches 0, then it is safe to assume there are no more arrays, and so you can set MaxValue to 0 when this happens.

I prefer my way of indexing
you only need 1 max variable

cast event:
max = max + 1

loop:
for each integer i from 1 to max
if time > 0 or something do
some actions
else
spell is over so we take all data from the last slot and put it in the current one
set unit = unit[max]
set max = max - 1
set i = i - 1
if i < 1 (or == 0) turn of trigger
end of loop

so you will always have all slots from 1 to max occupied

edit: moved if to the else as maker pointed out
but you will have to make sure that you turn off the trigger at map ini since else it will loop until the spell is casted the first time (or whatever you are doing with the loop)
 
Last edited:
Don't use custom values. Use array variables or hashtables(in normal WE only).
But anyways, you need 2 Integers, eg. MaxValue and TotalValue. MaxValue is the largest array. TotalValue is the integer that you will be decreasing. So, when you create a unit, set both integers to +1, but when one dies, set only TotalValue to -1. When TotalValue reaches 0, then it is safe to assume there are no more arrays, and so you can set MaxValue to 0 when this happens.

I dont see the point of using both MaxValue and TotalValue, they're both just integers right? (or maybe I just dont see it coz there are no triggers on how ur using them...)

anyway I always do it like D4RK_G4ND4LF's method...
 
If you have one integer, MaxValue, and you constantly decrease and increase it, it will loose track of all the arrays.
eg. MaxValue is currently 5. Unit[2] dies, setting MaxValue to 3 instead of 4. But what if Unit[4] is still alive? He gets missed out in the count.
But if you use 2 integers, MaxValue and TotalValue, this won't happen.
eg. MaxValue and TotalValue is currently 10. Unit[5] dies, setting TotalValue to 9 instead of 10. However, MaxValue remains the same for any units still left, like Unit[10]. TotalValue will decrease by 1 every time a Unit[] dies, so when it finally reaches 0, there are no more Unit[]s alive, and so that means the max number is 0, and THAT means you can set MaxValue to 0, reseting the whole array.

Most people do it my way. It is a lazy way, but there is little advantage/disadvantage between the 2 ways.
 
If you have one integer, MaxValue, and you constantly decrease and increase it, it will loose track of all the arrays.
eg. MaxValue is currently 5. Unit[2] dies, setting MaxValue to 3 instead of 4. But what if Unit[4] is still alive? He gets missed out in the count.
But if you use 2 integers, MaxValue and TotalValue, this won't happen.
eg. MaxValue and TotalValue is currently 10. Unit[5] dies, setting TotalValue to 9 instead of 10. However, MaxValue remains the same for any units still left, like Unit[10]. TotalValue will decrease by 1 every time a Unit[] dies, so when it finally reaches 0, there are no more Unit[]s alive, and so that means the max number is 0, and THAT means you can set MaxValue to 0, reseting the whole array.

Most people do it my way. It is a lazy way, but there is little advantage/disadvantage between the 2 ways.

oh... I see... a still like the other way... I'm to used to it... ^^
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
spell is over so we take all data from the last slot and put it in the current one
set unit = unit[max]
set max = max - 1
set i = i - 1
end of loop
if i < 1 (or == 0) turn of trigger


I see that a lot. It makes the i == 0 check once per loop, whic is often once per 0.03 seconds. However in many cases it should be

set unit = unit[max]
set max = max - 1
set i = i - 1
if i < 1 (or == 0) turn of trigger
end of loop

i can't be 0 if it isn't subtracted from. So why check it at the end of the loop. This way saves a lot of functions calls usually.

I repeat that this does not apply to all cases, but does for many many spells I see in the spell section for example.
 
Status
Not open for further replies.
Top