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

JASS how to break loop?

Status
Not open for further replies.
Level 15
Joined
Nov 30, 2007
Messages
1,202
Conditions not working!

JASS:
function Ability_Interact takes nothing returns boolean
    local integer idD = GetDestructableTypeId(GetSpellTargetDestructable())
    return GetSpellAbilityId() == 'ACfn' and (idD == 'LTe2' or idD == 'LTg1')
endfunction

function Gate_Interaction_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local destructable TargetedGate = GetSpellTargetDestructable()
    local real x = GetLocationX(GetRectCenter(gg_rct_Options_Spawn))
    local real y = GetLocationY(GetRectCenter(gg_rct_Options_Spawn))
    local integer PlayerNum = GetConvertedPlayerId(p)
    local integer GateArray
    local integer i = 0
    set udg_InteractionCurrentTarget_d[PlayerNum] = TargetedGate
    loop
        exitwhen i > udg_GateCount
        if (udg_Gate[i] == TargetedGate) then
            set GateArray = i
            set i = udg_GateCount + 1
            else
            set i = i + 1
        endif
    endloop

// Abilities: Open - 'A005', Close - 'A006', Lock 'Aslp', Unlock - 'A008', Knock - 'ACwe', Information - 'ACsf'

    set udg_InteractionCurrentTarget_i[PlayerNum] = GateArray 
    set udg_OptionsUnit[PlayerNum] = CreateUnit(p, 'hhou', x, y, 0.00 )
    call SelectUnitForPlayerSingle(udg_OptionsUnit[PlayerNum], p)
    call UnitAddAbilityBJ('ACsf', udg_OptionsUnit[PlayerNum])


    if (udg_GateStatus[GateArray] != 0) then // Status != Dead
    call UnitAddAbilityBJ('ACwe', udg_OptionsUnit[PlayerNum])


        if (udg_GateStatus[GateArray] == -2) then // Status = Closed and Locked
        call UnitAddAbilityBJ('ACwe', udg_OptionsUnit[PlayerNum]) 

            if (IsPlayerInForce(p, udg_GateControl_g[GateArray]) == true ) then //Player has control
            call UnitAddAbilityBJ('A005', udg_OptionsUnit[PlayerNum]) 
            call UnitAddAbilityBJ('A008', udg_OptionsUnit[PlayerNum]) 
            endif 
        endif

        if (udg_GateStatus[GateArray] == -1) then // Status = Closed and Unlocked
        call UnitAddAbilityBJ('A005', udg_OptionsUnit[PlayerNum]) 
            if (IsPlayerInForce(p, udg_GateControl_g[GateArray]) == true ) then 
            call UnitAddAbilityBJ('Aslp', udg_OptionsUnit[PlayerNum])
            endif 
        endif

        if (udg_GateStatus[GateArray] == 1) then // Status = Open and Locked
            if (IsPlayerInForce(p, udg_GateControl_g[GateArray]) == true ) then 
            call UnitAddAbilityBJ('A006', udg_OptionsUnit[PlayerNum]) 
            call UnitAddAbilityBJ('A008', udg_OptionsUnit[PlayerNum]) 
            endif 
        endif

        if (udg_GateStatus[GateArray] == 2) then // Status = Open and Unlocked
        call UnitAddAbilityBJ('A006', udg_OptionsUnit[PlayerNum]) 
            if (IsPlayerInForce(p, udg_GateControl_g[GateArray]) == true ) then  
            call UnitAddAbilityBJ('Aslp', udg_OptionsUnit[PlayerNum])
            endif 
        endif

    endif

    set p = null
    set TargetedGate = null

endfunction

//===========================================================================
function InitTrig_Gate_Interaction takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition(t, Condition(function Ability_Interact))
    call TriggerAddAction(t, function Gate_Interaction_Actions)
    set t = null
endfunction

JASS:
function CheckForOptionsUnit takes nothing returns boolean
return GetUnitTypeId(GetTriggerUnit()) == 'hhou'
endfunction

