Respawn creeps.

Crazy_Dead

New Member
Reaction score
24
Your trigger isn't going to work if the triggering unit disappears from the game by decay, Lifee. Furthermore, that trigger example leaks more than just a location and will cause the game to lag.

A system isn't something that takes only one line of GUI. We'll first be able to help you on this subject once you are willing to accept that there is work and a learning process involved in making a map.

@Next Post by Lifee

1st: Your trigger leaks.
2nd: Check Quote.
 

apostolis

New Member
Reaction score
1
i tried both .When i put time for example 3 sec just to see if its working its working but when i put 300 sec they never respawn
 

Seprest

New Member
Reaction score
15
After the wait time create 1 temporary point will be set to a random point in a desired region. Check if there are no units in the area, if there isn't spawn the a unit of type of dying unit. Destroy temp points.

Wouldn't that be fine for a simple creep respawn trigger?

You may also want to create some code to check what region the unit should spawn in.
 

apostolis

New Member
Reaction score
1
it seems that when a creep is not been respawned(for any reazon) blocks all the respawns that must be done.I dont get it thought but i thing thats the reason why its not working
 

OneBadPsycho

10100111001
Reaction score
93
A simple respawn system could look like this:

First we set the creep respawn points, using their own unique custom value.
Code:
Creep Setup
    Events
        Map initialization
    Conditions
    Actions
        Set [COLOR="Red"]TempGroup[/COLOR] = (Units owned by [COLOR="SeaGreen"]Player owning your creeps![/COLOR])
        Unit Group - Pick every unit in [COLOR="Red"]TempGroup[/COLOR] and do (Actions)
            Loop - Actions
                Set [COLOR="Red"]Integer[/COLOR] = ([COLOR="Red"]Integer[/COLOR] + 1)
                Unit - Set the custom value of (Picked unit) to [COLOR="Red"]Integer[/COLOR]
                Set [COLOR="Red"]CreepLoc[/COLOR][[COLOR="Red"]Integer[/COLOR]] = (Position of (Picked unit))
        Custom script:   call DestroyGroup(udg_[COLOR="Red"]TempGroup[/COLOR])

Then we make a trigger, which checks for the owner, whenever a unit dies.
Code:
Respawn
    Events
        Unit - A unit Dies
    Conditions
        (Owner of (Dying unit)) Equal to [COLOR="SeaGreen"]Player owning your creeps![/COLOR]
    Actions
        Wait [COLOR="SeaGreen"]Respawn Time[/COLOR] seconds
        Unit - Create 1 (Unit-type of (Dying unit)) for (Owner of (Dying unit)) at [COLOR="Red"]CreepLoc[/COLOR][(Custom value of (Dying unit))] facing Default building facing degrees
        Unit - Set the custom value of (Last created unit) to (Custom value of (Dying unit))

I have marked variables with red and constants with green. You will only need to change these.

You will need the following variables:

TempGroup - Unit Group Variable
Integer - Integer Variable
CreepLoc - Point Array Variable
 

Inflicted

Currently inactive
Reaction score
63
surely for your trigger :Creep Setup: you would want it every second and not at initialisation? cos what if he creates new units?
 

OneBadPsycho

10100111001
Reaction score
93
surely for your trigger :Creep Setup: you would want it every second and not at initialisation? cos what if he creates new units?

Create new units where? If he use the palette in the editor they will automatically be counted in this.

If he create them using a trigger he just adds the following below the unit creation:
Code:
Set [COLOR="Red"]Integer[/COLOR] = ([COLOR="Red"]Integer[/COLOR] + 1)
Unit - Set the custom value of (Last created unit) to [COLOR="Red"]Integer[/COLOR]
Set [COLOR="Red"]CreepLoc[/COLOR][[COLOR="Red"]Integer[/COLOR]] = (Position of (Last created unit))
 

Inflicted

Currently inactive
Reaction score
63
well i dont know his map - but maybe he has a building and trains units or something, your trigger works off initialisation, so yeah i dont thing thatd work for training or hiring. but easily fixable i gues
 

Bogrim

y hello thar
Reaction score
154
Just a small note, there's no reason to use "Dying unit". Just use Triggering unit. The unit that activates the event will always be the triggering unit, and all the event responses that correspond to triggering unit are completely pointless.
 

OneBadPsycho

