Warcraft 3 documentation

vJASS & Zinc Documentation
For the latest documentation about how it works vJASS and Zinc language layers for Warcraft III, please follow these links:
Jasshelper documentation - Zinc documentation - WC3 Optimizer documentation

[System] Creep Respawn

nel · 191

0 Members and 1 Guest are viewing this topic.

Rating

Average Score - 5 / 5

« Created: June 23, 2019, 07:35:38 AM by moyack »

[System] Creep Respawn
on: June 23, 2019, 06:53:51 AM
Categories: System, JASS, vJASS
Rating: 5
Warcraft III Spell resource
« Created: June 23, 2019, 07:39:31 AM by moyack »
« Last Edit: June 24, 2019, 01:50:24 PM by nel »

Related Topics or Resources



by

Creep Respawn

It used to re-spawn a creep.

Code: jass
  1. library CreepRespawn /* v1.0.0.2
  2. *************************************************************************************
  3. *
  4. *   An RPG Creep Respawn.
  5. *
  6. *************************************************************************************
  7. *
  8. *   */ needs /*
  9. *
  10. *       ___________________________________
  11. *
  12. *       Required:
  13. *
  14. *       */ Table                                    /*      hiveworkshop.com/threads/snippet-new-table.188084/
  15. *       */ TimerUtils                               /*      wc3c.net/showthread.php?t=101322
  16. *       */ Alloc                                    /*      github.com/nestharus/JASS/blob/master/jass/Systems/Alloc/Table/script.j
  17. *
  18. *       ___________________________________
  19. *
  20. *       Optional:
  21. *
  22. *       */ optional RegisterPlayerUnitEvent         /*      hiveworkshop.com/threads/snippet-registerevent-pack.250266/
  23. *       */ optional UnitDex                         /*      hiveworkshop.com/threads/system-unitdex-unit-indexer.248209/
  24. *
  25. ************************************************************************************
  26. *
  27. *   SETTINGS
  28. *
  29. */
  30.     globals
  31.         /*
  32.         *    Player
  33.         */
  34.         private constant   player PLAYER                 = Player(PLAYER_NEUTRAL_AGGRESSIVE)
  35.        
  36.         /*
  37.         *    Special effect for revived creep.
  38.         */
  39.         private constant   string REVIVE_EFFECT          = "Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl"
  40.  
  41.         /*
  42.         *    Revive duration
  43.         */
  44.         private constant     real CREEP_REGULAR_DURATION = 5
  45.         private constant     real CREEP_BOSS_DURATION    = 10
  46.        
  47.         /*
  48.         *   Boss Type
  49.         *
  50.         *   Note: You must set the Unit's classification at Object Editor
  51.         *         based on CREEP_TYPE_BOSS.
  52.         */
  53.         private constant unittype CREEP_TYPE_BOSS        = UNIT_TYPE_ANCIENT
  54.  
  55.         /*
  56.         *    Maximum number of creeps.
  57.         *
  58.         *   Note: You do not need to change this value unless you know what
  59.         *   are you doing.
  60.         */
  61.         private constant  integer CREEP_MAX_COUNT        = 0x2000
  62.     endglobals
  63. /*
  64. ***********************************************************************************/
  65.  
  66.     globals
  67.         private TableArray CreepTable
  68.         private integer Count = 0
  69.     endglobals
  70.  
  71.     private struct System extends array
  72.         implement Alloc
  73.  
  74.         private integer type
  75.         private unit unit
  76.         private integer key
  77.  
  78.         private static method onRevive takes nothing returns nothing
  79.             local timer Timer = GetExpiredTimer()
  80.             local thistype this = GetTimerData(Timer)
  81.  
  82.             local unit Creep = CreateUnit(PLAYER,                           /*
  83.             */     this.type,                                               /*
  84.             */     CreepTable[this.key].real[0],                            /*
  85.             */     CreepTable[this.key].real[1],                            /*
  86.             */     CreepTable[this.key].real[2]                             /*
  87.             */ )
  88.            
  89.             static if LIBRARY_UnitDex then
  90.                 local integer Index = GetUnitId(Creep)
  91.  
  92.                 /*
  93.                 *    Copy the old unit's information to new indexed unit.
  94.                 */
  95.                 set CreepTable[Index].real[0] = CreepTable[this.key].real[0]
  96.                 set CreepTable[Index].real[1] = CreepTable[this.key].real[1]
  97.                 set CreepTable[Index].real[2] = CreepTable[this.key].real[2]
  98.                 set CreepTable[Index].boolean[3] = true
  99.  
  100.                 /*
  101.                 *    Flush old unit.
  102.                 */
  103.                 call CreepTable[this.key].flush()
  104.             else
  105.                 /*
  106.                 *    Set the new unit's index based on dead unit's index
  107.                 */
  108.                 call SetUnitUserData(Creep, this.key)
  109.             endif
  110.  
  111.             /*
  112.             *    Revive Effect
  113.             */
  114.             call DestroyEffect(AddSpecialEffect(                            /*
  115.             */     REVIVE_EFFECT, GetUnitX(Creep), GetUnitY(Creep)          /*
  116.             */ ))
  117.            
  118.             /*
  119.             *    Remove corpse
  120.             */
  121.             if this.unit != null then
  122.                 call RemoveUnit(this.unit)
  123.                 set this.unit = null
  124.             endif
  125.            
  126.             /*
  127.             *    Remove Timer
  128.             */
  129.             call ReleaseTimer(Timer)
  130.  
  131.             /*
  132.             *    Remove memory leaks
  133.             */
  134.             set Creep = null
  135.             set Timer = null
  136.             set this.type = 0
  137.             set this.key = 0
  138.            
  139.             /*
  140.             *    Deindex
  141.             */
  142.             call this.deallocate()
  143.         endmethod
  144.        
  145.     static if LIBRARY_RegisterAnyPlayerUnitEvent then
  146.         private static method onDeath takes nothing returns nothing
  147.     else
  148.         private static method onDeath takes nothing returns boolean
  149.     endif
  150.             local thistype this
  151.             local real Duration = 0
  152.             local unit u = GetTriggerUnit()
  153.             local integer k = GetUnitUserData(u)
  154.  
  155.             /*
  156.             *    Check if this unit is registered on this system else it
  157.             *   won't respawn.
  158.             */
  159.             if CreepTable[k].boolean[3] then
  160.                 set this = thistype.allocate()
  161.  
  162.                 set this.unit = u
  163.                 set this.type = GetUnitTypeId(this.unit)
  164.                 set this.key = k
  165.  
  166.                 if IsUnitType(this.unit, CREEP_TYPE_BOSS) then
  167.                     set Duration = CREEP_BOSS_DURATION
  168.                 else
  169.                     set Duration = CREEP_REGULAR_DURATION
  170.                 endif
  171.  
  172.                 call TimerStart(NewTimerEx(this), Duration, false,          /*
  173.                 */     function thistype.onRevive                           /*
  174.                 */ )
  175.             debug else
  176.                 debug call BJDebugMsg(GetUnitName(u) + " >> false ")
  177.             endif
  178.  
  179.             set u = null
  180.  
  181.             static if not LIBRARY_RegisterAnyPlayerUnitEvent then
  182.                 return false
  183.             endif
  184.         endmethod
  185.  
  186.         private static method enumGroup takes nothing returns boolean
  187.             local unit Enum = GetFilterUnit()
  188.  
  189.             /*
  190.             *    Indexing
  191.             */
  192.             static if LIBRARY_UnitDex then
  193.                 set Count = GetUnitId(Enum)
  194.             else
  195.                 set Count = Count + 1
  196.                 call SetUnitUserData(Enum, Count)
  197.             endif
  198.  
  199.             /*
  200.             *    Store a data to CreepTable
  201.             */
  202.             set CreepTable[Count].real[0] = GetUnitX(Enum)
  203.             set CreepTable[Count].real[1] = GetUnitY(Enum)
  204.             set CreepTable[Count].real[2] = GetUnitFacing(Enum)
  205.             set CreepTable[Count].boolean[3] = true
  206.  
  207.             /*
  208.             *    Remove memory leak
  209.             */
  210.             set Enum = null
  211.             return false
  212.         endmethod
  213.  
  214.         private static method registerMode takes nothing returns nothing
  215.             local group Iterator = CreateGroup()
  216.  
  217.             /*
  218.             *    Enumerate all of Player Creep's units
  219.             */
  220.             call GroupEnumUnitsOfPlayer(Iterator, PLAYER, Filter(           /*
  221.             */     function thistype.enumGroup                              /*
  222.             */ ))
  223.  
  224.             /*
  225.             *    Remove memory leaks
  226.             */
  227.             call DestroyGroup(Iterator)
  228.             call DestroyTimer(GetExpiredTimer())
  229.             set Iterator = null
  230.         endmethod
  231.  
  232.         private static method onInit takes nothing returns nothing
  233.             /*
  234.             *    Init Death Event
  235.             */
  236.             static if LIBRARY_RegisterAnyPlayerUnitEvent then
  237.                 call RegisterPlayerUnitEvent(PLAYER,                        /*
  238.                 */     EVENT_PLAYER_UNIT_DEATH, function thistype.onDeath   /*
  239.                 */ )
  240.             else
  241.                 local trigger trg = CreateTrigger()
  242.  
  243.                 call TriggerRegisterPlayerUnitEvent(trg, PLAYER,            /*
  244.                 */     EVENT_PLAYER_UNIT_DEATH, null                        /*
  245.                 */ )
  246.                 call TriggerAddCondition(trg, Condition(                    /*
  247.                 */     function thistype.onDeath                            /*
  248.                 */ ))
  249.  
  250.                 set trg = null
  251.             endif
  252.  
  253.             /*
  254.             *    Init CreepTable
  255.             */
  256.             set CreepTable = TableArray[CREEP_MAX_COUNT]
  257.  
  258.             /*
  259.             *    Init Register Mode
  260.             */
  261.             call TimerStart(CreateTimer(), 0, false, function thistype.registerMode)
  262.         endmethod
  263.     endstruct
  264. endlibrary