function GateSpell_Actions takes nothing returns nothing

    local player p = GetTriggerPlayer() // Will probably use it more when I add messages.
    local integer i = udg_InteraCurTarget_i[GetConvertedPlayerId(p)]
    local destructable Gate = udg_Gate[i]
    local destructable GatePathing = udg_GatePathing[i]
    local integer PlayerNum = GetConvertedPlayerId(GetTriggerPlayer())
    local real y = GetLocationY(GetDestructableLoc(Gate))
    local real x = GetLocationX(GetDestructableLoc(Gate))
    local integer z = 1

if (udg_GateStatus[i] != 0) then // GateStatus != Broken

    if (GetSpellAbilityId() == 'A005') then // Open Gate
    call SetDestructableAnimationBJ(Gate, "death alternate")
    call SetDestructableInvulnerableBJ(Gate, true)
    call KillDestructable(GatePathing)

//Replaces abilities from eveyr player that has it avalible.

    loop
        exitwhen z > 11
            if (udg_InteraCurTarget_d[z] == udg_InteraCurTarget_d[PlayerNum]) then
            call UnitRemoveAbilityBJ( 'A005', udg_InteraOptions_u[z])
            call UnitAddAbilityBJ( 'A006', udg_InteraOptions_u[z])
            endif
            set z = z + 1
    endloop

//Takes the GateStatus and changes it to matching opposite.

        if (udg_GateStatus[i] == -2) then
            set udg_GateStatus[i] = 1  
        else
            set udg_GateStatus[i] = 2  
        endif
    endif    



    if (GetSpellAbilityId() == 'A006') then // Close Gate

    call SetDestructableAnimationBJ(Gate, "stand")
    call SetDestructableInvulnerableBJ(Gate, false)
    call DestructableRestoreLife(GatePathing, 250, true )

    loop
        exitwhen z > 11
            if (udg_InteraCurTarget_d[z] == udg_InteraCurTarget_d[PlayerNum]) then
            call UnitRemoveAbilityBJ( 'A006', udg_InteraOptions_u[z])
            call UnitAddAbilityBJ( 'A005', udg_InteraOptions_u[z])
            endif
            set z = z + 1
    endloop
            
        if (udg_GateStatus[i] == 1) then
            set udg_GateStatus[i] = -2
        else
            set udg_GateStatus[i] = -1
        endif  
    endif


    if (GetSpellAbilityId() == 'Aslp') then // Lock Gate

    call PlaySoundAtPointBJ(gg_snd_Lever, 100, Location(x, y), 1500.00)

    if (udg_GateStatus[i] == -1 ) then // GateStatus = Closed and Unlocked
        set udg_GateStatus[i] = -2
    else 
        set udg_GateStatus[i] = 1
    endif

    loop
        exitwhen z > 11
            if (udg_InteraCurTarget_d[z] == udg_InteraCurTarget_d[PlayerNum]) then
            call UnitRemoveAbilityBJ( 'Aslp', udg_InteraOptions_u[z])
            call UnitAddAbilityBJ( 'A008', udg_InteraOptions_u[z])
            endif
            set z = z + 1
    endloop
    endif


    if (GetSpellAbilityId() == 'A008') then // Unlock Gate

    call PlaySoundAtPointBJ(gg_snd_Lever, 100, Location(x, y), 1500.00)

    if (udg_GateStatus[i] == -2) then // GateStatus = Closed and Unlocked
        set udg_GateStatus[i] = -1
    else 
        set udg_GateStatus[i] = 2
    endif

    loop
        exitwhen z > 11
            if (udg_InteraCurTarget_d[z] == udg_InteraCurTarget_d[PlayerNum]) then
            call UnitRemoveAbilityBJ( 'A008', udg_InteraOptions_u[z])
            call UnitAddAbilityBJ( 'Aslp', udg_InteraOptions_u[z])
            endif
            set z = z + 1
        endloop
    endif


    if (GetSpellAbilityId() == 'ACwe') then // Knock On Gate
    if ((udg_GateOwner[i] != Player(11)) and (udg_GateOwner[i] == p)) then
    call PingMinimapLocForForceEx( GetForceOfPlayer(udg_GateOwner[i]), Location(x, y), 4.00, bj_MINIMAPPINGSTYLE_SIMPLE, 100, 100, 100)
    call DisplayTextToForce(GetForceOfPlayer(udg_GateOwner[i]), "Alert: Someone is knocking on your door...")
    endif
    call PlaySoundAtPointBJ(gg_snd_DoorKnock, 100, Location(x, y), 1500.00)
    call TriggerSleepAction(0.25)
    call PlaySoundAtPointBJ(gg_snd_DoorKnock, 100, Location(x, y), 1500.00)
    call TriggerSleepAction(0.25)
    call PlaySoundAtPointBJ(gg_snd_DoorKnock, 100, Location(x, y), 1500.00)
    call TriggerSleepAction(0.25)
    endif
