• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] TD spawn problem

Status
Not open for further replies.
I have a TD (4 player solo TD) and i converted the spawn triggers into JASS and i have a problem. Ive gone through the entire code for each player, but for somereason it spawns 2 extra creeps per round for red. Heres the code:
Red:
JASS:
function Trig_RedSpawn_Conditions takes nothing returns boolean
    if ( not ( udg_Defeat == false ) ) then
        return false
    endif
    return true
endfunction

function Trig_RedSpawn_Func004Func002001 takes nothing returns boolean
    return ( udg_Level_Number != 10 )
endfunction

function Trig_RedSpawn_Func004Func002002001 takes nothing returns boolean
    return ( udg_Level_Number != 20 )
endfunction

function Trig_RedSpawn_Func004Func002002002 takes nothing returns boolean
    return ( udg_Level_Number != 30 )
endfunction

function Trig_RedSpawn_Func004Func002002 takes nothing returns boolean
    return GetBooleanAnd( Trig_RedSpawn_Func004Func002002001(), Trig_RedSpawn_Func004Func002002002() ) 
    endfunction

function Trig_RedSpawn_Func004C takes nothing returns boolean
    if ( not GetBooleanAnd( Trig_RedSpawn_Func004Func002001(), Trig_RedSpawn_Func004Func002002() ) ) then
        return false
    endif
    return true
endfunction

function Trig_RedSpawn_Actions takes nothing returns nothing
    call CreateNUnitsAtLoc( udg_Monster_Amount, udg_Monster_Type, Player(11), GetRectCenter(gg_rct_Red_Spawn), bj_UNIT_FACING )
        call DisplayTextToForce( bj_FORCE_PLAYER[0], ( ( "Level " + I2S(udg_Level_Number) ) + ( " - " + ( GetUnitName(GetLastCreatedUnit()) + "s" ) ) ) )
    if ( Trig_RedSpawn_Func004C() ) then
        set bj_forLoopAIndex = 1
        set bj_forLoopAIndexEnd = 10
        loop
            call TriggerSleepAction( 1.00 )
            call CreateNUnitsAtLoc( udg_Monster_Amount, udg_Monster_Type, Player(11), GetRectCenter(gg_rct_Red_Spawn), bj_UNIT_FACING )
            set bj_forLoopAIndex = bj_forLoopAIndex + 1
            exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        endloop
    else
    endif
endfunction

//===========================================================================
function InitTrig_RedSpawn takes nothing returns nothing
    set gg_trg_RedSpawn = CreateTrigger(  )
    call TriggerRegisterTimerExpireEventBJ( gg_trg_RedSpawn, udg_Next_Level )
    call TriggerAddCondition( gg_trg_RedSpawn, Condition( function Trig_RedSpawn_Conditions ) )
    call TriggerAddAction( gg_trg_RedSpawn, function Trig_RedSpawn_Actions )
endfunction

Blue:
JASS:
function Trig_BlueSpawn_Conditions takes nothing returns boolean
    if ( not ( udg_Defeat == false ) ) then
        return false
    endif
    return true
endfunction

function Trig_BlueSpawn_Func004Func001001 takes nothing returns boolean
    return ( udg_Level_Number != 10 )
endfunction

function Trig_BlueSpawn_Func004Func001002001 takes nothing returns boolean
    return ( udg_Level_Number != 20 )
endfunction

function Trig_BlueSpawn_Func004Func001002002 takes nothing returns boolean
    return ( udg_Level_Number != 30 )
endfunction

function Trig_BlueSpawn_Func004Func001002 takes nothing returns boolean
    return GetBooleanAnd( Trig_BlueSpawn_Func004Func001002001(), Trig_BlueSpawn_Func004Func001002002() )
endfunction

function Trig_BlueSpawn_Func004C takes nothing returns boolean
    if ( not GetBooleanAnd( Trig_BlueSpawn_Func004Func001001(), Trig_BlueSpawn_Func004Func001002() ) ) then
        return false
    endif
    return true
endfunction

