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

creat a unit at a point

Status
Not open for further replies.
Level 7
Joined
Aug 19, 2009
Messages
278
How to creat a unit at a point with given x and y coordinates?

The function is

JASS:
CreateNUnitsAtLoc()

its function is

JASS:
function CreateNUnitsAtLoc takes integer count, integer unitId, player whichPlayer, location loc, real face returns group
    call GroupClear(bj_lastCreatedGroup)
    loop
        set count = count - 1
        exitwhen count < 0
        call CreateUnitAtLocSaveLast(whichPlayer, unitId, loc, face)
        call GroupAddUnit(bj_lastCreatedGroup, bj_lastCreatedUnit)
    endloop
    return bj_lastCreatedGroup
endfunction

I just need to create a unit at a given k and y coordinate. I don't want to use location as they leak. Any other way to do it?
 
Level 7
Joined
Aug 19, 2009
Messages
278
Now i am having another problem

how to save the unit created by

JASS:
call CreateUnit( Player(0), 'n000', 100.00, 250.00, 90.00)

as the last created unit?

JASS:
set udg_dummy = bj_lastCreatedUnit
doesn't work
 
Now i am having another problem

how to save the unit created by

JASS:
call CreateUnit( Player(0), 'n000', 100.00, 250.00, 90.00)

as the last created unit?

JASS:
set udg_dummy = bj_lastCreatedUnit
doesn't work

JASS:
native CreateUnit takes player id, integer unitid, real x, real y, real face returns unit
CreateUnit //is simple native, let's compare it with function

function CreateUnitAtLocSaveLast takes player id, integer unitid, location loc, real face returns unit
    if (unitid == 'ugol') then
        set bj_lastCreatedUnit = CreateBlightedGoldmine(id, GetLocationX(loc), GetLocationY(loc), face)
    else
        set bj_lastCreatedUnit = CreateUnitAtLoc(id, unitid, loc, face)
    endif

    return bj_lastCreatedUnit
endfunction

/*
This function will create unit and return it as bj_lastCreatedUnit.
GUI work like this, it will link new things to old ones, that's why you need to remove them (cleaning leaks) well more or less.

Just check how GUI create unit function look like:
*/

function CreateNUnitsAtLoc takes integer count, integer unitId, player whichPlayer, location loc, real face returns group
    call GroupClear(bj_lastCreatedGroup)
    loop
        set count = count - 1
        exitwhen count < 0
        call CreateUnitAtLocSaveLast(whichPlayer, unitId, loc, face)
        call GroupAddUnit(bj_lastCreatedGroup, bj_lastCreatedUnit)
    endloop
    return bj_lastCreatedGroup
endfunction

/*
Finally you can link native and use it like this:
*/
globals
    unit Global_Jass_Unit
endglobals

function Example takes nothing returns nothing
    local unit Local_Jass_Unit = CreateUnit( Player(0), 'n000', 100.00, 250.00, 90.00)
    set udg_Global_GUI_Unit    = CreateUnit( Player(0), 'n000', 100.00, 250.00, 90.00)
    set Global_Jass_Unit       = CreateUnit( Player(0), 'n000', 100.00, 250.00, 90.00)
    set bj_lastCreatedGroup    = CreateUnit( Player(0), 'n000', 100.00, 250.00, 90.00)
endfunction
 
Status
Not open for further replies.
Top