• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

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