Detecting Rally Place

MasterOfRa

New Member
Reaction score
10
I'm trying to detect a rally place so i can do something when it happens. Either that or I need another way to detect right/left clicks

JASS:
library Terrain initializer Init
globals
    private constant integer BLACK_TERRAIN = 'Ydrt'
    private constant integer WHITE_TERRAIN = 'Ydtr'
    private constant integer ICE_TERRAIN   = 'Yrtl'
    
    private constant integer BLACK_HERO    = 'Hblk'
    private constant integer WHITE_HERO    = 'Hwht'
    private constant integer ICE_HERO      = 'Hice'
    private integer terrainAoe             = 1
    private integer terrainShape           = 0 // 0 is circle
endglobals
private function Periodic takes nothing returns nothing
    local integer count = 0 
    local integer tType = 0
    local real x
    local real y
    loop
        if Escapers[count] != null then
            if isAlive[count] then
                set x = GetUnitX( Escapers[count])
                set y = GetUnitY( Escapers[count])
                set tType = GetTerrainType(x,y)
                if     tType == WHITE_TERRAIN then
                    call KillUnit(Escapers[count])
                    set isAlive[count] = false
                    call DestroyEffect(AddSpecialEffect(FID_frostnova,x,y))
                elseif tType == ICE_TERRAIN then
                    call DestroyEffect(AddSpecialEffect(FID_skate,x,y))
                endif
            endif
        endif
        set count = count + 1
        exitwhen count >= MAX_PLAYERS
    endloop
endfunction

//===========================================================================
private function ActionsRally takes nothing returns nothing
    local unit caster = GetSpellAbilityUnit()
    local location targetLoc = GetSpellTargetLoc()
    local real x = GetLocationX(targetLoc)
    local real y = GetLocationY(targetLoc)
    if GetUnitTypeId(caster) == BLACK_HERO then
        call SetTerrainType(0,0, BLACK_TERRAIN, -1, terrainAoe, terrainShape )
    elseif GetUnitTypeId(caster) == WHITE_HERO then
        call SetTerrainType(0,0, WHITE_TERRAIN, -1, terrainAoe, terrainShape )
    elseif GetUnitTypeId(caster) == ICE_HERO then
        call SetTerrainType(0,0, ICE_TERRAIN, -1, terrainAoe, terrainShape )
    endif
    call RemoveLocation(targetLoc)
    set targetLoc = null
endfunction

//===========================================================================
private function ConditionsRally takes nothing returns boolean
    call BJDebugMsg("Spell "+I2S(GetSpellAbilityId())+" cast")
    call BJDebugMsg("Spell Tested For"+I2S(AID_RALLY))
    return GetSpellAbilityId() == AID_RALLY
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition( trig, Condition( function ConditionsRally ) )
    call TriggerAddAction( trig, function ActionsRally )
    set trig = null
    call SetTerrainType(0,0, BLACK_TERRAIN, -1, 8, 0 )
    call TimerStart(NewTimer(),TT_PERIOD,true,function Periodic)
endfunction
endlibrary
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
Modified from my Rally Sound Replacement:

JASS:
function RallyCheckUnit takes nothing returns nothing
    if (GetUnitCurrentOrder(GetEnumUnit()) != 851980) then // 851980 = String2OrderIdBJ("smart")
    // If, an instant later, the unit's order is not still 'smart', it had its rally point set by the order:
        // Do actions here also
    endif
    call GroupRemoveUnit(udg_RallyCheckGroup, GetEnumUnit())
endfunction

function RallyCheckGroup takes nothing returns nothing
    call ForGroup(udg_RallyCheckGroup, function RallyCheckUnit)
    call DestroyTimer(GetExpiredTimer())
endfunction

function RallyConditionAction takes nothing returns boolean
    if (GetUnitAbilityLevel(GetTriggerUnit(), 'ARal') > 0) then
        if (GetIssuedOrderId() == 851971) then // 851971 = String2OrderIdBJ("setrally")
            // Do actions here
        elseif (GetIssuedOrderId() == 851980) then // 851980 = String2OrderIdBJ("smart")
            // If, an instant later, the unit's order is still 'smart', it did not have its rally point set by the order, so we test:
            call GroupAddUnit(udg_RallyCheckGroup, GetTriggerUnit())
            call TimerStart(CreateTimer(), 0.00, false, function RallyCheckGroup)
        endif
    endif
    return false
endfunction

function InitTrig_RallyTrigger takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER)
    call TriggerAddCondition(t, Condition(function RallyConditionAction))
endfunction


It's the simplest, most straightforward way I know to find out if a unit had its rally-point changed by either the rally ability or a right-click. The ForGroup() could probably be changed to a FirstOfGroup loop, though.
 

Weep

Godspeed to the sound of the pounding
Reaction score
400
That will return the current location of a unit's rally-point. I think MasterOfRa wants to detect the event when a unit has its rally-point set.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
evenement : an unit receive a point/target order
condition : issued order == "setrally" (left click)

But if the order is "smart" then it's a right click, assuming you don't give the "rally" ability to not-structrures-unit, and structures can't move, you would only have to check if the triggering unit is a structure.
 

