• 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.

Jass Needed - Simple Unit Creation with Eyecandies

Status
Not open for further replies.
Level 30
Joined
Jan 31, 2010
Messages
3,552
First of all, thanks for watching at this thread. What I need is quite simple, a script that will follow the two lines listed down. I need it for my project map, which is about to be released. Credits, and reputation will be given, of course.

Yellow colored stuff should be things I can easily change. This goes on for two teams, and 3 creep types per team. Note that the "Catapult" waves will go every fourth wave, and need their own spawn interval.
1. Every 40 seconds, 4 Units are created at Point (Center of region).
2. Appearance - I want the units start at 100% transparency, and to fade to 0% over a short period of time (1 second is enough, I think).

Pretty much everything. Quite simple for someone familiar with Jass.
 
Script done using simple jass. Trigger is GUI friendly. Set 'Region', 'MaxValue' and 'UnitId' at Map Initialization. Requires Unit Indexer.

EDIT: Added variable SPAWN_INTERVAL for interval customization.
Don't forget about customizing player who gets the units. Right now it's Player(0) (aka Player 1 (Red)).

~Optimizted code.

Initialization:
  • init
    • Events
      • Map Initialization
    • Conditions
    • Actions
      • Set Region = Region 000 <gen>
      • Set Region2 = Region 001 <gen>
      • Custom script: call Register(Player(0), 'hfoo', 3, 1, GetRectCenterX(udg_Region), GetRectCenterY(udg_Region), GetRectCenterX(udg_Region2), GetRectCenterY(udg_Region2))
      • Custom script: call Register(Player(0), 'ebal', 1, 4, GetRectCenterX(udg_Region), GetRectCenterY(udg_Region), GetRectCenterX(udg_Region2), GetRectCenterY(udg_Region2))
      • Custom script: call Register(Player(1), 'ogru', 2, 1, GetRectCenterX(udg_Region2), GetRectCenterY(udg_Region2), GetRectCenterX(udg_Region), GetRectCenterY(udg_Region))
      • Custom script: call Register(Player(1), 'ocat', 1, 4, GetRectCenterX(udg_Region2), GetRectCenterY(udg_Region2), GetRectCenterX(udg_Region), GetRectCenterY(udg_Region))
JASS:
//*************************************************************************
//*
//* Globals required
//*
//*************************************************************************


    //* udg_Index                         Counts the amount of instances
    //* udg_Counter                       Counts instances
    //* udg_FadeGroup                     Group for fading units
    //* udg_Timer                         Global timer that runs whole script
    //* udg_fade[]                        Counts alpha for given unit

   //* For instances support:

      //* udg_Player[]
      //* udg_UnitId[]
      //* udg_Amount[]
      //* udg_Delay[]
      //* udg_CurWave[]
      //* udg_x1[]
      //* udg_y1[]
      //* udg_x2[]
      //* udg_y2[]


//*************************************************************************
//*
//* Code itself
//*
//*************************************************************************


//* The interval of OnExpire function (means how quickly unit's alpha changes)
constant function FadeInterval takes nothing returns real
    return 0.03125
endfunction

//* Constant fade duration.
constant function FadeTime takes nothing returns real
    return 2.
endfunction

//* Determinates inteval between unit creation
constant function SpawnInterval takes nothing returns real
    return 8.
endfunction

function Register takes player owner, integer id, integer amount, integer delay, real rect1x, real rect1y, real rect2x, real rect2y returns nothing
    set udg_Index = udg_Index + 1
    set udg_Player[udg_Index] = owner
    set udg_UnitId[udg_Index] = id
    set udg_Amount[udg_Index] = amount
    set udg_Delay[udg_Index] = delay
    set udg_CurWave[udg_Index] = 0
    set udg_x1[udg_Index] = rect1x
    set udg_y1[udg_Index] = rect1y
    set udg_x2[udg_Index] = rect2x
    set udg_y2[udg_Index] = rect2y
endfunction

function Callback takes nothing returns nothing
    local unit u = GetEnumUnit()
    local integer id = GetUnitUserData(u)
    
    if udg_fade[id] < 255 then
        set udg_fade[id] = udg_fade[id] + (255 / R2I(FadeTime() / FadeInterval()))
        call SetUnitVertexColor(u, 255, 255, 255, udg_fade[id])
    else
        call GroupRemoveUnit(udg_FadeGroup, u)
        set udg_Counter = udg_Counter - 1
        if udg_Counter == 0 then
            call PauseTimer(udg_Timer)
        endif
    endif

    set u = null
endfunction

function OnExpire takes nothing returns nothing
    call ForGroup(udg_FadeGroup, function Callback)
endfunction

function RunSpawn takes nothing returns boolean
    local integer i = udg_Index
    local integer j
    
    loop
        exitwhen i == 0
        set udg_CurWave[i] = udg_CurWave[i] + 1
        if udg_CurWave[i] == udg_Delay[i] then
            set udg_CurWave[i] = 0
            set j = udg_Amount[i]
            loop
                exitwhen j == 0
                set bj_lastCreatedUnit = CreateUnit(udg_Player[i], udg_UnitId[i], udg_x1[i], udg_y1[i], bj_UNIT_FACING)
                call IssuePointOrderById(bj_lastCreatedUnit, 851983, udg_x2[i], udg_y2[i])
                if udg_Counter == 0 then
                    call TimerStart(udg_Timer, FadeInterval(), true, function OnExpire)
                endif
                set udg_Counter = udg_Counter + 1
                set udg_fade[GetUnitUserData(bj_lastCreatedUnit)] = 0
                call GroupAddUnit(udg_FadeGroup, bj_lastCreatedUnit)
                set j = j - 1
            endloop
        endif
        set i = i - 1
    endloop
    return false
endfunction
        
function InitTrig_CallSpawn takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEvent(t, SpawnInterval(), true)
    call TriggerAddCondition(t, Condition(function RunSpawn))
    set udg_Index = 0
    set udg_Counter = 0
    set t = null
endfunction

~Test map attached.
 

Attachments

  • AdvancedSpawn.w3x
    19.3 KB · Views: 22
Last edited:
Level 20
Joined
Jul 6, 2009
Messages
1,885
Well, here's my system too. It's a bit more flexible than Spinnaker's.
Spinnaker, i'm not sure your system supports multiple unit types and spawn at particular wave.

To use my system, just use function Spawn(owning player,raw code of spawned units,integer amount,spawn location,location for target of attack of units,wave spawn (for example, 1 means on each wave, 4 on each fourth wave)). Do this for each unit type, you can see how it's done in test map.

In the test map, each wave 3 footmen will appear on one side and each second wave 2 riflemen on the other side.

To use, copy Unit Creation and T32 triggers.
 

Attachments

  • Asdf.w3x
    20.6 KB · Views: 37
Spinnaker, i'm not sure your system supports multiple unit types and spawn at particular wave.
System was freshhand Garfield :p I just written it without anything - with a little help of JC ofc ;S

Apheraz Lucent didn't say anything about multiple units, he just said: '4 Units'. And I can add multiple unit support in a sec.
What does 'Spawn at particular wave' mean?
 
Status
Not open for further replies.
Top