• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

SpawnSystem

Spawn System - GUI Friendly

Very simple and easy to use spawnsystem, spawns within the created rect (region in GUI)...
See PARAMETER EXPLANATION inside the code for more information


JASS:
/*
=====Spawn System v1.1
=====by: Mckill2009

HOW TO INSTALL:
- Make a new trigger and convert to custom text via EDIT >>> CONVERT CUSTOM TEXT
- Copy ALL that is written here and overwrite the existing texts in the custom text
- Copy the TimerUtils 2.0 by Vexorian

REQUIREMENTS:
- Jass New Gen Pack by Vexorian
- TimerUtils by Vexorian

HOW TO USE:
- Create a region(rect in Jass) in your map, this is the "r" parameter
- call SpawnSystem.create(p, unittypeid, duration, interval, sfx, r, maxcount, centerregion, life)

PARAMETER EXPLANATION:
- p (Player) = The Player where the spawned unit belong
- unittypeid (Integer) = The UnitType, this is an integer RAW CODE of a unit 
- duration (Real) = The duration of the spell
- interval (Real) = The interval of the creation of the spawned unit
- life (Real) = sets the life of created unit
- sfx (String) = Used for Special Effect, strings like "Abilities\\Spells\\Undead\\RaiseSkeletonWarrior\\RaiseSkeleton.mdl" is an example of such
- r (Rect) = Is the rect or region square on which your unit will spawn, example like gg_trg_Region_000
- maxcount (Integer) = the maximum units created
- centerregion (Boolean) = creates center fo the region or in random places
- trig (Trigger) = creates a condition for premature stop, calls TriggerEvaluate that returns boolean, set to null to disable condition
- x (Real) = picks a coordinate (r=rect should be null if this is used)
- y (Real) = picks a coordinate (r=rect should be null if this is used)

HOW TO GET THE RAW CODE:
- You can view the raw codes by pressing CTRL+D in the object editor
- Examples of raw codes are 'uskm', 'hpea', if it's a custom unit then 'h000', 'H000' and so on...

CREDITS: For their suggestions
- watermelon_1234
- Magtheridon96
*/

library SpawnSystem uses TimerUtils

globals
    //===CONFIGURABLES:    
    private constant integer           FIXED_MAX_COUNT = 500 //sets the max unit created
endglobals

struct SpawnSystem
    player p
    integer uType
    integer maxcount
    real duration
    real interval
    real life
    real xLoc
    real yLoc
    string sfx    
    rect r
    private boolean center
    private trigger trg
    
    static method onSpawnThem takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local thistype this = GetTimerData(t)
        local unit dummy
        if .duration > 0 and .maxcount > 0 and (TriggerEvaluate(.trg) or .trg==null) then
            set .maxcount = .maxcount - 1
            set .duration = .duration - .interval
            if .r==null then
                set dummy = CreateUnit(.p, .uType, .xLoc, .yLoc, 0) 
            else    
                if not .center then
                    set dummy = CreateUnit(.p, .uType, GetRandomReal(GetRectMinX(.r), GetRectMaxX(.r)), GetRandomReal(GetRectMinY(.r), GetRectMaxY(.r)), 0)
                else
                    set dummy = CreateUnit(.p, .uType, GetRectCenterX(.r), GetRectCenterY(.r), 0) 
                endif
            endif
            
            if not IsUnitType(dummy, UNIT_TYPE_FLYING) then
                call DestroyEffect(AddSpecialEffect(.sfx, GetUnitX(dummy), GetUnitY(dummy)))
            else
                call DestroyEffect(AddSpecialEffectTarget(.sfx, dummy,"origin"))
            endif
            call UnitApplyTimedLife(dummy, 'BTLF', .life)
        else
            call DestroyTrigger(.trg)
            call ReleaseTimer(t)
            call .destroy()
        endif
        set t = null
        set dummy = null
    endmethod
    
    static method create takes player p, integer unittypeid, real duration, real interval, real lifeduration, string sfx, rect r, integer maxcount, boolean centerregion, trigger trig, real x, real y returns thistype
        local thistype this = thistype.allocate()
        set .p = p
        set .uType = unittypeid
        set .duration = duration
        set .interval = interval
        set .sfx = sfx
        set .life = lifeduration
        set .r = r
        if maxcount > FIXED_MAX_COUNT then
            set .maxcount = FIXED_MAX_COUNT
        else
            set .maxcount = maxcount
        endif
        set .center = centerregion
        set .life = life        
        set .trg = trig
        set .xLoc = x
        set .yLoc = y
        call TimerStart(NewTimerEx(this), interval, true, function thistype.onSpawnThem)
        return this
    endmethod
endstruct

endlibrary



  • Demo
    • Events
      • Time - Elapsed game time is 1.00 seconds
    • Conditions
    • Actions
      • Custom script: local string s = "Abilities\\Spells\\Undead\\RaiseSkeletonWarrior\\RaiseSkeleton.mdl"
      • Custom script: call SpawnSystem.create(Player(0), 'uskm', 30, 1, 0, s, gg_rct_loc1, 10, false,null,0,0)
      • Custom script: call SpawnSystem.create(Player(0), 'hpea', 40, 2, 5, s, gg_rct_loc2, 20, true,null,0,0)
      • Custom script: call SpawnSystem.create(Player(1), 'uskm', 30, 1, 10, s, gg_rct_loc3, 10, false,null,0,0)
      • Custom script: call SpawnSystem.create(Player(0), 'hfoo', 10, 1, 0, s, gg_rct_loc4, 15, true,null,0,0)



JASS:
scope SStest initializer init

private function Alive takes nothing returns boolean
    return not IsUnitType(udg_u, UNIT_TYPE_DEAD)
endfunction

