| 03-04-2007, 09:11 PM | #1 |
I set some regions that I want a random creep to spawn if there is no creep already in that region every 60 seconds. I set the regions and I know that I can create a trigger for each region however is there an easier way to do this? |
| 03-04-2007, 09:27 PM | #2 |
You're referring to a creep respawn system? YES! JASS:function Trig_RespawnInit_Actions takes nothing returns nothing local unit p //will be used to loop through each of the creeps, along with local group g=GetUnitsOfPlayerAll(Player(PLAYER_NEUTRAL_AGGRESSIVE)) //this - the unit group of EACH creep (minus the ones already looped through, you'll see what I mean) local integer eachUnit=0 //and this - the number that represents each creep individually. loop set p=FirstOfGroup(g) exitwhen (p==null) set eachUnit = (eachUnit + 1) set udg_neutral_point[eachUnit] = GetUnitLoc(p) set udg_neutral_type[eachUnit] = p call SetUnitUserData( p, eachUnit ) call GroupRemoveUnit(g,p) endloop call DestroyGroup( g) set eachUnit = 0 endfunction //=========================================================================== function InitTrig_RespawnInit takes nothing returns nothing set gg_trg_RespawnInit = CreateTrigger( ) call TriggerRegisterTimerEventSingle( gg_trg_RespawnInit, 0.01 ) call TriggerAddAction( gg_trg_RespawnInit, function Trig_RespawnInit_Actions ) endfunction AND JASS:function Trig_Neutral_Respawn_Actions takes nothing returns nothing local integer dyingUnitsCV set dyingUnitsCV = GetUnitUserData(GetDyingUnit()) // Set here because if i just used custom value of the dying unit below the wait, it could be a different dying unit. call TriggerSleepAction( 45.00 ) // This wait could be as long as you want it to be before the creeps respawn. call CreateNUnitsAtLoc( 1, GetUnitTypeId(udg_neutral_type[dyingUnitsCV]), Player(PLAYER_NEUTRAL_AGGRESSIVE), udg_neutral_point[dyingUnitsCV], bj_UNIT_FACING ) // Hopefully now why I used the custom value becomes imminent call SetUnitUserData( GetLastCreatedUnit(), dyingUnitsCV) //set the CV back to the unit because it's lost when the unit dies set dyingUnitsCV = 0 //still not sure whether this leaks. endfunction //=========================================================================== function InitTrig_Neutral_Respawn takes nothing returns nothing set gg_trg_Neutral_Respawn = CreateTrigger( ) call TriggerRegisterPlayerUnitEventSimple( gg_trg_Neutral_Respawn, Player(PLAYER_NEUTRAL_AGGRESSIVE), EVENT_PLAYER_UNIT_DEATH ) call TriggerAddAction( gg_trg_Neutral_Respawn, function Trig_Neutral_Respawn_Actions ) endfunction You'll need the following GLOBAL variables: neutral_type of unit type (ARRAY size 1) neutral_point of point type (ARRAY size 1) neutral_dying of integer type (NOT ARRAY) // I DID NOT MAKE THIS SYSTEM! I'm not sure who did though, because an author is not listed anywhere in the ancient map I got it from...although wheover DID make it got help from Blade.DK, so...thank him! |
| 03-04-2007, 09:31 PM | #3 |
Add the rects to an array and use a loop. JASS:function creeprespawn takes nothing returns nothing local rect r local integer i = 0 loop exitwhen i > the number of rects you made set r = rect_ar[i]//rect_ar is a global rect array (or a global region array if you used GUI to make it) //do your actions here set i = i + 1 endloop set r = null endfunction |
| 03-04-2007, 09:33 PM | #4 |
Botanic, a note on what you mentioned before: The "check every 60 seconds to recreate neutrals" system you mentioned using will work with wantok's function, but if creeps get led out of the rect at the point where the 60 second trigger occurs, you'll have 2 sets of creeps...plus working with rects is BAD! They tend to leak, and having global regions (rects) is even worse...the system I posted above doesn't require you to use any kind of regions..just make sure the neutrals you want to respawn are there at the beginning of the map. |
| 03-04-2007, 09:42 PM | #5 |
While WNxCryptic's code works, I doubt you'll be able to understand it. An easier way to do this would be:
I think that might work, and if you have troubles, post 'em here. If it doesn't work, I can post you whole triggers. |
| 03-04-2007, 09:46 PM | #6 |
The system WNxCryptic posted does seem like it would work better for you than what I posted. Unless you plan on having more than one creep in a region and only want one to respawn when all of the creeps in that region are dead. Then you'd have to add some more checks to it. Also you can replace CreateNUnitsAtLoc() with CreateUnitsAtLoc(). You really don't even need to understand this system to use it. The only thing you need to change is the TriggerSleepAction to the respawn time that you desire. Everything else is automated. |
| 03-04-2007, 10:37 PM | #7 |
thank you guys this wasnt quite what i was looking for but it led me in the right direction. |
