HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Is there any way to make triggers more efficient?

05-30-2002, 05:13 AM#1
Guest
I read killfest...and I noticed that you generate creatures using standard actions (just you generate the correct number of creatures). I was wondering if there is a more efficient way to generate units.

Thank you for all your help, as all of you have been very helpful.

However, I have a problem with my map.

The map is kinda like the gauntlet, except I don't want to put units down static.

I want to generate them a few steps ahead when the heroes step on a certain region.

So they step on the certain region, and a few units are generated in the next region (a few steps down).

I have done this, and it is over 27 regions. Not only will it take tons of code (i already did first 4) but it lags when the units pop out. I mean it like freezes the screen for like .5 s, which is annoying, when units are being generated every 10 seconds.

I used a If Then Else statement, if picked unit = hero, then generate 2 skeleton warriors, else do nothing.

I wonder if the statement is the cause of the lag.

I noticed on the other maps such as zone control, there is no lag when the units popout.

Would it help if I seperated my statements? Into several If, then do nothings?

Would that make the unit pop out more efficient and less laggy.
05-30-2002, 07:46 AM#2
Guest
I have found that if you create a lot of units in a short amount of time, the game lags. Thus, it's not the efficiency of your trigger that is making the game lag, it's the fact that you're creating units on the map. For some reason that slows down the game a lot (probably because it has to look up the model, unit info, ai, and all that stuff whenever it places a unit.)
05-30-2002, 12:12 PM#3
Mr.123
I'm first noticing the problem in TD2 but not in TD or its variants. The thing I've been doing different is instead of 1 statement of "create 20 units of blah" I've been doing "For a = 1 to 9, create 4 units of blah". In some cases, it's "For a = 1 to 9, create 1 unit of blah, create 1 unit of blah, ... 4 times".

It's like using fwrite() to write a block of bytes is much faster than to write to disk 1 byte at a time.
05-30-2002, 06:56 PM#4
weaaddar
Actually a really trick way of doing this could be for making a unit apear like 1000 (thats just about a screen a way) you could do create a unit at a position trigger unit x coordinate+(or -)1000, or you could do it for y so you really don't need that 27 locations. Also killfest that is posted is kinda outdated (well 5.7 pretty good thats like the last thing posted). The new one is better but i can't seem to resolve the crash bug thats started with it.
05-30-2002, 07:34 PM#5
Guest
Hmmm...

Mr.123 what do you mean by doing a = 1 to 9, is that an integer?

Could you please attach your map?

Thanks

Yea the unit would appear weaaddar, but it would be neutral hostile...

I want it to engage aggro, thus I want the spawned unit to go to the next region where my heroes are.
05-30-2002, 08:08 PM#6
weaaddar
Engage aggro? maybe I could look at your map and help you.
05-30-2002, 09:19 PM#7
Mr.123
Code:
function Trig_Stage_16_Func008003 takes nothing returns nothing
    set udg_t1 = GetRandomInt(0, 11)
    call CreateNUnitsAtLoc( udg_NumUnitsPerWave/2, 'otau', Player(11), GetRectCenter(udg_SpawnArray[udg_t1]), bj_UNIT_FACING )
    call CreateNUnitsAtLoc( udg_NumUnitsPerWave/4, 'ohun', Player(11), GetRectCenter(udg_SpawnArray[udg_t1]), bj_UNIT_FACING )
    call CreateNUnitsAtLoc( udg_NumUnitsPerWave/4, 'Obla', Player(11), GetRectCenter(udg_SpawnArray[udg_t1]), bj_UNIT_FACING )
endfunction

    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 9
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        call Trig_Stage_16_Func008003()
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop

Cannot nest actions in for loops using the GUI so code is the only way. You can find a copy of my map in the downloads section by clicking the link near the top.
06-01-2002, 06:26 AM#8
3DGuy
man u r a L337 scripter/coder
06-01-2002, 09:03 AM#9
dataangel
How about this solution:

Don't do that ;)

Think about it. You don't want the units to be placed statically. But you're creating x number of them just before the player's hero comes into view -- so the player really can't tell the difference between them being statically placed and not being statically placed.

If you're trying to make a random monster system, I suggest you place 1 of each type of monster in an unreachable place somewhere else on your map. This way they'll already be loaded so the game won't freeze so much (that's just my theory anyway, I could be totally wrong). Also, to make it seem less static, have it spawn them at random points in the region.

Yes, you could do it more efficiently (I think). By putting strings together and having it interpret this as a location name...but I don't believe there's a convert string to region name thingy yet (although there is something like that for units). And in any case you'd have to do that in code.

BTW, if yer afraid of code but want multiple statements in a for loop, just run the for loop twice ;)

(granted this is not always possible and is less efficient)
06-01-2002, 08:37 PM#10
Guest
The problem with pre-placing all your units is that once you get over the 500-unit mark, it causes slowdowns for slower computers. And as you approach the 1000-unit mark, it causes slowdowns for even the fastest computers running this game. I ran into this problem in my rpg, where I had 800 units on the map and the game was choppy for everyone until they beat the first half of the map and cut it down to 400 units. I resolved this by making triggers to add the units, but this caused game freezes. So I put the loading triggers during the cinematics, when the game was paused anyway.
06-02-2002, 01:38 AM#11
dataangel
Follow DarkChronos lead and do it in big chunks. If you're using 27 locations your chunks aren't big enough. If your map is divided up into levels or areas, have it generate the guys for each area during a cinema, OR, you could do something (somewhat) clever like this:

Event
Player begins level1 (however you detec that)
Action
Generate first group of level2 units
Wait 10 seconds
Generate second group of level2 units
Wait 10 seconds
Generate third group of level 3 units

This way it's loading level2 as they go through level1 without tons of location triggers ;)
06-03-2002, 04:06 PM#12
Guest
Wouldn't it freeze the cinema?

Because I noticed when I generate 25 units at 0 s time elapsed, there is like a 5 second lag. I thought cinematics only zoomed in on the actual game (disabled units control, etc...). You are still in the game. So wont the cinematics be choppy?
06-03-2002, 04:21 PM#13
Guest
Hey Darkchrono...

Isn't it kinda dull if you do mass generation (all the units are kinda the same?). Isn't it good for the individual groups to be different?

Melt
06-03-2002, 04:28 PM#14
Guest
Yes, the cinematics will be choppy, but if it is just text (like a unit speaking) then all this amounts to is extra time for the players to read what is being said. It's certainly preferable to lag in the middle of a battle.

Personally, I hate the lag myself, but slowdown seems to annoy people more. You have to decide for yourself if you want the map to be slowed down most of the time or lagged for short amounts of time.

That's why you make the units and then move individual types to different areas. For example, tell it to move 4 footmen, 2 knights, and 3 priests to location 1, etc. You can also use this to randomize your map, by creating a location where all units come from, and tell it to move random units from that location onto the map.