SCRMaps
/
Sign in

Showing an explosion, in one line

How to put any of StarCraft's effect graphics wherever you want: one unit and one write.

11 min read

To make an explosion happen at a spot, the usual approach is hunting for a unit that has that graphic. There is no need: the whole technique is three lines.

wwrite(0x666160 + 2*380, imageId);   // 380번 스프라이트의 이미지를 바꾼다
CreateUnit(1, 33, loc, cp);          // 유닛 33 = 스캐너 스윕
RemoveUnit(33, cp);
Unit 33, the Scanner Sweep, spawns sprite 380 when it is created. Change which image that sprite uses and that image plays at the spot.

Why it composes matters: StarCraft reads the image only at creation and never looks again. So setting the image, creating, setting it again and creating gives you two different effects at once out of one shared sprite slot.

Why unit 33
It cannot be clickedIt cannot be clicked, not even by dragging.
It does not appear on the minimapIt is not drawn there at all.
Any number can overlapAny number of them can occupy the same spot.
A unit underneath is not slowedPutting one over a ground unit does not affect its movement.
Unit-moving triggers do not touch itIt will not be moved or swept up by accident.

All of which is exactly what you want from a decoration. It is this list, not any graphic, that made unit 33 the effect vehicle everybody uses.

You have to make unit 33 trigger-creatable first, or CreateUnit silently does nothing - no error and no unit. Ticking "unit listing and palette" in DatEdit is this, and the same thing can be done in code: it is bit 0x0002 of the Staredit availability flags.

Put back what you changed. Sprite 380 is the slot the game uses for a real Scanner Sweep too, so without restoring the original image the next scan plays your explosion.

One more effect made of the same parts, because it fixes the pattern. The trail of fading copies behind a moving unit is nothing but a shadow spawned every frame and removed shortly after.

if (MemoryXEPD(u + 0x20/4, AtLeast, 1, 0x12)) {        // 움직일 때만 / only while moving
    const dir = bread_epd(u + 0x21/4, 0x21 % 4);       // 유닛이 보는 방향 / its facing
    // ... 각도로 바꾸고 180도 더해 ‘뒤에’ 놓고 ...
    const x, y = lengthdir(8, reverse);
    MoveLocation(loc, UNIT, p, "Anywhere");  addloc(loc, x, y);

    TrgUnit("Nuclear Missile").startDirection = (angle * 32 / 360 + 8) & 31;
    Sprite("Nuclear Missile").image = SHADOW_IMAGE;    // 그 유닛의 이미지
    Image(SHADOW_IMAGE).drawingFunction = 6;           // VisionCloaked — 반투명 / translucent

    const shadow = CUnit.from_next();
    CreateUnit(1, "Nuclear Missile", loc, p);
    shadow.statusFlags.NoCollide = true;
    shadow.removeTimer = 6;
    SHADOW.add(shadow);
    SetMemoryEPD(shadow + 0x10/4, SetTo, 0);           // 이동 목표 제거
    Image(SHADOW_IMAGE).drawingFunction = 0;           // 바로 되돌림
}
Five things to take from it
Mask 0x120x10 moving plus 0x02 accelerating on the movement flags - the trail only appears while the unit is actually moving.
Drawing function 6Function 6 is NOT shadow - it is VisionCloaked, the shimmer a cloaked unit shows to its own side. Shadow is 10. That is exactly why the trail reads as a ghost, and reaching for the name instead of the number gives you a flat black drop shadow. Setting and unsetting it around the single CreateUnit keeps anything else drawn this frame from picking it up.
startDirection is in 32 stepsstartDirection is in 32 steps, not 256: (angle * 32 / 360 + 8) & 31.
removeTimer 6The length of the trail. Keep them in a UnitGroup and reap at removeTimer == 1 so no corpse is left.
The vehicle is a Nuclear MissileThe vehicle is a Nuclear Missile for the same reason unit 33 is used elsewhere: nobody else is using it. It needs its unit-listing flag turned on before it can be created.
The five pools the engine draws from