• 🏆 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!

[Solved] Viewing trigger randomly crashes WE

Status
Not open for further replies.
Level 11
Joined
Sep 14, 2009
Messages
284
I have a trigger that sometimes (about 50% of the times) when I simply click on the trigger to view the code, crashes WE. Its only this trigger, and I'm using Sharpcraft WE.

If anyone can look at the code and find why this is happening would be great. Now I have to remember to save the map before editing the code, or I risk losing work if I forget to save.

JASS:
//===========================================================================
function CombatWon_MoveItems takes nothing returns nothing
    call SetItemPosition(GetEnumItem(), GetRectCenterX(gg_rct_PartyManagerItemDump), GetRectCenterY(gg_rct_PartyManagerItemDump))
endfunction
function CombatWon takes nothing returns nothing
    local group g = null
    local integer i = 0
    local player p = Player(8)
    local real x = 0
    local real y = 0
    local unit u = null
   
    set inArena = false
    set inCombat = false
    call StartSound(gg_snd_Sound_CombatWon)
   
    // ----- Display experience and gold gained and add gold to player -----
    if GetLocalPlayer() == p then
        call ClearTextMessages()
    endif
    call DisplayTextToPlayer(p, 0, 0, "|cffFFCC00Combat Won|r!\n|cffFFFF00+ " + I2S(combatGoldGain) + " Gold|r!\n|cff5BADFF+ " + I2S(combatExpGain) + " Experience|r!")
    call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD) + combatGoldGain)
   
    // ----- Remove last item drop and create new eventual item drop -----
    set i = 0
    if GetRandomInt(1, 100) <= itemMaterialDropRate then
        set i = itemMaterialDropType
    else
        set x = I2R(GetRandomInt(0, 7))
        call DisplayTextToPlayer(Player(8), 0, 0, "Potion random number = " + R2S(x))
        if x == 0.0 then
            set i = 'phea' // Basic healing potion
        else
            if x == 1.0 then
                set i = 'pman' // Basic mana potion
            endif
        endif
    endif
    if i != 0 then
        if lastItemDrop != null then
            call RemoveItem(lastItemDrop)
        endif
        set lastItemDrop = CreateItem(i, PolarProjectionX(overworldX, 50, GetRandomReal(0, 360)), PolarProjectionY(overworldY, 50, GetRandomReal(0, 360)))
    endif
   
    // -----  -----
    /* if combatBossBattle then
        set combatBossBattle = false
        if CombatSpawnBossTrig != null then
            call DestroyTrigger(CombatSpawnBossTrig) DISABLE
            set CombatSpawnBossTrig = null
        endif
        if CombatBossBattleRemove == true then
            set CombatBossBattleRemove = false
            call RemoveUnit(CombatSpawnBoss)
        endif
        call StopMusic(false)
        call SetZoneMusic(ZoneCurrent)
    endif */
   
    // ----- Revive dead characters, move characters and add experience -----
    set i = 3
    set x = GetRectCenterX(gg_rct_EnterPartyManager)
    set y = GetRectCenterY(gg_rct_EnterPartyManager)
    loop
        exitwhen i < 0
        if i == 0 then
            set x = overworldX
            set y = overworldY
        endif
        if GetUnitState(partyMember[i], UNIT_STATE_LIFE) <= 0.405 then
            call ReviveHero(partyMember[i], x, y, false)
            call SetUnitState(partyMember[i], UNIT_STATE_LIFE, GetUnitState(partyMember[i], UNIT_STATE_MAX_LIFE) * 0.10)
            call SetUnitState(partyMember[i], UNIT_STATE_MANA, GetUnitState(partyMember[i], UNIT_STATE_MAX_MANA) * 0.10)
        endif
        call SetUnitPosition(partyMember[i], x, y)
        call AddHeroXP(partyMember[i], combatExpGain, true)
        call IssueImmediateOrder(partyMember[i], "stop")
        set i = i - 1
    endloop
    call SetUnitFacing(partyMember[0], overworldAngle)
   
    // ----- Reset camera bounds and destroy combat rect visibility -----
    call SetCameraBoundsExe(gg_rct_CameraBoundsOverworld)
    call PanCameraToTimed(overworldX, overworldY, 0)
    call DestroyFogModifier(combatRectVisibility)
   
    // ----- Enable party manager ability and set unit selection -----
    call SetPlayerAbilityAvailable(p, abilPartyManager, true)
    if GetLocalPlayer() == p then
        call ClearSelection()
        call SelectUnit(partyMember[0], true)
    endif
   
    // ----- Move all items in combatRect to party manager and remove all leftover units in combatRect -----
    call EnumItemsInRect(combatRect, null, function CombatWon_MoveItems)
    set g = CreateGroup()
    call GroupEnumUnitsInRect(g, combatRect, null)
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        call RemoveUnit(u)
        call GroupRemoveUnit(g, u)
    endloop
   
    // ----- Restart combatSpawnTimer -----
    call TimerStart(combatSpawnTimer, GetRandomReal(23, 27), false, null)
   
    // ----- Cleanup -----
    call DestroyGroup(g)
    set g = null
    set p = null
    set u = null
   
endfunction
//===========================================================================
function CombatTimer_Actions takes nothing returns nothing
    local boolean anyCharAlive = false
    local boolean anyEnemyAlive = false
    local integer i = 0
    local group g = CreateGroup()
    local player p = Player(8)
    local player pEnemy = Player(PLAYER_NEUTRAL_AGGRESSIVE)
    local player pOwner = null
    local unit u = null
   
    // ----- Check if any character or enemy is alive -----
    call GroupEnumUnitsInRect(g, combatRect, null)
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        if GetUnitState(u, UNIT_STATE_LIFE) > 0.405 and GetUnitAbilityLevel(u, abilDummyUnit) < 1 then
            set pOwner = GetOwningPlayer(u)
            if pOwner == p and IsUnitType(u, UNIT_TYPE_HERO) then
                set anyCharAlive = true
            else
                if pOwner == pEnemy then
                    set anyEnemyAlive = true
                endif
            endif
        endif
        call GroupRemoveUnit(g, u)
    endloop
   
    /*
        If all enemies are dead: run victory settings.
        Else, if all characters are dead: run defeat settings.
        Else, start combatTimer again.
    */
    if (anyCharAlive == false or anyEnemyAlive == false) and combatActive <= 0 then
        call TriggerSleepAction(0.5)
        if anyCharAlive then
            call CombatWon()
        else
            //call CombatLost()
        endif
    else
        call TimerStart(combatTimer, 1, false, null)
    endif
   
    // ----- Cleanup -----
    call DestroyGroup(g)
    set g = null
    set p = null
    set pEnemy = null
    set pOwner = null
   
endfunction
//===========================================================================
function InitTrig_CombatTimer takes nothing returns nothing
    set gg_trg_CombatTimer = CreateTrigger()
    call TriggerRegisterTimerExpireEvent(gg_trg_CombatTimer, combatTimer)
    call TriggerAddAction(gg_trg_CombatTimer, function CombatTimer_Actions)
endfunction
 
Status
Not open for further replies.
Top