10100111001
Reaction score
93
Just a small note, there's no reason to use "Dying unit". Just use Triggering unit. The unit that activates the event will always be the triggering unit, and all the event responses that correspond to triggering unit are completely pointless.

It shouldn't matter much.



are both natives and if he uses dying unit, he wouldn't get confused later, even if Triggering Unit is faster.
 

Bogrim

y hello thar
Reaction score
154
Furthermore, you should save the integer of the unit type locally in that trigger, OneBadPsycho, or you'll still be at the risk of no unit being created at respawn. That would be adding
Trigger:
  • Custom script: local integer i = GetUnitTypeId(GetTriggerUnit())

as the first line in the trigger, create a unit-type variable named something like "Temp_Type", adding
Trigger:
  • Custom script: set udg_Temp_Type = i

after the wait and then create a unit-type of the variable instead.
 

OneBadPsycho

10100111001
Reaction score
93
Could you explain exactly why ? :eek:

This, for instance, works:

JASS:
globals
    real Respawn_Time = 30
    location array CreepLoc
endglobals

scope Respawn initializer Init

private function Conditions takes nothing returns boolean
    return GetOwningPlayer(GetDyingUnit()) == Player(9)
endfunction

private function Actions takes nothing returns nothing
    local unit re
    call TriggerSleepAction(Respawn_Time)
    set re = CreateUnitAtLoc(GetOwningPlayer(GetDyingUnit()), GetUnitTypeId(GetDyingUnit()), CreepLoc[GetUnitUserData(GetDyingUnit())], GetRandomReal(1, 360))
    call SetUnitUserData(re, GetUnitUserData(GetDyingUnit()))
    set re = null
endfunction

private function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    local integer lint = 0
    loop
        call TriggerRegisterPlayerUnitEvent(t, Player(lint), EVENT_PLAYER_UNIT_DEATH, null)
        set lint = lint + 1
        exitwhen lint == 11
    endloop    
    call TriggerAddCondition(t, Condition(function Conditions))
    call TriggerAddAction(t, function Actions)
    set t = null
endfunction

endscope


This is going off topic.
 

Bogrim

y hello thar
Reaction score
154
Could you explain exactly why ? :eek:
While triggerunit is a local variable that will persist through any wait period, it is still just a handle and if the unit itself disappears from the game (for any reason, such as decay, being the target of a Raise Dead-type spell or removed by a trigger) before the handle is used, the game cannot retrieve the necessary information. For this same reason, you saved the location variables in the map initialization rather than as an attached variable to the unit.
 

tooltiperror

Super Moderator
Reaction score
231
@OneBadPsycho - Of course, you could attach the data to a struct so you don't have to use the hideous TSA. And make it MUI. You also shouldn't be changing unit values, since it will ruin indexers. And you don't need any globals. You could also use a function called RespawnTime to get the time you need, and possibly add an argument to it so different units have different respawn times.

Uses Key Timers.

JASS:
 library Respawn initializer onInit uses KT
  private function RespawnTime takes nothing returns real
      return 60.00
  endfunction
  struct Data
     integer rawcode
     player owner
     real x
     real y
       private static method create takes unit u returns thistype
           local thistype this=thistype.allocate()
           set this.rawcode=GetUnitTypeId(u)
           set this.owner=GetOwningPlayer(u)
           set .x=GetUnitX(u)
           set .y=GetUnitY(u)
           return this
       endmethod
  endstruct
  private function callback takes nothing returns boolean
     local Data data=KT_GetData() // I forget how to inline this.
     call CreateUnit(data.owner,data.int,data.x,data.y,0)
     return true
  endfunction
  private function Action takes nothing returns nothing
      local Data data=Data.create(GetUnitTypeId(GetTrigerUnit()))
      call KT_Add(function callback,data,RespawnTime())
  endfunction
  private function onInit takes nothing returns nothing
      local trigger t=CreateTrigger()
      local integer int=BJ_MAX_PLAYERS+1
        loop
          set int=int-1
          call TriggerRegisterPlayerUnitEvent(t,Player(int),EVENT_PLAYER_UNIT_DEATH,null)
          exitwhen lint==0
        endloop    
      call TriggerAddAction(t,function Action)
      set t=null
  endfunction
 endlibrary


Untested, of course.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      • Ghan
        Administrator - Servers are fun

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top