storing unit locations

Jooster

New Member
Reaction score
7
alright so i have pre-placed units on the map. determined upon a terrain selection. there are sever rects laid out throughout the map. each unit pre-placed in these regions, if are killed, i would like them to re spawn. i got one alright trigger that gives the unit a integer value and im using

Code:
set udg_Creep_X[udg_TriggerName] = GetUnitX(GetEnumUnit())
set udg_Creep_Y[udg_TriggerName] = GetUnitY(GetEnumUnit())

but when its time to respawn the unit back in its allocating spot it will respawn on the exact opposite side of the map or smack in the center of the map.

is there a easier way of going about this? *edit* forgot to mention this. Is it possible to use a custom script that sets the units rect instead of X,Y co-ordinates?
 

Exide

I am amazingly focused right now!
Reaction score
448
X and Y coordinates are quicker, but more troublesome to use.
I'd suggest you simply use Points.
(I have no idea what your udg_TriggerName is, but I trust you do. :p)

Code:
Setup
    Events
        Time - Elapsed game time is 1.00 seconds
    Conditions
    Actions
        Set tempgroup = (Units in (Playable map area) owned by Neutral Hostile)
        Unit Group - Pick every unit in tempgroup and do (Actions)
            Loop - Actions
                Unit - Set the custom value of (Picked unit) to loopinteger
                Set creepspawn[loopinteger] = (Position of (Picked unit))
                Set loopinteger = (loopinteger + 1)
        Custom script:   call DestroyGroup(udg_tempgroup)

Code:
Respawn
    Events
        Unit - A unit Dies
    Conditions
        (Owner of (Triggering unit)) Equal to Neutral Hostile
    Actions
        Wait 30.00 game-time seconds
        Hero - Instantly revive (Triggering unit) at creepspawn[(Custom value of (Triggering unit))], Hide revival graphics

Variables:
creepspawn = Point - array variable
loopinteger = integer variable
tempgroup = unit group variable


With X and Y:

Code:
Setup
    Events
        Time - Elapsed game time is 1.00 seconds
    Conditions
    Actions
        Set tempgroup = (Units in (Playable map area) owned by Neutral Hostile)
        Unit Group - Pick every unit in tempgroup and do (Actions)
            Loop - Actions
                Unit - Set the custom value of (Picked unit) to loopinteger
                Set creepspawnX[loopinteger] = (X of (Position of (Picked unit)))
                Set creepspawnY[loopinteger] = (Y of (Position of (Picked unit)))
                Set loopinteger = (loopinteger + 1)
        Custom script:   call DestroyGroup(udg_tempgroup)

Code:
Respawn
    Events
        Unit - A unit Dies
    Conditions
        (Owner of (Triggering unit)) Equal to Neutral Hostile
    Actions
        Wait 30.00 game-time seconds
        Hero - Instantly revive (Triggering unit) at (Point(creepspawnX[(Custom value of (Triggering unit))], creepspawnY[(Custom value of (Triggering unit))])), Hide revival graphics

Same variables as before, but with two new:

creepspawnX = real - array variable
creepspawnY = real - array variable



with custom scripts:

Code:
Custom script:   set udg_creepspawnX[loopinteger] = GetUnitX(GetEnumUnit())
Custom script:   set udg_creepspawnY[loopinteger] = GetUnitY(GetEnumUnit())


with JASS:

JASS:

function Trig_Setup_Group_Actions_Func takes nothing returns nothing
    local integer loopinteger = 1

    call SetUnitUserData( GetEnumUnit(), loopinteger )
    set udg_creepspawnX[loopinteger] = GetUnitX(GetEnumUnit())
    set udg_creepspawnY[loopinteger] = GetUnitY(GetEnumUnit())
    set loopinteger = ( loopinteger + 1 )
endfunction

function Trig_Setup_Actions takes nothing returns nothing
    local group tempgroup = GetUnitsInRectOfPlayer(GetPlayableMapRect(), Player(PLAYER_NEUTRAL_AGGRESSIVE))

    call ForGroup( tempgroup, function Trig_Setup_Group_Actions_Func )

    call DestroyGroup(tempgroup)
    set tempgroup = null
endfunction

//===========================================================================
function InitTrig_Setup takes nothing returns nothing
    local trigger Setup = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( Setup, 1.00 )
    call TriggerAddAction( Setup, function Trig_Setup_Actions )
endfunction


(With JASS you're using two local variables (loopinteger and tempgroup) so udg_loopinteger and udg_tempgroup aren't needed.)

JASS:

function Trig_Respawn_Conditions takes nothing returns boolean
    return ( GetOwningPlayer(GetTriggerUnit()) == Player(PLAYER_NEUTRAL_AGGRESSIVE) )
endfunction

function Trig_Respawn_Actions takes nothing returns nothing
    local integer cvalue = GetUnitUserData(GetTriggerUnit())

    call PolledWait( 30.00 )
    call ReviveHero( GetTriggerUnit(), udg_creepspawnX[cvalue], udg_creepspawnY[cvalue], false )