Troll-Brain

You can change this now in User CP.
Reaction score
85
Good point.
I dunno if attack is done or if it's the rally when you do a right click.

Few months ago i planned to determine which "smart" an unit receive ("move","setrally", and so one) but they are such many cases possibles, and so many tests must be done in order to know the priorities.
 

MasterOfRa

New Member
Reaction score
10
thanks, it works now

JASS:
library Terrain initializer Init uses Constants
globals
    private constant integer BLACK_TERRAIN = 'Ydrt'
    private constant integer WHITE_TERRAIN = 'Ydtr'
    private constant integer ICE_TERRAIN   = 'Yrtl'
    
    private unit BLACK_HERO    = null
    private unit WHITE_HERO    = null
    private unit ICE_HERO      = null
    
    private integer terrainAoe             = 1
    private integer terrainShape           = 0 // 0 is circle
endglobals
private function Periodic takes nothing returns nothing
    local integer count = 0 
    local integer tType = 0
    local real x
    local real y
    loop
        if Escapers[count] != null then
            if isAlive[count] then
                set x = GetUnitX( Escapers[count])
                set y = GetUnitY( Escapers[count])
                set tType = GetTerrainType(x,y)
                if     tType == WHITE_TERRAIN then
                    call KillUnit(Escapers[count])
                    set isAlive[count] = false
                    call DestroyEffect(AddSpecialEffect(FID_frostnova,x,y))
                elseif tType == ICE_TERRAIN then
                    call DestroyEffect(AddSpecialEffect(FID_skate,x,y))
                endif
            endif
        endif
        set count = count + 1
        exitwhen count >= MAX_PLAYERS
    endloop
endfunction

//===========================================================================
private function ActionsRally takes nothing returns nothing
    local unit caster = GetOrderedUnit()
    local real x = GetOrderPointX()
    local real y = GetOrderPointY()
    if caster     == BLACK_HERO then
        call SetTerrainType(x,y, BLACK_TERRAIN, -1, terrainAoe, terrainShape )
    elseif caster == WHITE_HERO then
        call SetTerrainType(x,y, WHITE_TERRAIN, -1, terrainAoe, terrainShape )
    elseif caster == ICE_HERO then
        call SetTerrainType(x,y, ICE_TERRAIN  , -1, terrainAoe, terrainShape )
    endif
endfunction

//===========================================================================
private function ConditionsRally takes nothing returns boolean
    return GetUnitAbilityLevel(GetOrderedUnit(),AID_TERRAINCHANGER) != 0
endfunction

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

public function Reset takes nothing returns nothing
    call SetTerrainType(0,0, WHITE_TERRAIN, -1, 47, 1 )
    call SetTerrainType(0,0, BLACK_TERRAIN, -1, 8, 0 )
    set BLACK_HERO = CreateUnit(Player(Builder),UID_BLACK_TERRAIN,-47.75*128,-47.75*128,0)
    set WHITE_HERO = CreateUnit(Player(Builder),UID_WHITE_TERRAIN,-47.75*128,-47.75*128,0)
    set ICE_HERO   = CreateUnit(Player(Builder),UID_ICE_TERRAIN  ,-47.75*128,-47.75*128,0)
endfunction

//===========================================================================
private function ConditionsOptions takes nothing returns boolean
    local unit caster = GetSpellAbilityUnit()
    local integer spell  = GetSpellAbilityId()
    if spell == AID_TERRAIN_SHRINK then
        set terrainAoe = terrainAoe - 1
        if terrainAoe < 1 then
            set terrainAoe = 1
            call SimError(Player(Builder),"Terrain Aoe cannot go below 1!")
        else
            call DisplayTimedTextToPlayer( Player(Builder), 0.52, -1.00, 2.00, "Terrain Aoe: "+I2S(terrainAoe) )
        endif
    elseif spell == AID_TERRAIN_EXPAND then
        set terrainAoe = terrainAoe + 1
        if terrainAoe > 10 then
            set terrainAoe = 10
            call SimError(Player(Builder),"Terrain Aoe cannot go above 10!")
        else
            call DisplayTimedTextToPlayer( Player(Builder), 0.52, -1.00, 2.00, "Terrain Aoe: "+I2S(terrainAoe) )
        endif
    elseif spell == AID_TERRAIN_SHAPE_TOGGLE then
        if terrainShape == 0 then
            set terrainShape = 1
            call DisplayTimedTextToPlayer( Player(Builder), 0.52, -1.00, 2.00, "Terrain Shape: Square" )
        else
            set terrainShape = 0
            call DisplayTimedTextToPlayer( Player(Builder), 0.52, -1.00, 2.00, "Terrain Shape: Circle" )
        endif
    endif
    return false
endfunction

//===========================================================================
private function Init takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER)
    call TriggerAddCondition( trig, Condition( function ConditionsRally ) )
    call TriggerAddAction( trig, function ActionsRally )
    set trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition( trig, Condition( function ConditionsOptions) )
    set trig = null
    call TimerStart(NewTimer(),TT_PERIOD,true,function Periodic)
    call Reset()
endfunction
endlibrary
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top