HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

a Unit Dies... event and it's relation to an Array?

05-04-2004, 10:12 PM#1
Dalten
Say I have 100 units assigned to a Unit Array.

Then lets say that one of them dies, doesn't matter how where why or when..... how do I query what unit it was without a huge IF loop?

For example, a Bandit is assigned the variable in my array: Unit(43) Say the Bandit dies, how can I get the game to recognize what Array unit(in this case, 43), died? I know of two solutions, neither of which I want to use:

1) a lenghty If/Then loop comparing if Triggering Unit is = the Unit(Variable A) but I imagine this would add a ton of lag for some people.
2) use Custom Value's of Unit... but i'm using that for someone else and I don't see this changing.

Any suggestions?
05-04-2004, 11:28 PM#2
Saboera
u are really in the wrong forum... post that in trigger haven
05-05-2004, 02:30 AM#3
th15
Sorry man but using massive if-loops to traverse an array is PRECISELY what arrays were designed for. What i can tell you is that it doesn't take too much CPU power to run the conditions of an if-loop so go ahead and loop it.

On another note, you can use multi-dimensional unit custom values. What i mean is that you can use 1 digit to mean something for one trigger and use the other digit to mean something for the other trigger. Simply do integer division and it drops fractions for you so you could have the tens digit mean whether the unit is alive or dead and the ones digit mean how much extra exp it gives a player when it's kiled.

Quote:
Originally Posted by Dalten
Say I have 100 units assigned to a Unit Array.

Then lets say that one of them dies, doesn't matter how where why or when..... how do I query what unit it was without a huge IF loop?

For example, a Bandit is assigned the variable in my array: Unit(43) Say the Bandit dies, how can I get the game to recognize what Array unit(in this case, 43), died? I know of two solutions, neither of which I want to use:

1) a lenghty If/Then loop comparing if Triggering Unit is = the Unit(Variable A) but I imagine this would add a ton of lag for some people.
2) use Custom Value's of Unit... but i'm using that for someone else and I don't see this changing.

Any suggestions?
05-05-2004, 03:16 AM#4
Dalten
Quote:
Originally Posted by th15
Sorry man but using massive if-loops to traverse an array is PRECISELY what arrays were designed for. What i can tell you is that it doesn't take too much CPU power to run the conditions of an if-loop so go ahead and loop it.

On another note, you can use multi-dimensional unit custom values. What i mean is that you can use 1 digit to mean something for one trigger and use the other digit to mean something for the other trigger. Simply do integer division and it drops fractions for you so you could have the tens digit mean whether the unit is alive or dead and the ones digit mean how much extra exp it gives a player when it's kiled.

Good suggestion bro, i'll play with it. Currently i'm using the custom values for a single function that needs, i'm guessing a max of 3 digits. Couldn't i use more than 2 digits for multiple purposes?

Just thinking about it a lil(haven't tried it yet), but i'm having a problem coming up with the concept. I can ASSIGN the values no problem, but ripping them out is a problem.

Nm i think i got it, i'm using the substring functions to rip out the values i need. For example unit 155 has resist of 50, then his value will be 155050 and i'll use substrings to separate the variable.

Thanks for putting me on the right path!
05-05-2004, 11:07 AM#5
Cubasis
uhh.

http://kattana.users.whitehat.dk/viewfunc.php?id=252

Usage:
For each (Integer A) from 1 to 100, do (Actions)
Loop - Actions
Custom Script: call SetHandleInt(udg_Unit[GetForLoopIndexA()],"Index",GetForLoopIndexA)

Put that in some initiation trigger. (It basicly loops all the unit, and uses SetHandleInt to attach (Integer A) onto Unit[(Integer A)] using label: "Index".)

Then, when you want to use it (in the death trigger), just:

Custom Script: set udg_TempInt = GetHandleInt(GetDyingUnit(),"Index")

(Using "GetHandleInt", gets the integer attached onto the Dying Unit on label: "Index", and stores it in TempInt).

Note, TempInt must be a integer variable, you can change it to anything you want.

Oh, and for this to work, you must have CnP'ed the content of the site linked above into your custom Script area.

Cubasis
05-05-2004, 04:29 PM#6
Vexorian
You can also use a unit group instead of a unit array?
05-05-2004, 04:44 PM#7
Traeon-
Quote:
Originally Posted by Dalten
Say I have 100 units assigned to a Unit Array.

Then lets say that one of them dies, doesn't matter how where why or when..... how do I query what unit it was without a huge IF loop?

For example, a Bandit is assigned the variable in my array: Unit(43) Say the Bandit dies, how can I get the game to recognize what Array unit(in this case, 43), died? I know of two solutions, neither of which I want to use:

1) a lenghty If/Then loop comparing if Triggering Unit is = the Unit(Variable A) but I imagine this would add a ton of lag for some people.
2) use Custom Value's of Unit... but i'm using that for someone else and I don't see this changing.

Any suggestions?

Checking coditions takes virtually no CPU power, you should at least give the IF-THEN approach a try.
05-05-2004, 06:46 PM#8
Cubasis
Quote:
Originally Posted by Traeon-
Checking coditions takes virtually no CPU power, you should at least give the IF-THEN approach a try.

{OffTopic}
Not for the prescot :P
{/OffTopic}

:D
05-05-2004, 09:34 PM#9
ThyFlame
Quote:
Originally Posted by th15
Simply do integer division and it drops fractions for you so you could have the tens digit mean whether the unit is alive or dead and the ones digit mean how much extra exp it gives a player when it's kiled.

I'm wondering exactly what you mean by "it drops fractions", since integers are whole numbers.
05-05-2004, 11:53 PM#10
Panto
So, ThyFlame, what happens when you divide 23 by 10? You get 2.3, right? Unless you're using Integers, in which case it "drops" the .3, and you have just 2.

The system is sound, and reliable.
05-06-2004, 12:22 AM#11
Cubasis
Yes, and just so I add a (another) seemingly useless post into this thread with another example to Panto's explenation, just to clear one more possible confusion:

So 28 / 10 "also" becomes 2. Even though in decimal it's 2.8. That's how integer-division works. So even a real: 2.99 becomes a 2 as integer.

Cubasis