The queue method from the last lesson gets you as far as "pressed". But for half of all skills the whole point is where - a teleport, a ground-targeted blast, where a summon appears. You could lay locations and read those, but then you are back at the 255-location problem.
There is already one situation where StarCraft asks the player for a coordinate: placing a building. So make the skill button a Create Building rather than a Create Unit, and the game collects the clicked spot for you and puts it in the caster's CUnit - 0x58 is X and 0x5A is Y.
// 메인 명령으로 감지하고, 좌표를 읽어 로케이션을 옮긴다
// detect on the main order, read the coordinates, move a location
const x, y = posread_epd(caster + 0x58/4);
setloc("SkillTarget", x, y);| The building's graphic | Change it to a cursor, a dot, a beacon or something like a start location, so it reads as an indicator. |
|---|---|
| The Build (Protoss) order's requirements | Its default limits it to Probes. Widen it or the hero pressing the button does nothing. |
| Which order to detect | Main Order, not Secondary Order. |
There is a reason it has to be the main order. Building uses both: the main order walks the unit to the spot and the secondary order makes the building. Reading the main order fires your trigger before the unit starts walking; waiting for the secondary one means the skill goes off after the hero has walked across the map.
This has exactly one drawback: building costs minerals and gas, not energy. To charge energy instead, change the approach - use a real spell, but hollow it out so it does nothing by itself.
- 1Set that order's Animation to ReturnToIdle, so the cast never actually happens.
- 2Set that spell weapon's cooldown to 100. That is the mark that tells this cast apart from a real one.
- 3Condition on Spell Cooldown instead of the main order; when it fires, run the skill and write the cooldown back to 0.
- 4Read the coordinates from 0x58 and 0x5A exactly as before.
The engine charges the energy, because a real spell really was cast - it just does nothing, and everything it appears to do is your trigger.
If the target has to be a unit rather than a patch of ground there is a third route. Make the button an ordinary spell button: the cursor changes, the player picks a unit, and the choice lands in the Secondary Order and its target field. Read that, cancel the order, and produce the effect yourself.
| A build button | Gives you a ground coordinate (0x58, 0x5A). Detect on the main order. Costs minerals and gas. |
|---|---|
| A real spell with its insides emptied | Gives you a ground coordinate and the engine charges the energy. Detect on the spell cooldown. |
| An ordinary spell button | Gives you a unit target. Detect on the secondary order and its target field. You handle the cost. |
All three routes share one price. Order detection consumes the order by writing Stop, and the engine cannot tell your Stop from the player pressing stop. So detection and the genuine cast cannot coexist: hook the order and the real spell does not resolve. That is the structure, not a bug.
So when you want the real spell to happen and only to trim its result - Hallucination producing one copy instead of two - detection is the wrong tool. Use EUDLoopNewUnit, which visits only the units created this cycle and is cheap even in a 1,600-unit map, and delete one; the player sees two for a frame. Without EUD at all: MoveLocation works on hallucinations, so a classic trigger can remove both copies and create one dummy built from the boss's stats.
On that third route you have to charge the energy yourself for a simple reason: as far as the game is concerned the button is not a spell, so the game's own energy check never runs. Read the energy out of the struct, do nothing if it is short, and subtract before firing if it is not.
A note on the source: the third route comes from 2020 Brood War era material that the corpus marks unverified. The addresses used were checked against eud_book's SC:R support levels - CUnit's Secondary Order ID and Build Queue are both Supported - but test it on Remastered anyway.
Where the third route gets used most is "use this item on one of my units", and the shape is fixed enough to be worth memorising whole.
foreach(player : EUDLoopPlayer()) {
const orb = CUnit.cast(orbEPDs[player]);
if (orb == 0) continue;
if (orb.order == "Die") { orbEPDs[player] = 0; continue; } // 죽은 것 정리 / reap
if (orb.order == <인식할 명령>) {
orb.order = "Stop"; // 한 번만 발동 / consume it
const target = orb.orderTarget;
if (orb.owner != target.owner) continue; // 내 유닛에게만 / my own units only
if (target.unitType != "Terran Marine") continue;
...
}
}| Does every item need its own sacrificed spell? | No. Several items can share one spell; which item it was is sorted out afterwards from orb.unitType. |
|---|---|
| How do you write “my units only”? | orb.owner != target.owner, and that is all of it - there is no separate check. |
| Nothing is detected at all | Check you stored the item's EPD before the CreateUnit, not after. Store it after and the handle is empty, and the symptom is that nothing happens at all. |
| It is detected but the order never matches | Put a print above the test. Nothing printing means the handle is wrong; printing but never matching means the button is not changing the order - check the weapon and combat auto-response. |
And there is a rule about where to spend effort in it. The detection runs every cycle and is worth optimising; what happens after it fires runs rarely and should be written plainly. Optimising both equally only makes the code harder.
Separate from the implementation, a non-target skill carries one design decision: how the player aims it. Three schemes were actually built and compared, and both the verdict and the field reports afterwards are worth having.
| 1. Press, move, press again | Pressing the button gives you time to move the mouse; pressing again fires in that direction. |
|---|---|
| 2. The Storm model | Exactly how a High Templar casts Storm: the button puts you in a targeting state and a left click places it. |
| 3. Press and it goes | Scheme 1 without the second press: the moment the button goes down it fires toward the mouse. |
Scheme 2 won the vote, and the reason is a good one: it is what StarCraft already does, so there is nothing for a player to learn. It works without a tutorial.
Two field reports from people who shipped them both matter. With scheme 2, a surprising number of players never left-click, so every public game has someone reporting that the skill does not fire. With scheme 3, the location that follows the mouse lags by a beat, so a skill that needs precise aim misfires often. The more precise the skill, the more scheme 3 should be avoided - and if you use scheme 2, put the “now left-click” prompt somewhere.
Detecting a button press with the build queueThree ways to read the struct wrongThe primitives that are already written