Spawn creep wave with unit ability problem

Discussion in 'World Editor Help' started by KvickaN, Jan 31, 2019.

  1. KvickaN

    KvickaN TH.net Regular

    Ratings:
    +24 / 0 / -0
    Hi!

    The map is a TD where each induvidual player spawn its own wave by using an ability in the players "builder unit". I think there's some problem when many players uses his/her ability at the same time.

    The problem is that when playing the map online, spawning gets buggy, it's supposed to spawn 25 or 50 units (depending on level) but it seems like it's random every time. Sometimes 18, sometimes 28 etc. (It works great offline, spawning all 50 with no problem)

    At first, I thought it was because of it being the same ability, so I made 9 separate abilities so that each player has their own unique ability id. That did not solve the problem... I have also tried splitting the trigger into 9 of the same but each trigger only responding to the specific player that casts ability. This resulted in the exact same thing, same problem.

    Please help!

    This is the trigger:

    Code:
    Spawn Level
        Events
            Unit - A unit Finishes casting an ability
        Conditions
            (Ability being cast) Equal to GoSpawn[(Player number of (Owner of (Triggering unit)))]
        Actions
            Set Level[(Player number of (Owner of (Triggering unit)))] = (Level[(Player number of (Owner of (Triggering unit)))] + 1)
            Leaderboard - Change the label for (Owner of (Triggering unit)) in LEADERBOARD to ((Name of (Owner of (Triggering unit))) + ( |c00ffffff@lvl:|r |c00FFFF00 + (String(Level[(Player number of (Owner of (Triggering unit)))]))))
            Unit - Set Max Mana of (Random unit from (Units owned by (Owner of (Triggering unit)) of type |cFFFF0000Summoner|r)) to 0
            If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                If - Conditions
                    (Level[(Player number of (Owner of (Triggering unit)))] Equal to 10) or ((Level[(Player number of (Owner of (Triggering unit)))] Equal to 17) or (Level[(Player number of (Owner of (Triggering unit)))] Equal to 20))
                Then - Actions
                    Set Points[(Player number of (Owner of (Triggering unit)))] = (Center of TempLoc[(Player number of (Owner of (Triggering unit)))])
                    Unit - Create 1 MonsterType[Level[(Player number of (Owner of (Triggering unit)))]] for Player 12 (Brown) at Points[(Player number of (Owner of (Triggering unit)))] facing Default building facing degrees
                    Custom script:   call RemoveLocation(udg_Points[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))])
                    Set LastCUnit[(Player number of (Owner of (Triggering unit)))] = (Last created unit)
                    Set TempMovePoint1[(Player number of (Owner of (Triggering unit)))] = (Center of MovePoint1[(Player number of (Owner of (Triggering unit)))])
                    Unit - Order LastCUnit[(Player number of (Owner of (Triggering unit)))] to Move To TempMovePoint1[(Player number of (Owner of (Triggering unit)))]
                    Custom script:   call RemoveLocation(udg_TempMovePoint1[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))])
                    Game - Display to (All players) for 5.00 seconds the text: ((Spawning level: |c00FFFF00 + (String(Level[(Player number of (Owner of (Triggering unit)))]))) + (|r -  + ((Name of LastCUnit[(Player number of (Owner of (Triggering unit)))]) + (( for  + pc[(Player number of (Owner of (Triggering unit)))]) + ((Name of (Own
                    For each (Integer A) from 1 to 25, do (Actions)
                        Loop - Actions
                            If ((Number of units in (Units in PlayerArea[(Player number of (Owner of (Triggering unit)))] owned by Player 12 (Brown))) Greater than 4) then do (Wait until ((Number of units in (Units in PlayerArea[(Player number of (Owner of (Triggering unit)))] owned by Player 12 (Brown))) Less than 5), checking every 0.10 seconds) else do (Do nothing)
                            If (PlayerChances[(Player number of (Owner of (Triggering unit)))] Less than or equal to 0) then do (Skip remaining actions) else do (Wait 3.00 game-time seconds)
                            Set Points[(Player number of (Owner of (Triggering unit)))] = (Center of TempLoc[(Player number of (Owner of (Triggering unit)))])
                            Unit - Create 1 MonsterType[Level[(Player number of (Owner of (Triggering unit)))]] for Player 12 (Brown) at Points[(Player number of (Owner of (Triggering unit)))] facing Default building facing degrees
                            Custom script:   call RemoveLocation(udg_Points[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))])
                            Set LastCUnit[(Player number of (Owner of (Triggering unit)))] = (Last created unit)
                            Set TempMovePoint1[(Player number of (Owner of (Triggering unit)))] = (Center of MovePoint1[(Player number of (Owner of (Triggering unit)))])
                            Unit - Order LastCUnit[(Player number of (Owner of (Triggering unit)))] to Move To TempMovePoint1[(Player number of (Owner of (Triggering unit)))]
                            Custom script:   call RemoveLocation(udg_TempMovePoint1[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))])
                    Unit - Set Max Mana of (Random unit from (Units owned by (Owner of (Triggering unit)) of type |cFFFF0000Summoner|r)) to 10
                Else - Actions
                    Set Points[(Player number of (Owner of (Triggering unit)))] = (Center of TempLoc[(Player number of (Owner of (Triggering unit)))])
                    Unit - Create 1 MonsterType[Level[(Player number of (Owner of (Triggering unit)))]] for Player 12 (Brown) at Points[(Player number of (Owner of (Triggering unit)))] facing Default building facing degrees
                    Custom script:   call RemoveLocation(udg_Points[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))])
                    Set LastCUnit[(Player number of (Owner of (Triggering unit)))] = (Last created unit)
                    Set TempMovePoint1[(Player number of (Owner of (Triggering unit)))] = (Center of MovePoint1[(Player number of (Owner of (Triggering unit)))])
                    Unit - Order LastCUnit[(Player number of (Owner of (Triggering unit)))] to Move To TempMovePoint1[(Player number of (Owner of (Triggering unit)))]
                    Custom script:   call RemoveLocation(udg_TempMovePoint1[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))])
                    Game - Display to (All players) for 5.00 seconds the text: ((Spawning level: |c00FFFF00 + (String(Level[(Player number of (Owner of (Triggering unit)))]))) + (|r -  + ((Name of LastCUnit[(Player number of (Owner of (Triggering unit)))]) + (( for  + pc[(Player number of (Owner of (Triggering unit)))]) + ((Name of (Own
                    For each (Integer A) from 1 to 50, do (Actions)
                        Loop - Actions
                            If ((Number of units in (Units in PlayerArea[(Player number of (Owner of (Triggering unit)))] owned by Player 12 (Brown))) Greater than 7) then do (Wait until ((Number of units in (Units in PlayerArea[(Player number of (Owner of (Triggering unit)))] owned by Player 12 (Brown))) Less than 8), checking every 0.10 seconds) else do (Do nothing)
                            If (PlayerChances[(Player number of (Owner of (Triggering unit)))] Less than or equal to 0) then do (Skip remaining actions) else do (Wait 0.30 game-time seconds)
                            Set Points[(Player number of (Owner of (Triggering unit)))] = (Center of TempLoc[(Player number of (Owner of (Triggering unit)))])
                            Unit - Create 1 MonsterType[Level[(Player number of (Owner of (Triggering unit)))]] for Player 12 (Brown) at Points[(Player number of (Owner of (Triggering unit)))] facing Default building facing degrees
                            Custom script:   call RemoveLocation(udg_Points[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))])
                            Set LastCUnit[(Player number of (Owner of (Triggering unit)))] = (Last created unit)
                            Set TempMovePoint1[(Player number of (Owner of (Triggering unit)))] = (Center of MovePoint1[(Player number of (Owner of (Triggering unit)))])
                            Unit - Order LastCUnit[(Player number of (Owner of (Triggering unit)))] to Move To TempMovePoint1[(Player number of (Owner of (Triggering unit)))]
                            Custom script:   call RemoveLocation(udg_TempMovePoint1[GetConvertedPlayerId(GetOwningPlayer(GetTriggerUnit()))])
                    Unit - Set Max Mana of (Random unit from (Units owned by (Owner of (Triggering unit)) of type |cFFFF0000Summoner|r)) to 10
    
    
    Pathing 1 red
    Code:
    red 1
        Events
            Unit - A unit enters red1 <gen>
        Conditions
            (Owner of (Entering unit)) Equal to Player 12 (Brown)
        Actions
            Set RedMovePoints[2] = (Center of MovePoint2[1])
            Unit - Order (Entering unit) to Move To RedMovePoints[2]
            Custom script:   call RemoveLocation(udg_RedMovePoints[2])
    
    Pathing 2 red
    Code:
    red 2
        Events
            Unit - A unit enters red2 <gen>
        Conditions
            (Owner of (Entering unit)) Equal to Player 12 (Brown)
        Actions
            Set RedMovePoints[3] = (Center of MovePoint3[1])
            Unit - Order (Entering unit) to Move To RedMovePoints[3]
            Custom script:   call RemoveLocation(udg_RedMovePoints[3])
    
    Pathing 3 red
    Code:
    red 3
        Events
            Unit - A unit enters red3 <gen>
        Conditions
            (Owner of (Entering unit)) Equal to Player 12 (Brown)
        Actions
            Set RedMovePoints[4] = (Center of MovePoint4[1])
            Unit - Order (Entering unit) to Move To RedMovePoints[4]
            Custom script:   call RemoveLocation(udg_RedMovePoints[4])
    
    Pathing 4 red
    Code:
    red 4 to end
        Events
            Unit - A unit enters red4 <gen>
        Conditions
            (Owner of (Entering unit)) Equal to Player 12 (Brown)
        Actions
            Set RedMovePoints[5] = (Center of MovePoint5[1])
            Unit - Order (Entering unit) to Move To RedMovePoints[5]
            Custom script:   call RemoveLocation(udg_RedMovePoints[5])
    
    If you see anything obvious I would be grateful for some help!

    Edit: I think solving my problem involves Local Variables, will try to read up on this. Help still appreciated!

    Edit: Yes! Adding this worked:

    local integer bj_forLoopAIndex
    local integer bj_forLoopAIndexEnd
     
    Last edited: Feb 1, 2019
  2. AceHart

    AceHart Your Friendly Neighborhood Admin

    Ratings:
    +1,483 / 0 / -0
    > If you see anything obvious

    Yes, "wait until" for example. Which is such a killer as you noticed.
    Or "Player number of (Owner of (Triggering unit))" - because if I see that very expression 50 gazillion times rather than once setting a variable, I feel like strangling someone, usually the author of said trigger


    Either way though, if Player 12 having too many units is a problem, then handle it as a problem rather than a side-condition.

    Code:
    Spawn 1
        Events
            Time - Every 0.50 seconds of game time
        Conditions
            (Number of units in (Units in Region Player 1 <gen> owned by Player 12 (Brown))) Less than or equal to 5
        Actions
            Trigger - Turn off (This trigger)
            Set SpawnPlayer = Player 1 (Red)
            Trigger - Run Spawn Wave for player <gen> (ignoring conditions)
    
    As in, when player 1 uses the launch wave ability, turn this trigger on (it is off by default and there is one such trigger per player).
    I take it you can see what it will do?
     
  3. AceHart

    AceHart Your Friendly Neighborhood Admin

    Ratings:
    +1,483 / 0 / -0
    > I think solving my problem involves ...[stuffs]

    Yes, yes. I try to mostly stick to the ages old saying of "plan twice, trigger once" - passed the test of time and all that
     
    • Like Like x 1

Share This Page