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.
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +1
  • V-SNES V-SNES:
    Happy Friday!
    +1

      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