CreateUnit

Parameters
idplayer

The owner of the unit.

unitidinteger

The rawcode of the unit.

xreal

The x-coordinate of the unit.

yreal

The y-coordinate of the unit.

facereal

Unit facing in degrees.

  • 0 = East
  • 90 = North
  • 180 = West
  • 270 = South
  • -90 = South (wraps around)
comment

Creates a unit of type unitid for player id, facing a certain direction at the provided coordinates. Returns handle to unit.

Example: Create a human footman for first player (red) at map coordinates -30, 0, facing north:

    // Jass
    call CreateUnit(Player(0), 'hfoo', -30, 0, 90)
    -- Lua
    CreateUnit(Player(0), FourCC("hfoo"), -30, 0, 90)
note

See: bj_UNIT_FACING constant for default facing direction of units in BJ scripts and GUI.

note

If you want to create a unit with a specific shadow you can use something along these lines. See also.

// Dummy but valid image path required.
local image i = CreateImage( "ReplaceableTextures\\Splats\\AuraRune9b.blp", 1, 1, 0, 0, 0, 0, 1, 1, 0, 3)
local unit u
// If the image creation failed, abort, as it can screw up the game.
if GetHandleId(i) == -1 then
    return
endif
call DestroyImage(i)
set u = CreateUnit(Player(0), 'hpea', 0, 0, 0)

// Destroy the units shadow, because it seems like you can't really work with it.
call DestroyImage(i)

// Create a new image. This will be the units new shadow.
call CreateImage( "ReplaceableTextures\\Splats\\AuraRune9b.blp", 128, 128, 0, 0, 0, 0, 0, 0, 0, 1)

// Now you can do stuff with the image that is u's shadow.
// Do note though that you cannot change the position of the image.
call SetImageRenderAlways(i, true)
call SetImageColor(i, 255, 0, 0, 255)
bug

(tested 1.21, 2.0.4.23556): When this is used in global scope, such as globals block in Jass, it will do nothing on first map launch, but crash the game on map restart.

globals
    unit u = CreateUnit(Player(0), 'hfoo', -30, 0, 90)
endglobals

Blizzard bug report and test map

patch

1.00

Source
common.j (raise an issue to discuss on Github or submit a PR)
return type
unit
Source code
native          CreateUnit              takes player id, integer unitid, real x, real y, real face returns unit