• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Unit Spawn - Submission

Status
Not open for further replies.
JASS:
//Filters STRUCTURE and dead
function GroupCon takes nothing returns boolean
   return not(IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE))  and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0.4
endfunction

//Filters Non STRUCTURE and dead
function FilterUnits takes nothing returns boolean
   return IsUnitType(GetFilterUnit(), UNIT_TYPE_STRUCTURE)  and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0.4
endfunction
//Destroys the timers of the Buildings
function DisableTimer takes nothing returns nothing
   call PauseTimer(LoadTimerHandle(udg_Hash,GetHandleId(GetEnumUnit()),1))
   call DestroyTimer(LoadTimerHandle(udg_Hash,GetHandleId(GetEnumUnit()),1))
endfunction

function GroupAction takes nothing returns nothing
   call ExplodeUnitBJ( GetEnumUnit() )
endfunction

//Timer Action
function SpawnUnit takes nothing returns nothing
   local timer t =  GetExpiredTimer ()
   local unit u = LoadUnitHandle(udg_Hash, GetHandleId(t), 0)
   if GetUnitState(u, UNIT_STATE_LIFE) < 0.4 then
       call PauseTimer(t)
       call DestroyTimer(t)
       set u = null
       set t = null
       return
   endif
   if GetRandomInt(0,1)==0 then
       call IssuePointOrder( CreateUnit(GetOwningPlayer(u), 'hfoo', GetUnitX(u), GetUnitY(u), 270) , "Attack", 0,0)
   else
       call IssuePointOrder( CreateUnit(GetOwningPlayer(u), 'hrif', GetUnitX(u), GetUnitY(u), 270) , "Attack", 0,0)
   endif   
   set u = null
   set t = null
endfunction

//Are all Creeps Dead?
function Kill_Con takes nothing returns boolean
   set bj_wantDestroyGroup = true
   return CountUnitsInGroup(GetUnitsOfPlayerMatching(Player(PLAYER_NEUTRAL_AGGRESSIVE), Condition(function GroupCon))) == 0
endfunction

//If Kill_Con -> Stop Timers, Victory, Explode Armee
function Kill takes nothing returns nothing
   set bj_wantDestroyGroup = true
   call ForGroupBJ( GetUnitsInRectMatching(GetPlayableMapRect(), Condition (function FilterUnits)), function DisableTimer )
   set bj_wantDestroyGroup = true
   call ForGroupBJ( GetUnitsInRectMatching(GetPlayableMapRect(), Condition (function GroupCon)), function GroupAction )
   call DisplayTimedTextToPlayer(GetLocalPlayer(),0,0, 99999.00, "You Won!" )
endfunction

//===========================================================================
function InitTrig_UnitSpawn takes nothing returns nothing
   local trigger tr = CreateTrigger()
   local integer loopA = 0
   local integer loopB = 0
   local unit u
   local timer t
   local real  angel = -45
   set udg_Hash =    InitHashtable()
   //Spawn Creeps
   loop
       exitwhen loopA >19
       call CreateUnit(Player(PLAYER_NEUTRAL_AGGRESSIVE), ChooseRandomCreep(-1), 0, 0, GetRandomReal(0,360))
       set loopA = loopA + 1
   endloop
   //Spawn Baracks and Timers
   set loopA = 0
   loop
       exitwhen loopA >3
       set t = CreateTimer()
       set angel = angel + 90
       set u = CreateUnit(Player(loopA), 'hbar', 3000 * Cos(angel * bj_DEGTORAD), 3000 * Sin(angel * bj_DEGTORAD), 270)
       call SaveUnitHandle(udg_Hash, GetHandleId(t), 0, u)
       call SaveTimerHandle(udg_Hash, GetHandleId(u),1,t)
       call TimerStart(t, 2.5, true, function SpawnUnit)
       set loopB = 0
       loop
           exitwhen loopB > 3
           call SetPlayerAllianceStateAllyBJ( Player(loopA), Player(loopB), true )
           call SetPlayerAllianceStateAllyBJ( Player(loopB), Player(loopA), true )
           set loopB = loopB + 1
       endloop   
       set loopA = loopA + 1
   endloop
   set t = null
   //Regiester Creep Killing
   call TriggerRegisterPlayerUnitEvent( tr, Player(PLAYER_NEUTRAL_AGGRESSIVE), EVENT_PLAYER_UNIT_DEATH, null )
   call TriggerAddAction( tr, function Kill )
   call TriggerAddCondition( tr, Condition( function Kill_Con ) )
   set tr = null
endfunction
This is Mission - Unit Spawn all 4 parts.
Edit: Changed Init and Made Buildings knowing their timers instead of the Player
Edit: Fixed Route -> Square
 

Attachments

  • Jass Class 3 Unit Spawn.w3m
    16.1 KB · Views: 32
Last edited:
The distane is not exatly "3000". ;)

You only need one timer
I think it makes sense to use multiple timers for the buildings.

Attention

My fault, I did not state explicitly that players should become allies, but please do so. Changed: Changelog

===

I am curious why you bind the timer data to the player himself, whereas it's logicaly binded to the building. It should be binded to the building, I believe. : )

And I agree with Chaosy, that not all BJs are useful to use. Sometimes the native function can be used directly.

On a side note; nulling units and timers makes sense, too.

Some explanation would help.
Yes maybe. But is there some specific question you have?
 
I am curious why you bind the timer data to the player himself, whereas it's logicaly binded to the building. It should be binded to the building, I believe. : )
Makes it easier for this mission to destroy them later, but true it makes more sense to make a connection between unit timer.
Edit: Updated First Post: Code + Map
 
Last edited:
Others than tiny leaks and a bit performance suggestions it looks good.

Still some for further submissions:

JASS:
GetUnitState(u, UNIT_STATE_LIFE) < 0.4
There's a native GetWidgetLife, which is more perfomant for getting a unit's life, it's adviced to use it over GetUnitState with LIFE. (for mana GetUnitState is okay)

The red BJs make no sense here, please don't further use them in next missions, and use the natives instead, if it makes no logical difference.

In the Alliance loop, only one alliance action is needed, because the other player will come later in loop anyways, and then both will be allied towards each other.

The handles can be removed from hashtable when not needed anymore.

full
 
Level 7
Joined
Mar 10, 2013
Messages
366
Yes maybe. But is there some specific question you have?

His first submission file wasn't generic, didn't had any comments and it was very about which units it would spawn and the amount of units it would track.

Now it is generic, and the explanation is not much needed. I asked only because it was so specific to his needs it should be called a system.
 
Status
Not open for further replies.
Top