private function RandomNumbers takes nothing returns boolean
    local integer i = GetRandomInt(1,10)
    if i==3 then
        call BJDebugMsg("Spawning Stop coz integer is "+I2S(i))
        return false
    endif    
    return true
endfunction

private function init takes nothing returns nothing
    local string s = "Abilities\\Spells\\Undead\\RaiseSkeletonWarrior\\RaiseSkeleton.mdl"
    local trigger t = CreateTrigger()
    call TriggerAddCondition(t, function RandomNumbers)
    set udg_u = gg_unit_hpea_0002   
       
    //Spawning will stop if the integer is 3
    call SpawnSystem.create(Player(0), 'uskm', 100, 1, 0, s, gg_rct_loc1, 500, false, t,0,0)
    
    set t = CreateTrigger()
    call TriggerAddCondition(t, function Alive)
    //Spawning will stop if the peasant is killed
    call SpawnSystem.create(Player(0), 'hfoo', 50, 0.5, 0, s, gg_rct_loc2, 500, true, t,0,0)
    
    //Sfx for flying unit, null trigger to disable condition and life timer
    call SpawnSystem.create(Player(0), 'hgry', 75, 1.5, 1, s, null, 500, false, null, GetUnitX(udg_u), GetUnitY(udg_u))
    set t = null
endfunction

endscope



v1.1
- TimerUtils 2.0 updated
- Static life timer replaced by dynamic parameter
- Added boolean condition for premature spawn stop
- Added flyer sfx
- Added x & y coordinate
- LOC removed coz it lags also



- watermelon_1234
- Magtheridon96


Keywords:
system, spawn, dota, gui, jass, vjass, rpg, dark, aos, strife, defense
Contents

SpawnSystem (Map)

Reviews
14th Jan 2012 Bribe: if @not@ IsUnitType(dummy, UNIT_TYPE_FLYING) then call DestroyEffect(AddSpecialEffect(.sfx, GetUnitX(dummy), GetUnitY(dummy))) else @call...

Moderator

M

Moderator

14th Jan 2012
Bribe:
JASS:
            if @not@ IsUnitType(dummy, UNIT_TYPE_FLYING) then
                call DestroyEffect(AddSpecialEffect(.sfx, GetUnitX(dummy), GetUnitY(dummy)))
            else
                @call DestroyEffect(AddSpecialEffectTarget(.sfx, dummy,"origin"))@
            endif

The first "not" could be removed if you swap the second line (highlighted) up with the line before the "else".

Otherwise, what does this offer over other spawn systems? This is decent but I don't think much of it, I will vote it 2.5/5 and approve it.
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
Quick Review:

  • This system would be better if it allowed the spawning to be stopped prematurely or have a condition checking when it should stop spawning.
  • You really don't need to use LOC here.
  • Instead of passing a boolean life value, I think it would be better to pass a real time value so that users can easily specify an expiration timer for units only if time is greater than 0.
  • You might want to support a facing angle for the units when they get created.
  • JASS:
    if maxcount >= FIXED_MAX_COUNT then
    The equal sign makes it redundant.
 
Here's a quick review:

- You need to add a Jass API (To make it even more GUI-Friendly)
- You don't need the "life" boolean, you can go with a real for the time the unit will be alive. 0 could mean it will never die.
- Instead of NewTimer(), call NewTimerEx(this)
Vexorian updated TimerUtils.
In fact, instead of declaring the local timer variable and nulling it, you could simply do this:
call TimerStart(NewTimerEx(this), interval, true, function thistype.onSpawnThem)

You could give users the ability to pass coordinates (For advanced users)
All you'll need is a few extra API functions.

In fact, you could make the core of the system use coordinates and only use a wrapper for the locations.
 
@maddeem:

I know.. reading the documentation is really annoying and I hate doing it as well :p
You missed this:

JASS:
PARAMETER EXPLANATION:
- p (Player) = The Player where the spawned unit belong
- unittypeid (Integer) = The UnitType, this is an integer RAW CODE of a unit 
- duration (Real) = The duration of the spell
- interval (Real) = The interval of the creation of the spawned unit
- sfx (String) = Used for Special Effect, strings like "Abilities\\Spells\\Undead\\RaiseSkeletonWarrior\\RaiseSkeleton.mdl" is an example of such
- r (Rect) = Is the rect or region square on which your unit will spawn, example like gg_trg_Region_000
- maxcount (Integer) = the maximum units created
- centerregion (Boolean) = creates center fo the region or in random places
- life (Boolean) = set false to have life timed
 
Sorry for not putting the description in the 'details', maybe next time Ima do it...

@watermelon_1234
- Noted about the real & facing angle...
- I made the LOC coz it lags for the first spawn when I do this (when so many units are spawning)...
set dummy = CreateUnit(.p, uType, GetRandomReal(GetRectMinX(.r), GetRectMaxX(.r)), GetRandomReal(GetRectMinY(.r), GetRectMaxY(.r)), 0)
I don't wanna do a preload either...

@Mag
- I really dont know about the new TimerUtils, next Ima use it...thanks...
- Coordinates noted, but Ima make it extra instead of wrapping the location...

@btdonald
- it's explained inside the code...
- centerregion (Boolean) = creates center fo the region or in random places
- life (Boolean) = set false to have life timed
 
Bribe said:
1) The first "not" could be removed if you swap the second line (highlighted) up with the line before the "else".

2) Otherwise, what does this offer over other spawn systems? This is decent but I don't think much of it, I will vote it 2.5/5 and approve it.

Thanks for the approval;

1) Noted Ima do it in the next update...

2) Umm, nothing just very simple/easy to use unlike other spawn systems which
is really longgggg...and the creation parameter is merged in one line...
 
Top