Darthfett
Aerospace/Cybersecurity Software Engineer
- Reaction score
- 615
Auto Reorder Code
Do your units constantly go back to their starting place when you order them to attack-move? Well this code will fix that, and will make sure they are constantly ordered to go to the original location that you ordered them to move!
It starts with a JASS trigger to store the X and Y of the location that the unit was ordered.
When you put this into your map, you should delete the globals section, and add in the variable "ordercache", and of type Game Cache. This code also has a condition that makes it so the auto reordering will only affect units owned by Player 12 (Brown). You should also put function H2I in the map icon at the top of your trigger editor, if you don't already have it in their.
Here is the second trigger, which will automatically order all the units to their current target location.
This one, you'll just have to remove the globals section. It will automatically order all the units in tempgroup, which I have left as a blank group for you to set. It can be all the units owned by Brown, or just some of them.
I hope you find this one useful! It is one of the triggers that may be included in Infiltration, if you have seen the map yet.
Do your units constantly go back to their starting place when you order them to attack-move? Well this code will fix that, and will make sure they are constantly ordered to go to the original location that you ordered them to move!
It starts with a JASS trigger to store the X and Y of the location that the unit was ordered.
Code:
globals
gamecache udg_ordercache
endglobals
function H2I takes handle h returns integer
return h
return 0
endfunction
function STL_Conditions takes nothing returns boolean
return (GetOwningPlayer(GetOrderedUnit()) == Player(11) and GetIssuedOrderId() == String2OrderIdBJ("attack")) == true
endfunction
function SetTargLoc takes nothing returns nothing
local unit u = GetOrderedUnit()
local integer id = H2I(u)
call StoreReal(udg_ordercache,I2S(id), "X",GetUnitX(u))
call StoreReal(udg_ordercache,I2S(id), "Y",GetUnitY(u))
set u = null
endfunction
function InitTrig_SetTargLoc takes nothing returns nothing
set gg_trg_SetTargLoc = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( gg_trg_SetTargLoc, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
call TriggerAddAction( gg_trg_SetTargLoc, function SetTargLoc )
call TriggerAddCondition(gg_trg_SetTargLoc,Condition(function STL_Conditions))
endfunction
When you put this into your map, you should delete the globals section, and add in the variable "ordercache", and of type Game Cache. This code also has a condition that makes it so the auto reordering will only affect units owned by Player 12 (Brown). You should also put function H2I in the map icon at the top of your trigger editor, if you don't already have it in their.
Here is the second trigger, which will automatically order all the units to their current target location.
Code:
globals
gamecache udg_ordercache
endglobals
function H2I takes handle h returns integer
return h
return 0
endfunction
function AutoReorderUnits takes nothing returns nothing
local group tempgroup = CreateGroup()
local unit TEMP_Unit
loop
set TEMP_Unit = FirstOfGroup(tempgroup)
exitwhen TEMP_Unit == null
if GetOwningPlayer(TEMP_Unit) != Player(11) then
call GroupRemoveUnit(tempgroup,TEMP_Unit)
endif
endloop
loop
set TEMP_Unit = FirstOfGroup(tempgroup)
exitwhen TEMP_Unit == null
call IssuePointOrder(TEMP_Unit,"attack",GetStoredReal(udg_ordercache,I2S(H2I(TEMP_Unit)),"X"),GetStoredReal(udg_ordercache,I2S(H2I(TEMP_Unit)),"Y"))
call GroupRemoveUnit(tempgroup,TEMP_Unit)
endloop
call DestroyGroup(tempgroup)
set tempgroup = null
endfunction
function InitTrig_AutoReorderUnits takes nothing returns nothing
set gg_trg_AutoReorderUnits = CreateTrigger()
call TriggerRegisterTimerEvent(gg_trg_AutoReorderUnits,2.00,true)
call TriggerAddAction(gg_trg_AutoReorderUnits,function AutoReorderUnits)
endfunction
This one, you'll just have to remove the globals section. It will automatically order all the units in tempgroup, which I have left as a blank group for you to set. It can be all the units owned by Brown, or just some of them.
I hope you find this one useful! It is one of the triggers that may be included in Infiltration, if you have seen the map yet.