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

[JASS] SetUnitState problem

Status
Not open for further replies.
Level 2
Joined
Aug 30, 2007
Messages
11
Hello everybody, I'm new to Jass (I'll admit that upfront), and I've run into a bit of a problem when coding my TD. I'm looking for a way to modify max health of some spawned units, and figured that I could use SetUnitState to do it, but I'm getting the error "Expected a name" when I attempt to enable the trigger containing the code. Here's the code... see anything wrong?

JASS:
function Trig_Unit_Create_Func003002 takes nothing returns nothing
    call SetUnitLifeBJ( GetEnumUnit(), udg_MonsterLife )
    call SetUnitState( GetEnumUnit(), UNIT_STATE_MAX_LIFE, udg_MonsterHealth)
endfunction

function Trig_Unit_Create_Func005002 takes nothing returns nothing
    call SetUnitLifeBJ( GetEnumUnit(), udg_MonsterLife )
    call SetUnitState( GetEnumUnit(), UNIT_STATE_MAX_LIFE, udg_MonsterHealth)
endfunction

function Trig_Unit_Create_Func007002 takes nothing returns nothing
    call SetUnitLifeBJ( GetEnumUnit(), udg_MonsterLife )
    call SetUnitState( GetEnumUnit(), UNIT_STATE_MAX_LIFE, udg_MonsterHealth)
endfunction

function Trig_Unit_Create_Func009002 takes nothing returns nothing
    call SetUnitLifeBJ( GetEnumUnit(), udg_MonsterLife )
    call SetUnitState( GetEnumUnit(), UNIT_STATE_MAX_LIFE, udg_MonsterHealth)
endfunction

function Trig_Unit_Create_Func011002 takes nothing returns nothing
    call SetUnitLifeBJ( GetEnumUnit(), udg_MonsterLife )
    call SetUnitState( GetEnumUnit(), UNIT_STATE_MAX_LIFE, udg_MonsterHealth)
endfunction

function Trig_Unit_Create_Func013002 takes nothing returns nothing
    call SetUnitLifeBJ( GetEnumUnit(), udg_MonsterLife )
    call SetUnitState( GetEnumUnit(), UNIT_STATE_MAX_LIFE, udg_MonsterHealth)
endfunction

//-------------------------------------------------------------

function Trig_Unit_Create_Actions takes nothing returns nothing



    call CreateNUnitsAtLoc( 10, udg_MonsterType, Player(7), GetRectCenter(gg_rct_Spawn_1), bj_UNIT_FACING )
    call ForGroupBJ( GetUnitsInRectOfPlayer(gg_rct_Spawn_1, Player(7)), function Trig_Unit_Create_Func003002 )

    call CreateNUnitsAtLoc( 10, udg_MonsterType, Player(8), GetRectCenter(gg_rct_Spawn_2), bj_UNIT_FACING )
    call ForGroupBJ( GetUnitsInRectOfPlayer(gg_rct_Spawn_2, Player(8)), function Trig_Unit_Create_Func005002 )

    call CreateNUnitsAtLoc( 10, udg_MonsterType, Player(9), GetRectCenter(gg_rct_Spawn_3), bj_UNIT_FACING )
    call ForGroupBJ( GetUnitsInRectOfPlayer(gg_rct_Spawn_3, Player(9)), function Trig_Unit_Create_Func007002 )

    call CreateNUnitsAtLoc( 10, udg_MonsterType, Player(10), GetRectCenter(gg_rct_Spawn_3), bj_UNIT_FACING )
    call ForGroupBJ( GetUnitsInRectOfPlayer(gg_rct_Spawn_4, Player(10)), function Trig_Unit_Create_Func009002 )

    call CreateNUnitsAtLoc( 10, udg_MonsterType, Player(11), GetRectCenter(gg_rct_Spawn_3), bj_UNIT_FACING )
    call ForGroupBJ( GetUnitsInRectOfPlayer(gg_rct_Spawn_5, Player(11)), function Trig_Unit_Create_Func011002 )

    call CreateNUnitsAtLoc( 10, udg_MonsterType, Player(12), GetRectCenter(gg_rct_Spawn_3), bj_UNIT_FACING )
    call ForGroupBJ( GetUnitsInRectOfPlayer(gg_rct_Spawn_6, Player(12)), function Trig_Unit_Create_Func013002 )

endfunction

//===========================================================================
function InitTrig_Unit_Create takes nothing returns nothing
    set gg_trg_Unit_Create = CreateTrigger(  )
    call TriggerRegisterTimerExpireEventBJ( gg_trg_Unit_Create, udg_WaveTimer )
    call TriggerAddAction( gg_trg_Unit_Create, function Trig_Unit_Create_Actions )
endfunction
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
That looks like almost pure converted GUI. (Everything except for having used Player() instead of ConvertedPlayer()) -.-

Anyhow, there's a lot of things that could be improved there;

-Don't use BJs, use GetWidgetLife/SetWidgetLife (or just GetUnitState/SetUnitState if you so desire)

-Use coordinates, locations leak

-CreateNUnitsAtLoc is ebol, use CreateUnit

-You can't set a max state using SetUnitState. try this instead.

Cleaned up code:

JASS:
function Unit_Create takes nothing returns nothing
    local integer i = 0
    local unit u
    loop
        exitwhen i > 9
        set u = CreateUnit(Player(7),udg_MonsterType,GetRectCenterX(gg_rct_Spawn_1),GetRectCenterY(gg_rct_Spawn_1),270)
        call SetWidgetLife(u,udg_MonsterLife)
        //put in the SetUnitMaxState thing here
        set u = CreateUnit(Player(8),udg_MonsterType,GetRectCenterX(gg_rct_Spawn_2),GetRectCenterY(gg_rct_Spawn_2),270)
        call SetWidgetLife(u,udg_MonsterLife)
        //put in the SetUnitMaxState thing here
        set u = CreateUnit(Player(9),udg_MonsterType,GetRectCenterX(gg_rct_Spawn_3),GetRectCenterY(gg_rct_Spawn_3),270)
        call SetWidgetLife(u,udg_MonsterLife)
        //put in the SetUnitMaxState thing here
        set u = CreateUnit(Player(10),udg_MonsterType,GetRectCenterX(gg_rct_Spawn_3),GetRectCenterY(gg_rct_Spawn_3),270)
        call SetWidgetLife(u,udg_MonsterLife)
        //put in the SetUnitMaxState thing here
        set u = CreateUnit(Player(11),udg_MonsterType,GetRectCenterX(gg_rct_Spawn_3),GetRectCenterY(gg_rct_Spawn_3),270)
        call SetWidgetLife(u,udg_MonsterLife)
        //put in the SetUnitMaxState thing here
        set u = CreateUnit(Player(12),udg_MonsterType,GetRectCenterX(gg_rct_Spawn_3),GetRectCenterY(gg_rct_Spawn_3),270)
        call SetWidgetLife(u,udg_MonsterLife)
        //put in the SetUnitMaxState thing here
        set i = i + 1
    endloop
    set u = null
endfunction

function InitTrig_Unit_Create takes nothing returns nothing
    set gg_trg_Unit_Create = CreateTrigger()
    call TriggerRegisterTimerExpireEvent( gg_trg_Unit_Create, udg_WaveTimer )
    call TriggerAddAction( gg_trg_Unit_Create, function Unit_Create )
endfunction
 
Level 2
Joined
Aug 30, 2007
Messages
11
Hehe, it probably looks mostly like pure converted GUI since it IS mostly pure converted GUI. Got to start somewhere, eh? Anyway, thanks for your help!
 
Status
Not open for further replies.
Top