HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Triggering problem: Unit Group Array confusion :(

01-25-2003, 08:06 AM#1
Guest
Hi guys. Basically what I'm trying to do is create a bunch of areas where monsters will spawn at defined areas in certain intervals, but not if a group of monsters is already at that spot. In other words, I don't large monsters of spawned monsters piling up at low-traffic areas. The effect I'm after is identical to mods which feature groups of random creeps spawning at pre-set spots, such as Defense of the Ancients or Advanced Hero Arena 1.3 - monsters will spawn at each spot and stay there; if monsters are already at a spot, they will cease to further spawn at that point (avoiding the pileup effect), and after having a monster group cleared out for a while, after a set amount of time, they will respawn at that same spot.

So getting away from the background info, here's the triggering problem I've run into. (I use the Blizzard War3 world editor.)

Unit - Create 1 Skeleton Archer for Neutral Hostile at (Center of MonstersEasyRegion[(Integer A)]) facing 270.00 degrees
Unit Group - Add (Last created unit) to MonstersEasyGroup[(Integer A)]
Unit - Create 1 Kobold for Neutral Hostile at (Center of MonstersEasyRegion[(Integer A)]) facing 270.00 degrees
Unit Group - Add (Last created unit) to MonstersEasyGroup[(Integer A)]
Unit Group - Pick every unit in MonstersEasyGroup[(Integer A)] and do (Unit - Kill (Picked unit))

Of course I don't really intend to do a kill on all newly-spawned units; I was doing an 'enemy just created' special effect, but I eventually changed it to just a simple kill for debugging purposes.

So I start up the map and go near a monster group. They spawn, but nothing happens - they don't die like the code intends them to. So this means that they were never properly inserted into the unit group of the array, correct?

OK, so I'm doing some reading around, and I see some people talk about how unit group arrays have to be initialized in an odd way. (Specifically, they all have to be set to a dummy variable or something). So I try intializing them in a bunch of different ways, but weeeird things happen. If I, before the above code, put a single "Set MonstersEasyGroup[0] = MonstersTempGroup", then when the monsters spawn, ONE of the units will die (but not both). If I initialize the entire unit array to one unit group, e.g. "For Each [Integer A] from 0 to NumMonsterEasyGroups, Do Set MonstersEasyGroup[Integer A] = TempMonstersGroup", which results in BOTH monsters dying at startup in ONE group but not in ANOTHER (weird, since both monster creation calls were made from the same line of code) and flags resulting from unit group array checking not acting properly. I have also tried intializing each unit group in the array separately, e.g. Set MonstersEasyGroup[0] = MonstersEasyGroup0, MonstersEasyGroup[1] = MonstersEasyGroup1, etc. with no success. So in a nutshell, all kinds of buggy stuff has been happening. :(

As I read somewhere, generally when using the unit group array, using (Last created unit group) tends to work correctly if I call it right after I create a monster. The problem is that it only seems to work for ONE monster - I can't do a create, add last unit group, create, add last unit group to make a set of 2 different monsters in that group. If I do, when playtesting it, the 2nd monster doesn't act like it was ever part of the unit group.

The monsters groups spawn in the correct places; it's not a region array problem. The other parts of the spawning system, such as some of my integer timers and integer flags, act goofy, but I believe that's because the unit groups in the array that activate them are not functioning properly. (For instance, I have a trigger that, every X seconds, checks each unit group in the array to see if all of the monsters are dead, and if so, turns on the 'start countdown until those monsters respawn' flag.)

Back in an older version of my mod, when I didn't used to use unit group arrays, I could get things to work fine. But the project has taken on such a scale that I NEED to be able to use unit group arrays to avoid having to write millions of lines of trigger code.

I'm really tired of wrestling with this problem. If it weren't for this showstopper bug, my game would be virtually finished. :(

Does anyone know how to correctly initialize and use the unit array groups for more than one type of monster in each group or have an alternative solution? By the way, If you guys want me to copy the code for the entire monster spawning portion of my MOD, I'll be happy to do it if it may be of help.

Many thanks in advance to all who respond, because I'm starting to feel like the guy in this picture: :////
01-25-2003, 10:18 PM#2
AIAndy
A unit group variable is a kind of pointer. That means you have to create the actual unit group after declaring the variable. When you create a standard unit group variable in WE then it does that for you. For arrays you have to do that yourself. Unfortunally WE allows AFAIK no access to that function outside of custom text.
So you have to do run the following function before using the unit groups:

local integer i = 0
loop
exitwhen i == GroupNumber
set uga[i] = CreateGroup()
set i = i + 1
endloop

replace uga with the name of the array and GroupNumber with the number of groups you want to have in that array.
01-26-2003, 04:28 AM#3
Guest
Thanks for the response. I haven't been able to try what you recommended yet, because I don't know how to insert custom text yet. emote_confused I tried searching Google, this site, and maps.warcraftiii.net tutorials to no avail before trying to pull off something crazy which obviously didn't work.

Here is what I tried to do. My only idea was to try to copy what the WarChasers mod did; there is a call to "Game - Preload all files listed in scripts\WarChasers.pld" that gets called at map initialization before anything else. So that was my only real remaining idea.

I made a folder in my War3 directory called scripts and then created a file called scripts.txt with the information:

function initialize_unitgrouparrays takes nothing returns nothing
local integer i = 0
loop
exitwhen i == 2 (because there are only 2 unit groups in my array right now)
set MonstersEasyGroup[i] = CreateGroup()
set i = i + 1
endloop
endfunction

That's all the file contains; I'm pretty sure it's not even coded correctly because, as I said, I don't have experience with adding custom text to war3 mods. :[ Then in my game initialization, I added "Game - Preload scripts\scripts.txt", and saved the map, followed by my using WinMPQ and adding scripts\scripts.txt to my map. Then I tried it all out, but it didn't work.

Is it possible that I could be instructed or pointed to a resource that explains how to add custom text to a map? OR could I be told what what I did wrong? :( I'm pretty sure I just made a dumb, simple mistake that someone could easily point out in just a minute or two.

Thanks...
01-26-2003, 01:22 PM#4
AIAndy
To use custom text triggers in WE, just make a trigger and then use the menu option convert to custom text.
01-27-2003, 02:21 AM#5
Guest
OK, but what else do I have to do? I have this in my map:


[Trigger 1:] Game Initialization
(lots of stuff)
Trigger - Run Initialize Unit Group Arrays <gen> (checking conditions)

[Trigger 2:] Initialize Unit Group Arrays
function Trig_Initialize_Unit_Group_Arrays_Actions takes nothing returns nothing
local integer i = 0
loop
exitwhen i == MonstersEasyNumGroups
set MonstersEasyGroup[i] = CreateGroup()
set i = i + 1
endloop
endfunction

//===========================================================================
function InitTrig_Initialize_Unit_Group_Arrays takes nothing returns nothing
set gg_trg_Initialize_Unit_Group_Arrays = CreateTrigger( )
call TriggerAddAction( gg_trg_Initialize_Unit_Group_Arrays, function Trig_Initialize_Unit_Group_Arrays_Actions )
endfunction


However, the map won't let me enable the Initialize Unit Group Arrays trigger because of compile errors.

Line 117: Expected a name
Line 118: Expected a variable name

Can someone please tell me what I'm doing wrong in setting up this custom-text trigger? BTW, I don't even know how to see the line numbers, so I can't even say what lines the errors are on. :(
01-27-2003, 11:19 AM#6
AIAndy
The script names of variables in WE are not exactly the same as the name you give them. I think they have a udg_ prefix or something similar. To find out the name create a trigger that uses that variable and then convert it to custom text.
01-27-2003, 04:17 PM#7
CBWhiz
yes, its udg_ for user-defined-global.

just add udg_ before mosterspawnarray
01-30-2003, 04:06 AM#8
Guest
Wow! I got it working... well, for the most part. For some reason, the debug code I had to immediately kill all units in the unit group right after creation STILL wasn't working - the first monster would die, but the rest woudln't. HOWEVER, the crazy thing is, when I changed that line back to what I originally wanted anyway (which was to play a special effect on those monsters in the unit group), it works fine. I did not alter any other line other than change the "pick all units in unit group and kill" to "pick all units in unit group and play X special effect," nor did I change any variables or anything else. Apparently there is something unusual about the kill command with regards to the way I used it that I don't understand. :bgrun:

Anyway, regardless of that, the unit groups appear to be acting as expected now. I can check to see if they're empty now, etc. and it works fine. It's great!

Thanks for all the help on this, guys! :D