endif

    set p = null
    set Gate = null
    set GatePathing = null
    
endfunction

//===========================================================================
function InitTrig_Gate_Spells takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition(t, Condition( function CheckForOptionsUnit))
    call TriggerAddAction(t, function GateSpell_Actions)
    set t = null
endfunction
 
Last edited:
Level 29
Joined
Oct 24, 2012
Messages
6,543
if all three abilities need to be true change or to and sry forgot to add tht note if only one of the abilities need to be true keep them or

i see what u mean i misread the one thing here copy this one

JASS:
//===============================
// THIS PART IS NOT WORKING, THE TRIGGER NEVER RUNS? ;(
//===============================

function Ability_Interact takes nothing returns boolean
    local integer idD = GetDestructableTypeId(GetSpellTargetDestructable())
    if GetSpellAbilityId() == 'ACfn' and ( idD == 'LTe2' or idD == 'LTg1' ) then
        return true
    else
        return false
    endif
endfunction

//===============================

function Gate_Interaction_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local destructable Gate = GetSpellTargetDestructable()
    local real x = GetRectCenterX(GetRectCenterX(gg_rct_Options_Spawn))
    local real y = GetRectCenterY(GetRectCenterY(gg_rct_Options_Spawn))
    local integer PlayerNum = GetPlayerId(p)
    local integer GateArray
    local integer i = 0 // not sure what u changed it to 
    set udg_InteractionCurrentTarget_d[PlayerNum] = Gate
    loop
        exitwhen i > udg_GateCount
        if (udg_Gate[i] == GetSpellTargetDestructable()) then
            set GateArray = i
            set i = udg_GateCount + 1
            else
            set i = i + 1
        endif
    endloop
    call DisplayTextToForce( GetPlayersAll(), "HELLO!?" )
    set udg_OptionsUnit[PlayerNum] = CreateUnit( p, 'hhou', x, y, , 0.00 )
    call SelectUnitForPlayerSingle(udg_OptionsUnit[PlayerNum], p)
    call UnitAddAbility( udg_OptionsUnit[PlayerNum], 'ACsf' )
    

endfunction

//===========================================================================
function InitTrig_Gate_Interaction takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition(t, Condition(function Ability_Interact))
    call TriggerAddAction(t, function Gate_Interaction_Actions)
    set t = null
endfunction
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
also i just noticed the local integer GateArray is not doing anything

local variables basically wipe themselves from memory after the trigger is finished running

i also missed this

at the end of ur trigger do
not sure if u have to set destructibles to null

set p = null

JASS:
//===============================
// THIS PART IS NOT WORKING, THE TRIGGER NEVER RUNS? ;(
//===============================

function Ability_Interact takes nothing returns boolean
    local integer idD = GetDestructableTypeId(GetSpellTargetDestructable())
    if GetSpellAbilityId() == 'ACfn' and ( idD == 'LTe2' or idD == 'LTg1' ) then
        return true
    else
        return false
    endif
endfunction

//===============================

function Gate_Interaction_Actions takes nothing returns nothing
    local player p = GetTriggerPlayer()
    local destructable Gate = GetSpellTargetDestructable()
    local real x = GetRectCenterX(GetRectCenterX(gg_rct_Options_Spawn))
    local real y = GetRectCenterY(GetRectCenterY(gg_rct_Options_Spawn))
    local integer PlayerNum = GetPlayerId(p)
    local integer GateArray
    local integer i = 0 // not sure what u changed it to 
    set udg_InteractionCurrentTarget_d[PlayerNum] = Gate
    loop
        exitwhen i > udg_GateCount
        if (udg_Gate[i] == GetSpellTargetDestructable()) then
            set GateArray = i
            set i = udg_GateCount + 1
            else
            set i = i + 1
        endif
    endloop
    call DisplayTextToForce( GetPlayersAll(), "HELLO!?" )
    set udg_OptionsUnit[PlayerNum] = CreateUnit( p, 'hhou', x, y, , 0.00 )
    call SelectUnitForPlayerSingle(udg_OptionsUnit[PlayerNum], p)
    call UnitAddAbility( udg_OptionsUnit[PlayerNum], 'ACsf' )
    set p = null