function Trig_BlueSpawn_Actions takes nothing returns nothing
    call CreateNUnitsAtLoc( udg_Monster_Amount, udg_Monster_Type, Player(11), GetRectCenter(gg_rct_Blue_Spawn), bj_UNIT_FACING )
    call DisplayTextToForce( bj_FORCE_PLAYER[1], ( ( "Level " + I2S(udg_Level_Number) ) + ( " - " + ( GetUnitName(GetLastCreatedUnit()) + "s" ) ) ) )
    if ( Trig_BlueSpawn_Func004C() ) then
        set bj_forLoopAIndex = 1
        set bj_forLoopAIndexEnd = 10
        loop
            call TriggerSleepAction( 1.00 )
            call CreateNUnitsAtLoc( udg_Monster_Amount, udg_Monster_Type, Player(11), GetRectCenter(gg_rct_Blue_Spawn), bj_UNIT_FACING )
            set bj_forLoopAIndex = bj_forLoopAIndex + 1
            exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        endloop
    else
    endif
endfunction

//===========================================================================
function InitTrig_BlueSpawn takes nothing returns nothing
    set gg_trg_BlueSpawn = CreateTrigger(  )
    call TriggerRegisterTimerExpireEventBJ( gg_trg_BlueSpawn, udg_Next_Level )
    call TriggerAddCondition( gg_trg_BlueSpawn, Condition( function Trig_BlueSpawn_Conditions ) )
    call TriggerAddAction( gg_trg_BlueSpawn, function Trig_BlueSpawn_Actions )
endfunction

Teal:
JASS:
function Trig_TealSpawn_Conditions takes nothing returns boolean
    if ( not ( udg_Defeat == false ) ) then
        return false
    endif
    return true
endfunction

function Trig_TealSpawn_Func004Func002001 takes nothing returns boolean
    return ( udg_Level_Number != 10 )
endfunction

function Trig_TealSpawn_Func004Func002002001 takes nothing returns boolean
    return ( udg_Level_Number != 20 )
endfunction

function Trig_TealSpawn_Func004Func002002002 takes nothing returns boolean
    return ( udg_Level_Number != 30 )
endfunction

function Trig_TealSpawn_Func004Func002002 takes nothing returns boolean
    return GetBooleanAnd( Trig_TealSpawn_Func004Func002002001(), Trig_TealSpawn_Func004Func002002002() )
endfunction

function Trig_TealSpawn_Func004C takes nothing returns boolean
    if ( not GetBooleanAnd( Trig_TealSpawn_Func004Func002001(), Trig_TealSpawn_Func004Func002002() ) ) then
        return false
    endif
    return true
endfunction

function Trig_TealSpawn_Actions takes nothing returns nothing
    call CreateNUnitsAtLoc( udg_Monster_Amount, udg_Monster_Type, Player(11), GetRectCenter(gg_rct_Teal_Spawn), bj_UNIT_FACING )
    call DisplayTextToForce( bj_FORCE_PLAYER[2], ( ( "Level " + I2S(udg_Level_Number) ) + ( " - " + ( GetUnitName(GetLastCreatedUnit()) + "s" ) ) ) )
    if ( Trig_TealSpawn_Func004C() ) then
        set bj_forLoopAIndex = 1
        set bj_forLoopAIndexEnd = 10
        loop
            exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
            call TriggerSleepAction( 1.00 )
            call CreateNUnitsAtLoc( udg_Monster_Amount, udg_Monster_Type, Player(11), GetRectCenter(gg_rct_Teal_Spawn), bj_UNIT_FACING )
            set bj_forLoopAIndex = bj_forLoopAIndex + 1
        endloop
    else
    endif
endfunction

//===========================================================================
function InitTrig_TealSpawn takes nothing returns nothing
    set gg_trg_TealSpawn = CreateTrigger(  )
    call TriggerRegisterTimerExpireEventBJ( gg_trg_TealSpawn, udg_Next_Level )
    call TriggerAddCondition( gg_trg_TealSpawn, Condition( function Trig_TealSpawn_Conditions ) )
    call TriggerAddAction( gg_trg_TealSpawn, function Trig_TealSpawn_Actions )