endfunction

//===========================================================================
function InitTrig_Respawn takes nothing returns nothing
    local trigger Respawn = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( Respawn, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( Respawn, Condition( function Trig_Respawn_Conditions ) )
    call TriggerAddAction( Respawn, function Trig_Respawn_Actions )
endfunction
 

Vassilev

New Member
Reaction score
39
Hmmm...

You don't have a periodic timer that constantly updates the position of the heros?

Also..

Code:
Respawn
    Events
        Unit - A unit Dies
    Conditions
        (Owner of (Triggering unit)) Equal to Neutral Hostile
    Actions
        Wait 30.00 game-time seconds
        Hero - Instantly revive (Triggering unit) at creepspawn[(Custom value of (Triggering unit))], Hide revival graphics

I think the "triggering unit" might have phased out of existance from the game by the time 30 seconds have passed :p (decayed and removed from game, thus undetectable, had this problem before -.-")
 

vypur85

Hibernate
Reaction score
803
Heroes won't decay till inexistence. They will still be there unless you remove them. But creeps will. If I'm not mistaken, creeps decay time is about 1 minute. Anyway, I don't think this will work on normal units:

Code:
Hero - Instantly revive (Triggering unit) at creepspawn[(Custom value of (Triggering unit))], Hide revival graphics

It's used for heroes. For units, you need to create an entirely new unit.

Also, showing the entire trigger may help.
 

Vassilev

New Member
Reaction score
39
Heroes won't decay till inexistence. They will still be there unless you remove them. But creeps will. If I'm not mistaken, creeps decay time is about 1 minute. Anyway, I don't think this will work on normal units:

ah.. my bad :p

the problem with my trigger was that i grouppicked after 30 seconds and it didn't detect the dead heroes... or maybe it was just my boolean..
 

Jooster

New Member
Reaction score
7
exide, my spawn system is almost EXACTLY like what u sugguested. i just have multiple levels of units to spawn. I.E lvl 1/2/3 types of spawning groups. if that makes any sense. thats all working great. my only problem is what i suggested before. the group of units are being spawned at the center of the map. not where they were. its prtty frustrating.

ok so this is what i got.

Code:
ashenvale creeps
    Events
        Time - Elapsed game time is 40.00 seconds
    Conditions
    Actions
        Unit - Create 2 Timber Wolf for Neutral Hostile at (Center of creeps 1 north <gen>) facing Default building facing (270.0) degrees
        Unit - Create 1 Giant Wolf for Neutral Hostile at (Center of creeps 1 north <gen>) facing Default building facing (270.0) degrees
        Unit - Create 3 Dark Troll for Neutral Hostile at (Center of creeps 2 north <gen>) facing Default building facing (270.0) degrees
        Unit - Create 1 Dark Troll Shadow Priest for Neutral Hostile at (Center of creeps 2 north <gen>) facing Default building facing (270.0) degrees
        Unit - Create 2 Dark Troll Shadow Priest for Neutral Hostile at (Center of creeps 3 north <gen>) facing Default building facing (270.0) degrees
        Unit - Create 2 Giant Spider for Neutral Hostile at (Center of creeps 3 north <gen>) facing Default building facing (270.0) degrees
        Unit - Create 1 Dire Wolf for Neutral Hostile at (Center of creeps 3 north <gen>) facing Default building facing (270.0) degrees
        Trigger - Run creep values Changing <gen> (checking conditions)
        Sound - Play creeps_entering <gen>
        Game - Display to (All players) the text: |cffffcc00-Level 1-...
        Trigger - Turn on ashenvale creeps L2 <gen>


Code:
ashenvale creeps L2
    Events
        Time - Elapsed game time is 300.00 seconds
    Conditions
    Actions
        Unit Group - Pick every unit in (Units in (Playable map area) owned by Neutral Hostile) and do (Actions)
            Loop - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        ((Triggering unit) is A Hero) Not equal to True
                    Then - Actions
                        Unit - Remove (Picked unit) from the game
                    Else - Actions
        Unit Group - Destroy unit group (Last created unit group)
        Unit - Create 2 Giant Wolf for Neutral Hostile at (Center of creeps 1 north <gen>) facing Default building facing (270.0) degrees
        Unit - Create 1 Dire Wolf for Neutral Hostile at (Center of creeps 1 north <gen>) facing Default building facing (270.0) degrees
        Unit - Create 3 Dark Troll Berserker for Neutral Hostile at (Center of creeps 2 north <gen>) facing Default building facing (270.0) degrees
        Unit - Create 1 Dark Troll High Priest for Neutral Hostile at (Center of creeps 2 north <gen>) facing Default building facing (270.0) degrees
        Unit - Create 2 Dark Troll High Priest for Neutral Hostile at (Center of creeps 3 north <gen>) facing Default building facing (270.0) degrees
        Unit - Create 2 Brood Mother for Neutral Hostile at (Center of creeps 3 north <gen>) facing Default building facing (270.0) degrees
        Unit - Create 3 Dire Wolf for Neutral Hostile at (Center of creeps 3 north <gen>) facing Default building facing (270.0) degrees
        Trigger - Run creep values Changing <gen> (checking conditions)
        Sound - Play creeps_entering <gen>
        Game - Display to (All players) the text: |cffffcc00-Level 2-...
        Trigger - Turn on ashenvale creeps L3 <gen>

Code:
ashenvale creeps L3
    Events
        Time - Elapsed game time is 600.00 seconds
    Conditions
    Actions
        Unit Group - Pick every unit in (Units in (Playable map area) owned by Neutral Hostile) and do (Actions)
            Loop - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        ((Triggering unit) is A Hero) Not equal to True
                    Then - Actions
                        Unit - Remove (Picked unit) from the game
                    Else - Actions
        Unit Group - Destroy unit group (Last created unit group)
        Unit - Create 2 Dire Wolf for Neutral Hostile at (Center of creeps 1 north <gen>) facing Default building facing (270.0) degrees
        Unit - Create 1 Dark Troll Warlord for Neutral Hostile at (Center of creeps 1 north <gen>) facing Default building facing (270.0) degrees
        Unit - Create 4 Dark Troll Berserker for Neutral Hostile at (Center of creeps 1 north <gen>) facing Default building facing (270.0) degrees
        Unit - Create 3 Dark Troll Warlord for Neutral Hostile at (Center of creeps 2 north <gen>) facing Default building facing (270.0) degrees
        Unit - Create 2 Dark Troll High Priest for Neutral Hostile at (Center of creeps 2 north <gen>) facing Default building facing (270.0) degrees
        Unit - Create 2 Dark Troll High Priest for Neutral Hostile at (Center of creeps 3 north <gen>) facing Default building facing (270.0) degrees
        Unit - Create 2 Brood Mother for Neutral Hostile at (Center of creeps 3 north <gen>) facing Default building facing (270.0) degrees
        Unit - Create 3 Dire Wolf for Neutral Hostile at (Center of creeps 3 north <gen>) facing Default building facing (270.0) degrees
        Unit - Create 1 Satyr Hellcaller for Neutral Hostile at (Center of creeps 3 north <gen>) facing Default building facing (270.0) degrees
        Trigger - Run creep values Changing <gen> (checking conditions)
        Sound - Play creeps_entering <gen>
        Game - Display to (All players) the text: |cffffcc00-Level 3-...


Then..... these are the spawn/custom value triggers

Code:
creep values initialization
    Events
    Conditions
    Actions
        Set unit_group = (Units in (Playable map area) owned by Neutral Hostile)
        Unit Group - Pick every unit in (Units in (Playable map area) owned by Neutral Hostile) and do (Actions)
            Loop - Actions
                Set Creep_Value = (Creep_Value + 1)
                Unit - Set the custom value of (Picked unit) to Creep_Value
                Custom script: set udg_Creep_X[udg_Creep_Value] = GetUnitX(GetEnumUnit())
                Custom script: set udg_Creep_Y[udg_Creep_Value] = GetUnitY(GetEnumUnit())
        Custom script: call DestroyGroup (udg_unit_group)

Notice the trigger above and the trigger below are the same in a sense. just one dumps the value of the LVL1 and 2 creeps to reset the custom value for the next creeps entering the map when told to run.

Code:
creep values Changing
    Events
    Conditions
    Actions
        Set Creep_Value = 0
        Set unit_group = (Units in (Playable map area) owned by Neutral Hostile)
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                ((Triggering unit) is A Hero) Not equal to True
            Then - Actions
                Unit Group - Pick every unit in (Units in (Playable map area) owned by Neutral Hostile) and do (Actions)
                    Loop - Actions
                        Set Creep_Value = (Creep_Value + 1)
                        Unit - Set the custom value of (Picked unit) to Creep_Value
                        Set Creep_Spawnpoint[Creep_Value] = (Position of (Picked unit))
            Else - Actions
        Custom script: call DestroyGroup (udg_unit_group)

AND finally the respawn code

Code:
creep respawn
    Events
        Unit - A unit Dies
    Conditions
        ((Owner of (Triggering unit)) Equal to Neutral Hostile) and (((Triggering unit) is Summoned) Not equal to True)
    Actions
        Wait 60.00 seconds
        Unit - Create 1 (Unit-type of (Triggering unit)) for Neutral Hostile at Creep_Spawnpoint[(Custom value of (Triggering unit))] facing Default building facing (270.0) degrees
        Unit - Set the custom value of (Triggering unit) to (Custom value of (Triggering unit))
        Custom script: call RemoveLocation (udg_Creep_Spawnpoint)
*edit* forgot to ask, when i run these. it seems like after about 3 cycles through a section of creeps they just quit respawning all together.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top