How to install:
  • Copy this script and all required libraries and paste them to your map.
  • Done.

Future plans
  • All Unit Indexers must be compatible.
  • No required libraries.
  • Lua version.
« Last Edit: June 24, 2019, 01:50:24 PM by nel »



Re: [System] Creep Respawn
Reply #1 on: June 23, 2019, 07:55:26 AM

Very nice code. I love how it's well commented.

I took the freedom to set the download link, and to refer links to resources from this site so users can get them easily from there. I just need one image to make outstanding your submission, :D

Good job :)


Re: [System] Creep Respawn
Reply #2 on: June 23, 2019, 08:02:32 AM

Very nice code. I love how it's well commented.

I took the freedom to set the download link, and to refer links to resources from this site so users can get them easily from there. I just need one image to make outstanding your submission, :D

Good job :)

I tried to add a download link, but it gave me an error. Should I need to report that issue immediately?



Re: [System] Creep Respawn
Reply #3 on: June 23, 2019, 08:47:41 AM

I tried to add a download link, but it gave me an error. Should I need to report that issue immediately?
What kind of error, what message??

I'll check it out as soon as possible. BTW, wonderful screenshot
« Last Edit: June 23, 2019, 11:04:42 AM by moyack »



 

* Random Spells & Systems

Vivir aprendiendo.co - A place for learning stuff, in Spanish   Chaos Realm - The world of Game modders and wc3 addicts   Diplo, a gaming community   WC3JASS.com - The JASS Vault + vJASS and Zinc   Jetcraft - A Starcraft II mod   WormTastic Clan (wTc)