endfunction

//===========================================================================
function InitTrig_Gate_Interaction takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_SPELL_CAST)
    call TriggerAddCondition(t, Condition(function Ability_Interact))
    call TriggerAddAction(t, function Gate_Interaction_Actions)
    set t = null
endfunction
 
Last edited:
Level 37
Joined
Mar 6, 2006
Messages
9,240
See what I did here?
JASS:
function Ability_Interact takes nothing returns boolean
    local integer idD = GetDestructableTypeId(GetSpellTargetDestructable())
    return GetSpellAbilityId() == 'ACfn' and ( idD == 'LTe2' or idD == 'LTg1' )
endfunction

What is this?
JASS:
local real x = GetRectCenterX(GetRectCenterX(gg_rct_Options_Spawn))
local real y = GetRectCenterY(GetRectCenterY(gg_rct_Options_Spawn))
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
See what I did here?
JASS:
function Ability_Interact takes nothing returns boolean
    local integer idD = GetDestructableTypeId(GetSpellTargetDestructable())
    return GetSpellAbilityId() == 'ACfn' and ( idD == 'LTe2' or idD == 'LTg1' )
endfunction

What is this?
JASS:
local real x = GetRectCenterX(GetRectCenterX(gg_rct_Options_Spawn))
local real y = GetRectCenterY(GetRectCenterY(gg_rct_Options_Spawn))

So that the point doesnt leak? :S
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
This line isnt working: set udg_OptionsUnit[PlayerNum] = CreateUnit( p, 'hhou', x, y, , 0.00 )

Not when I change it to this either:
set udg_OptionsUnit[PlayerNum] = CreateUnit( p, 'hhou', Location(x, y), 0.00 )

I want to make a while loop running every 0.5 seconds updating this as long as the LastCreatedUnit is selected or perhaps its wiser to separate the cleanup from this trigger...
 
Level 15
Joined
Nov 30, 2007
Messages
1,202
I want to make a while loop that updates as long as the CreatedUnit is the only selected unit of the triggering player.

JASS:
loop
    exitwhen (CurrentSelectionCondition??)
     
 if () then
add ability X
else remove ability X
endif
 if () then 
add ability y
else remove ability y
endif
... etc... 
    call TriggerSleepAction( 0.20 )
endloop

end trigger

and when its no longer selected everything is flushed.

There will be 11 players in my map and this 11 possible interactions running at the same time, is this feasable or should I create a seperate trigger for every interaction trigger?

Gate interaction is but one.
 
Last edited:
Level 15
Joined
Nov 30, 2007
Messages
1,202
Register deselection event for a trigger instead of using a loop.

Problem would be that I dont know how much objects you can interact with, and if I could change the options in the same trigger perhaps it would be easier to make?

Is it really that bad with 11 loops running every 0.2 seconds (maximum) Well that and other triggers that use stuff like that ;


I was thinking that the deselectiong event would be another trigger that changes the CurrentSelectionUnit[PlayerNum]

and then a condition in that loop would recognize that the selection is no longer the same.

Hmm perhaps this is just a brainfart. And not relevant.

It's basically finnished.



Something is messed up with Gate Spells (second one)... The abilities for one are not replaced properly. Gonna relocate most of those conditions...

Edit, found the issue, I ussed two different variables for the Options unit.

Edit 2, Okey I'm finnished any feedback on the functionality of it is greatly valued.
 
Last edited:
Level 15
Joined
Nov 30, 2007
Messages
1,202
i meant u should update it on here lol ur first post is still the old version locals are always destroyed just limit it down to the lowest amount of locals u need

Okay, Changed that. Last things I would like to add is a cooldown to added ability and fix the sound not playing if you spam the trigger. (Lock sound) And perhaps that the unit goes near the gate when interacting with it. And a while loop hmm..
 
Last edited:
Status
Not open for further replies.
Top