Snippet Create Dummy Function

PrisonLove

Hard Realist
Reaction score
78
Hey guys I just started taking a computer programming course and decided that I would try to make a little snippet that might make life easier for map makers.

I created a JASS snippet that will create a dummy unit so that you don't have to keep writing out all the lines of code that are required to make dummies in all your spells.

Well, here it is:

JASS:
function CreateDummy takes player owner, integer unitCode, real x, real y, real facing, real time, integer abilityCode, integer abilityLevel returns unit
    set bj_lastCreatedUnit = CreateUnit( owner, unitCode, x, y, facing )
    call UnitAddAbility( bj_lastCreatedUnit, abilityCode )
    call SetUnitAbilityLevel( bj_lastCreatedUnit, abilityCode, abilityLevel )
    call UnitApplyTimedLife( bj_lastCreatedUnit, 'BTLF', time )
    return bj_lastCreatedUnit
endfunction


I realize it takes a lot of parameters, but what it does is create a unit for a player at a location with a timed life and adds an ability to the created unit, as well as setting a level to that ability.

So it would be used like this:

JASS:
local unit dummy = CreateDummy(Player(0), 'oshm', 0, 0, 270.00, 60.00, 'ACfb', 1)


This call creates a Shaman for Player 1 (Red) at the center of the map that lasts for 60 seconds and has the firebolt ability.

I don't know if you guys would find this useful, but hopefully it could eliminate some redundancy in your codes. Just add this snippet to the map header and you're good to go.

The best part about this in my opinion is that there are no leaks to remove, as coordinate don't leak and the unit is killed after the designated time. Also, it can be used for summoning units as well, since it isn't limited to only creating a dummy.

If this is in the wrong section would someone please be kind enough to move it?
 

Azlier

Old World Ghost
Reaction score
461
I like recycled dummy units of one main type.

Why is this in the project section?
 

PrisonLove

Hard Realist
Reaction score
78
I didn't know where to put it, so if someone would be kind enough to move it that would be great.
 

RaiJin

New Member
Reaction score
40
this snippet feels like a BJ in my opinion and i don't think its really needed

but yes i know what you mean writing those 4 lines is a disaster for the lazy, but still i don't think this is very helpful there's other systems that could do an awesome job in these area's aswell
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
JASS:

library Dummy initializer Init

	globals
		private constant integer DUMMY_ID = 'h000'
		private unit Dummy
	endglobals
	
	public function Get takes player p returns unit
		call SetUnitOwner(Dummy,p)
		return Dummy
	endfunction
	
	private function Init takes nothing returns nothing
		set Dummy = CreateUnit(Player(15),DUMMY_ID,0.,0.,0.)
	endfunction
	
	//Note : Use SetUnitPosition as long as you want.
	//		 Remove the ability added to dummy after it does it's task.
	//		 It is used for instant type spells
	//		 Never use KillUnit or RemoveUnit on dummy.
endlibrary


Use a dummy for whole map. :p
 

kingkingyyk3

Visitor (Welcome to the Jungle, Baby!)
Reaction score
216
Yep, you are right. The dummy's all animation time must be 0.000. The ability added too. (0 casting time)
 

Jesus4Lyf

Good Idea™
Reaction score
397
JASS:
function CreateDummy takes player owner, integer unitCode, real x, real y, real facing, real time, integer abilityCode, integer abilityLevel returns unit
    local unit u = CreateUnit( owner, unitCode, x, y, facing )
    call UnitAddAbility( u, abilityCode )
    call SetUnitAbilityLevel( u, abilityCode, abilityLevel )
    call UnitApplyTimedLife( u, 'BTLF', time )
    return u // This leaks. References to temporary agents must be removed (excluding function parameters).
endfunction

-->
JASS:
function CreateDummy takes player owner, integer unitCode, real x, real y, real facing, real time, integer abilityCode, integer abilityLevel returns unit
    set bj_lastCreatedUnit = CreateUnit( owner, unitCode, x, y, facing )
    call UnitAddAbility( bj_lastCreatedUnit, abilityCode )
    call SetUnitAbilityLevel( bj_lastCreatedUnit, abilityCode, abilityLevel )
    call UnitApplyTimedLife( bj_lastCreatedUnit, 'BTLF', time )
    return bj_lastCreatedUnit // The variable will be overwritten next time, removing the old reference.
endfunction

Agent handle ids are not recycled until no references remain to the agent. Local variables leak references when the function terminates.
 

PrisonLove

Hard Realist
Reaction score
78
When the unit dies from the expiration timer though, won't there no longer be a reference? Therefore, there should be no leak. I'm just wondering, I'm not saying you're wrong.
 

Azlier

Old World Ghost
Reaction score
461
The [lJASS]local unit u[/lJASS] is never nulled. It's a reference leak, and the handle slot will never get recycled.

Globals for the win.
 

Viikuna

No Marlo no game.
Reaction score
265
Yea. Dynamicly creating dummies is just terrible waste when you can actually avoid it, since CreateUnit is so slow.

If this had efficient dummy caster stuff together with some dummy stack for recycling dummies for channeling spells, it would be cool. Then it could maybe have a function like this too, for cases where you actually have to create dummies dynamicly. ( If there is any )
 

PrisonLove

Hard Realist
Reaction score
78
Well, like I said, I didn't know how useful it would be. Apparently it's not useful at all. Oh well, can't win em all.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top