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

[Snippet] Creep Respawn No New Posts Warcraft III Spells and Systems

Started by
nel

0 Members and 1 Guest are viewing this topic.

Rating

Average Score - 5 / 5

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

[Snippet] Creep Respawn
on: June 23, 2019, 06:53:51 AM
Categories: System, vJASS
Rating: 5
Warcraft III Spell resource
« Created: June 23, 2019, 07:39:31 AM by moyack »
« Last Edit: February 22, 2021, 11:10:43 AM by nel »
This resource / topic is compatible for Warcraft 3 Reforged

Related Topics or Resources



by

Creep Respawn

Code: jass
  1. scope CreepRespawn /* v2.0.0.0
  2. *************************************************************************************
  3. *
  4. *    Efficient Creep Respawning System. It is used for RPG Maps.
  5. *
  6. *************************************************************************************
  7. *
  8. *    Required:
  9. *
  10. *       CTL                         https://github.com/nestharus/JASS/blob/master/jass/Systems/ConstantTimerLoop32/script.j
  11. *       NewTable                    https://www.hiveworkshop.com/threads/snippet-new-table.188084/
  12. *
  13. *    --------------------------
  14. *
  15. *    Optional:
  16. *
  17. *       RegisterPlayerUnitEvent     https://www.hiveworkshop.com/threads/snippet-registerevent-pack.250266/
  18. *
  19. ************************************************************************************/
  20.  
  21.     globals
  22.         // Owner
  23.         private constant player  CREEP_OWNER     = Player(PLAYER_NEUTRAL_AGGRESSIVE)
  24.  
  25.         // Duration
  26.         private constant integer REVIVE_DURATION = 10
  27.  
  28.         // Revive Effect
  29.         private constant string  REVIVE_EFFECT   = "Abilities\\Spells\\Human\\Resurrect\\ResurrectTarget.mdl"
  30.  
  31.         // Remove corpse to reduce fps drops.
  32.         private constant boolean NO_CORPSE       = true
  33.     endglobals
  34.  
  35.     private struct sys extends array
  36.         private static constant integer CREEP_MAX_COUNT = 0x2000
  37.         private static TableArray tbArray
  38.         private static integer CreepCount = 0
  39.  
  40.         private unit Creep
  41.         private real Duration
  42.  
  43.         // Declare local var before looping
  44.         implement CTL
  45.             local integer CreepIndex
  46.  
  47.         // Start looping
  48.         implement CTLExpire
  49.             // Check if Duration reached 0
  50.             if this.Duration <= 0 then
  51.                 // Get Creep Index
  52.                 set CreepIndex = GetUnitUserData(this.Creep)
  53.  
  54.                 // Spawn
  55.                 call SetUnitUserData(CreateUnit(CREEP_OWNER, GetUnitTypeId(this.Creep), tbArray[CreepIndex].real[0], tbArray[CreepIndex].real[1], tbArray[CreepIndex].real[2]), CreepIndex)
  56.                 call DestroyEffect(AddSpecialEffect(REVIVE_EFFECT, tbArray[CreepIndex].real[0], tbArray[CreepIndex].real[1]))
  57.  
  58.                 static if NO_CORPSE then
  59.                     call RemoveUnit(this.Creep)
  60.                 endif
  61.  
  62.                 // Recycle
  63.                 set this.Creep = null
  64.                 set this.Duration = 0
  65.  
  66.                 // Deallocate
  67.                 call destroy()
  68.             else
  69.                 set this.Duration = this.Duration - .031250000
  70.                 debug call BJDebugMsg("[Index: " + I2S(this) + "] [Duration: " + R2S(this.Duration) + "]")
  71.             endif
  72.         implement CTLEnd
  73.  
  74.         // Dying Event
  75.         static if LIBRARY_RegisterAnyPlayerUnitEvent then
  76.             private static method onDeath takes nothing returns nothing
  77.         else
  78.             private static method onDeath takes nothing returns boolean
  79.         endif
  80.             local thistype this
  81.             local unit u = GetTriggerUnit()
  82.             local integer Index = GetUnitUserData(u)
  83.  
  84.             // Check if dying unit is revivable.
  85.             if tbArray[Index].boolean[3] then
  86.                 set this = thistype.create()
  87.  
  88.                 set this.Duration = REVIVE_DURATION
  89.                 set this.Creep = u
  90.             debug else
  91.                 debug call BJDebugMsg("[" + GetUnitName(Creep) + "] is not revivable.")
  92.             endif
  93.  
  94.             static if not LIBRARY_RegisterAnyPlayerUnitEvent then
  95.                 return false
  96.             endif
  97.         endmethod
  98.  
  99.         // Registration
  100.         private static method onRegister takes nothing returns nothing
  101.             local unit Creep = GetFilterUnit()
  102.             local integer Index = 0
  103.  
  104.             // Register except unit with locust.
  105.             if GetUnitAbilityLevel(Creep, 'Aloc') == 0 then
  106.                 // Set Index
  107.                 set thistype.CreepCount = thistype.CreepCount + 1
  108.                 set Index = thistype.CreepCount
  109.                 call SetUnitUserData(Creep, Index)
  110.  
  111.                 // Save X, Y, and Facing values.
  112.                 set tbArray[Index].real[0] = GetUnitX(Creep)
  113.                 set tbArray[Index].real[1] = GetUnitY(Creep)
  114.                 set tbArray[Index].real[2] = GetUnitFacing(Creep)
  115.                 set tbArray[Index].boolean[3] = true
  116.  
  117.                 debug call BJDebugMsg("[" + I2S(Index) + "] [" + GetUnitName(Creep) + "] [" + R2S(tbArray[Index].real[0]) + "] [" + R2S(tbArray[Index].real[1]) + "] [" + R2S(tbArray[Index].real[2]) + "] is registered.")
  118.             debug else
  119.                 debug call BJDebugMsg("[" + GetUnitName(Creep) + "] has locust ability.")
  120.             endif
  121.  
  122.             set Creep = null
  123.         endmethod
  124.  
  125.         private static method registerMode takes nothing returns nothing
  126.             local group Iterator = CreateGroup()
  127.  
  128.             // Get all CREEP_OWNER units.
  129.             call GroupEnumUnitsOfPlayer(Iterator, CREEP_OWNER, Filter(function thistype.onRegister))
  130.  
  131.             // Remove memory leaks.
  132.             call DestroyGroup(Iterator)
  133.             call DestroyTimer(GetExpiredTimer())
  134.             set Iterator = null
  135.         endmethod
  136.  
  137.         // Init
  138.         private static method onInit takes nothing returns nothing
  139.             // Init onDeath Event
  140.             static if LIBRARY_RegisterAnyPlayerUnitEvent then
  141.                 call RegisterPlayerUnitEvent(CREEP_OWNER, EVENT_PLAYER_UNIT_DEATH, function thistype.onDeath)
  142.             else
  143.                 local trigger trg = CreateTrigger()
  144.  
  145.                 call TriggerRegisterPlayerUnitEvent(trg, CREEP_OWNER, EVENT_PLAYER_UNIT_DEATH, null )
  146.                 call TriggerAddCondition(trg, Condition(function thistype.onDeath))
  147.  
  148.                 set trg = null
  149.             endif
  150.  
  151.             // Init TableArray
  152.             set tbArray = TableArray[thistype.CREEP_MAX_COUNT]
  153.  
  154.             // Register
  155.             call TimerStart(CreateTimer(), 0, false, function thistype.registerMode)
  156.         endmethod
  157.     endstruct
  158. endscope

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

Changelog
v2.0.0.0
- Replaced TimerUtils to CTL for better performance.
- Replaced library to scope
- Removed UnitDex temporarily. I will add Unit Indexer soon.

v1.0.0.0
- Initial releases

Future plans
  • All Unit Indexers must be compatible.
  • Lua version.
« Last Edit: February 22, 2021, 11:10:43 AM 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

Started by PitzerMike

Replies: 0
Views: 1131
Codes & Snippets

Started by Purgeandfire

Replies: 0
Views: 1129
Codes & Snippets

Started by Bribe

Replies: 0
Views: 1448
Codes & Snippets

Started by moyack

Replies: 0
Views: 9369
Codes & Snippets

Started by Magtheridon96

Replies: 1
Views: 8200
Codes & Snippets
Vivir aprendiendo.co - A place for learning stuff, in Spanish   Chaos Realm - The world of Game modders and wc3 addicts   Diplo, a gaming community   Power of Corruption, an altered melee featuring Naga and Demon. Play it now!!!   WC3JASS.com - The JASS Vault + vJASS and Zinc   Jetcraft - A Starcraft II mod   WormTastic Clan (wTc)   Warcraft RESOURCES Reforged: Modelos, mapas, proyectos y mas...