HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

I have some trouble to trigger with array...

10-08-2003, 04:03 PM#1
ABM
I would like to make ordinary units able to gain exp as if they were heros, but there is a lot of unit and units type and each single units should gain xp when killing another unit....

how can i do this using array?

something like when array(unitkilling) add killedunit custom value to Xp(unitkilling)....

sometihng like when a unit kill another one the killing gain the custom value of the killed unit.
when the killing unit XP> 100 remove killing unit from game and create upgraded unit at position of killing units (Xp become 0).

or replace killing unit with upgraded units keeping the Xp of killing unit for the upgraded unit so the upgraded unit will need more Xp to upgrade.

but i think to always reset XP to 0 is easier and better so anyone would figure how to do this trigger who give pain to my little brain...
10-08-2003, 04:26 PM#2
ChronOmega
why not just amke them all hereos with out hero abilitys or the inventory ability?
10-08-2003, 04:42 PM#3
ABM
Well it is a good idea but do u think i can make hero to be a building unit without bugging to WE ?
and if it is a hero i wouldn't be able to control as well as i wish the gain of experience and the level up...
it would be better with trigger......

anyone good with array overhere??

Hellllllp.......!!
10-08-2003, 04:56 PM#4
Zachary_Shadow
Could do it like this:

Use integers, and do:

Event:
Unit dies
Cond:
Unit = Footman
Action:
Set Xp = +1


Event:
Every 2 seconds of game time
Cond:
Xp = 10
Action:
Replace "Unit" with "unit"

This trigger could work for a single player/unit, with a few more triggers added...but not for a player and all his units...but

What if you set:

Event:
Unit dies
Cond:
Killing unit = "unit"
Unit = Footman
Action:
Set Xp = +1 for killing "unit"

hmm, not sure...try it out..?
10-08-2003, 05:57 PM#5
Illithid
variables
xp, array of integers default value = 0, array size 8000
counter integer default value = 0
x interger

Triggers:
If you need to assign custom values to units that start on the map:
Event
Map initialization
Action
pick all units in playable map area and do
counter = counter +1
set cutom value of (picked unit) = counter
loop
If you have units spawning this will need to be added, just add the counter, custom value and set units(counter) part after each create unit action performed in your spwaning.
Event
periodic event
Action
Creat a unit
Counter=counter+1
set custom value of last created unit = counter


xp gain for killing units
Event
unit kills a unit
Condition(if you don't want heroes using this xp system)
killing unit not equal to hero
Action
set xp(custom value of (killing unit)) = xp(custom value of (Killing unit) + 1
if xp(custom value of (killing unit)) > 9 then
set x = custom value of (killing unit)
replace (killing unit) with (what ever upgraded unit level 2 would be)
set custom value of (replaced unit)= x

If you have multiple levels, there will be two ways you can do this one is to have a integer array named level that keeps track of the level of each unit in which case you will want to change the above if statement to compare xp and level of unit and then have a seperate if then statement for each level.
The other is to after each level up you set xp of that unit back down to zero and then have a check to check unit-type of killing unit and then change unit to next unit-type.

One small note about this, you will run into problems if you exceed the max of an array, there are to ways you can fix this, one is add a check that checks if counter has reached max array size and reset it back to zero(if a unit from the start lives this long though he will share a custom value with a newly created unit) This isn't to bad though due to the fact that a max array size is something like 8000 values so it won't likely happen.

The other way of doing it is whenever a unit dies, the highest unit in the array would get reassigned to the custom value of the dying unit. This requires another array of class unit and when you create a unit you would need to assign that unit a custom value first and then put them into this array with index equal to their custom value. Then the reassigning trigger would be:
Event
Unit Dies
Action
set custom value of (units(x)) = custom value of (dying unit)
set units(custom value of (dying unit)) = units(x)
set xp(custom value of (dying unit)) = xp(x)
set x=x-1

the only problem with the second method is if the first unit is brought back to life, again you will have a problem with multiple units having the same custom value, so you will need a trigger that detects a unit being brought back via animate dead or resserrection and assigning them new custom values. And they will lose their xp, if you are keeping xp with each level you can add a statement that gives them the base xp for being the level they are at.
10-09-2003, 01:51 PM#6
ABM
Thanks Illithid for spending so much time answering me i just have another little question whats the difference between an array(0) and an array with (1.2.3.4.etc) ?
10-09-2003, 05:06 PM#7
Illithid
When you create an array, what you are actually doing is creating several related variables. Array size determines how many variables you are creating.

arrayname(1) = first variable
arrayname(2) = second variable
and so on

in the code I gave you xp is an array that keeps track of experience of all the units in your map.
xp(1) = experience of first unit
xp(2) = experience of second unit
and so on

to explain the rest of the code I gave you, when a unit is created in a map, it has no information to identify it seperately from each other unit in your map. I used set custom value to give a unique number to each unit in your map. Then whenever xp array needs to be accessed to check the experience of a unit it looks at the custom value of the unit and uses that in the array to access the xp for that specific unit.

To explain the part at the end their about looping back the counter or to move units in the array down. As I had stated at the start of this article, when you create an array you are actually creating a number of variables equal to the size of the array. If you try and reference a number that is greater then the size of the array there will be no variable there to actually reference(this can cause the program to crash) so you have to prevent the array from trying to reference anything above the array size.