HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

CreateUnit won't create my unit

10-14-2009, 03:45 PM#1
aualin
Okay so my CreateUnit function has gone against me.
Collapse JASS:
scope Beastmaster initializer onInit
    
    function actionOfDoom takes nothing returns nothing
        //KillUnit( GetTriggerUnit( ) )
        BJDebugMsg("Creating unit, attempt 1")
        BJDebugMsg(GetUnitName(CreateUnit(GetTriggerPlayer(), 'hpea', 0, 0, 0)))
        BJDebugMsg("Attempt 2")
        BJDebugMsg(GetUnitName(CreateUnitAtLoc( GetTriggerPlayer(), 'hpea', GetRectCenter(gg_rct_Spawn), 0 )))
        BJDebugMsg("Attempt 3")
        CreateNUnitsAtLoc( 1, 'hpea', GetTriggerPlayer(), GetRectCenter(gg_rct_Spawn), 0 )
    endfunction
    
    function onInit takes nothing returns nothing
        trigger daTriggerOfDoom = CreateTrigger( )
        TriggerRegisterEnterRectSimple( daTriggerOfDoom, gg_rct_Beastmaster )
        TriggerAddAction( daTriggerOfDoom, function actionOfDoom )
    endfunction
endscope

Just prints out (null)
Any idea why the hell wc3 is against me? :(
10-14-2009, 04:01 PM#2
chobibo
Try CreateUnit(player, unitId, x, y, facing) instead of CreateNUnitsAtLoc().
10-14-2009, 04:17 PM#3
aualin
Quote:
Originally Posted by chobibo
Try CreateUnit(player, unitId, x, y, facing) instead of CreateNUnitsAtLoc().
That's what
Collapse JASS:
BJDebugMsg(GetUnitName(CreateUnit(GetTriggerPlayer(), 'hpea', 0, 0, 0)))
is for
Just didn't bother checking what's in the unit group, cause it's probaly pretty empty anyway...
10-14-2009, 04:24 PM#4
chobibo
Oh sorry I didn't understand.

EDIT: So the problem is you can't create units right?
10-14-2009, 04:52 PM#5
aualin
Quote:
Originally Posted by chobibo
Oh sorry I didn't understand.

EDIT: So the problem is you can't create units right?
Yea, just returns null...
10-14-2009, 04:59 PM#6
Anitarf
That's because you are using GetTriggerPlayer in a trigger with a non-player event, so it returns null instead of a player. Trying to create a unit for a null player fails and so the CreateUnit function returns null as well.
10-14-2009, 04:59 PM#7
Rising_Dusk
GetTriggerPlayer() is null in that event response. You should use GetOwningPlayer(GetTriggerUnit()) instead.
10-14-2009, 05:15 PM#8
aualin
Quote:
Originally Posted by Anitarf
That's because you are using GetTriggerPlayer in a trigger with a non-player event, so it returns null instead of a player. Trying to create a unit for a null player fails and so the CreateUnit function returns null as well.
Quote:
Originally Posted by Rising_Dusk
GetTriggerPlayer() is null in that event response. You should use GetOwningPlayer(GetTriggerUnit()) instead.
This is one of the duuh... moments. Thanks a lot for the help :)
Worked like a charm.