endfunction

Purple:
JASS:
function Trig_PurpleSpawn_Conditions takes nothing returns boolean
    if ( not ( udg_Defeat == false ) ) then
        return false
    endif
    return true
endfunction

function Trig_PurpleSpawn_Func004Func002001 takes nothing returns boolean
    return ( udg_Level_Number != 10 )
endfunction

function Trig_PurpleSpawn_Func004Func002002001 takes nothing returns boolean
    return ( udg_Level_Number != 20 )
endfunction

function Trig_PurpleSpawn_Func004Func002002002 takes nothing returns boolean
    return ( udg_Level_Number != 30 )
endfunction

function Trig_PurpleSpawn_Func004Func002002 takes nothing returns boolean
    return GetBooleanAnd( Trig_PurpleSpawn_Func004Func002002001(), Trig_PurpleSpawn_Func004Func002002002() )
endfunction

function Trig_PurpleSpawn_Func004C takes nothing returns boolean
    if ( not GetBooleanAnd( Trig_PurpleSpawn_Func004Func002001(), Trig_PurpleSpawn_Func004Func002002() ) ) then
        return false
    endif
    return true
endfunction

function Trig_PurpleSpawn_Actions takes nothing returns nothing
    call CreateNUnitsAtLoc( udg_Monster_Amount, udg_Monster_Type, Player(11), GetRectCenter(gg_rct_Purple_Spawn), bj_UNIT_FACING )
    call DisplayTextToForce( bj_FORCE_PLAYER[3], ( ( "Level " + I2S(udg_Level_Number) ) + ( " - " + ( GetUnitName(GetLastCreatedUnit()) + "s" ) ) ) )
    if ( Trig_PurpleSpawn_Func004C() ) then
        set bj_forLoopAIndex = 1
        set bj_forLoopAIndexEnd = 10
        loop
            exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
            call TriggerSleepAction( 1.00 )
            call CreateNUnitsAtLoc( udg_Monster_Amount, udg_Monster_Type, Player(11), GetRectCenter(gg_rct_Purple_Spawn), bj_UNIT_FACING )
            set bj_forLoopAIndex = bj_forLoopAIndex + 1
        endloop
    else
    endif
endfunction

//===========================================================================
function InitTrig_PurpleSpawn takes nothing returns nothing
    set gg_trg_PurpleSpawn = CreateTrigger(  )
    call TriggerRegisterTimerExpireEventBJ( gg_trg_PurpleSpawn, udg_Next_Level )
    call TriggerAddCondition( gg_trg_PurpleSpawn, Condition( function Trig_PurpleSpawn_Conditions ) )
    call TriggerAddAction( gg_trg_PurpleSpawn, function Trig_PurpleSpawn_Actions )
endfunction

Also if there are any leakes, or anyway the code could be compacted, improved please let me know.

And if your wondering i have the loop so i can spawn creeps at 1 second intervals, yet have less code and easier control over the conditions.
 
Level 11
Joined
Oct 13, 2005
Messages
233
I'd highly suggest keeping those things in GUI. GUI converted to JASS is quite ugly and yields little/no advantages unless you know JASS well enough. And at that point, it's usually better to start from scratch with JASS.

The problem isn't with converting the code to JASS, it's with your original GUI. The JASS you posted is quite hard to read since it was converted from GUI. I'd suggest JASSing it from scratch or keeping it as GUI.
 
Doesnt using the custom scripting require turning on the advanced triggers and all that hassle that goes along with it?

And also, I have a question about loops: i did the loop integer a from 0 to 20 but it only runs like 14 times i think, shouldn't that run 20 times?

Lol, I changed the codes so its 0-20, but at the start it runs 7 times then as the game progresses it runs more (each time the trigger runs, it seems to increase the ammount of time it loops).
 
Last edited:
Status
Not open for further replies.
Top