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.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top