Skip to content

Cookbook

Small recipes to steal. Each one is complete and tested: put it in a file under a format 2.0 line and an event { name = "..." }, and it works - a .event file, or a .modchart file for the Lanes ones. Recipes that need a chart event use onEvent; the others are song scripts that run for the whole song.

Click one open, copy it, change the numbers until it feels right. That's really all there is to it.

Camera and HUD

Zoom pop on every downbeat
function onBeat(b)
    if b % 4 == 0 then
        camera.bump += 0.035
    end
end
A slow zoom that stays
params {
    zoom = number { from = "value1", default = 1.15, min = 0.5, max = 2, step = 0.05 },
    length = number { from = "value2", default = 4, min = 0, max = 32, step = 0.5, label = "Beats" },
}

function onEvent(p)
    tween(camera.zoom, p.zoom, beats(p.length), "sineInOut")
end

The shortcut for the same: zoom(p.zoom, beats(p.length)).

Shake on a hard hit
function onEvent(p)
    camera.shake = 0.012
    tween(camera.shake, 0, beats(1), "quadOut")
end

Or with the shortcut: shake(0.012, beats(1)).

The playfield rocks with the beat
local side = 1

function onBeat(b)
    side = -side
    hud.angle = side * 3
    tween(hud.angle, 0, beats(1), "quadOut")
end

Flashes and colours

Red flash on a miss
function onMiss(note)
    flash.color = #FF3040
    flash.alpha = 0.3
    tween(flash.alpha, 0, beats(0.5), "quadOut")
end
Cut to black and back
params {
    hold = number { from = "value1", default = 2, min = 0, max = 16, step = 0.5, label = "Beats black" },
}

function onEvent(p)
    screen.color = #000000
    screen.alpha = 1
    after(beats(p.hold), function()
        tween(screen.alpha, 0, beats(1))
    end)
end

With the shortcuts: fadeOut(#000000, 0), then fadeIn(beats(1)) in the after.

A title card on the chart event (uses onEvent)
function onEvent(p)
    title.color = #FFD040
    showTitle("ROUND 2", "fight!", beats(4))
end
The world goes dark for a part (fights, uses onSection)
function onSection(n)
    if n == 8 then stage.world = "off" end    -- only your pictures, notes and the HUD
    if n == 12 then stage.world = "on" end
end
A gold path builds up beat by beat (fights, uses onBeat)
function onBeat(b)
    if b < 16 then setBlock(0, 0, 0, b - 8, "gold_block") end
end
Your structure behind the opponent, turning in the drop (fights, uses onStart and onSection)
function onStart()
    build[0].file = "stage.nbt"
    build[0].z = 10
end

function onSection(n)
    if n == 8 then tween(build[0].turn, 360, beats(16)) end
end
A wall fades in for the last part (fights, uses onStart and onSection)
function onStart()
    for x = -6, 6 do
        for y = 0, 3 do setBlock(1, x, y, 0, "stone_bricks") end
    end
    build[1].z = 9
    build[1].alpha = 0
end

function onSection(n)
    if n == 12 then tween(build[1].alpha, 1, beats(4)) end
end
A crowd that jumps on every beat (fights, uses onStart and onBeat)
function onStart()
    for i = 0, 5 do
        mob[i].type = "villager"
        mob[i].x = -7.5 + i * 3
        mob[i].z = 7
    end
end

function onBeat(b)
    for i = 0, 5 do
        if (b + i) % 2 == 0 then mobAction(i, "jump") end
    end
end
A creeper walks up to the opponent and explodes (fights, uses onSection)
function onSection(n)
    if n == 4 then
        mob[0].type = "creeper"
        mob[0].x = 8
        mob[0].z = 4
        mobWalk(0, "opponent", beats(8))
    end
    if n == 6 then mobAction(0, "explode") end
end
A pig walks back and forth (fights, uses onStart and onBeat)
function onStart()
    mob[0].type = "pig"
    mob[0].x = -4
    mob[0].z = 2
end

function onBeat(b)
    if b % 8 == 0 then mobWalk(0, 4, 2, beats(4)) end
    if b % 8 == 4 then mobWalk(0, -4, 2, beats(4)) end
end
Fire everyone around can see for the drop (fights, uses onSection)
function onSection(n)
    if n == 8 then worldParticle("flame", "center", 40, 3) end
end
A storm comes up for the drop (fights, uses onSection)
function onSection(n)
    if n == 8 then
        stage.weather = "thunder"
        tween(stage.dayTime, 18000, beats(8))    -- the sky goes dark
        lightning("center", 6)
    end
end
Snow and fog for a quiet part (fights, uses onSection)
function onSection(n)
    if n == 4 then
        stage.weather = "snow"
        stage.fog = 0.6
        stage.fogColor = #A0B0C0
    end
    if n == 6 then
        stage.weather = "world"
        stage.fog = 0
    end
end
Lightning on every Sick of the opponent (fights, uses onOpponentHit)
function onOpponentHit(n)
    if n.judgment == "sick" then lightning("opponent", 3) end
end
The world turns red at low health (fights, uses onFrame)
function onFrame(dt)
    stage.tint = #FF2020
    stage.tintAlpha = (1 - player.health) * 0.4
end
Only the two fighters for the chorus (fights, uses onSection)
function onSection(n)
    if n == 16 then stage.world = "fighters" end    -- no world, the fighters stay
    if n == 24 then stage.world = "on" end
end
Strum background in the colour of the last judgment
function onHit(note)
    local c = note.judgment == "sick" ? #5CF2FF : note.judgment == "good" ? #5CFF8F : #FFB547
    underlay.color = c
    underlay.alpha = 0.8
    tween(underlay.color, #000000, beats(1))
    tween(underlay.alpha, 0.65, beats(1))
end

Text

A line of lyrics that fades in and out
params {
    line = text { from = "value1", label = "Line" },
    length = number { from = "value2", default = 4, min = 1, max = 16, step = 1, label = "Beats" },
}

local shown = 0

function onEvent(p)
    shown += 1
    local mine = shown
    text[7].value = p.line ?? ""
    text[7].y = 0.82
    text[7].alpha = 0
    tween(text[7].alpha, 1, beats(0.25))
    after(beats(p.length), function()
        if shown == mine then tween(text[7].alpha, 0, beats(0.5)) end
    end)
end

The counter makes sure a newer line isn't faded out by an older one's timer.

Live accuracy in a corner
function onFrame(dt)
    text[3].value = round(player.accuracy * 10) / 10 .. " %"
    text[3].align = "right"
    text[3].x = 0.97
    text[3].y = 0.92
    text[3].size = 0.8
end
Combo shout every 50
local next = 50

function onHit(note)
    if player.combo >= next then
        text[4].value = next .. " COMBO!"
        text[4].y = 0.6
        text[4].size = 1.6
        text[4].alpha = 1
        tween(text[4].size, 1.1, beats(0.5), "backOut")
        tween(text[4].alpha, 0, beats(1.5), "quadIn")
        next += 50
    end
end

function onMiss(note)
    next = 50
end

Lanes

These go in a .modchart file (why).

Lanes light up when they're pressed
function onFrame(dt)
    for lane = 0, 3 do
        strum[lane].scale = strum[lane].pressed ? 1.12 : 1
    end
end
The opponent's notes shake your lanes
function onOpponentHit(note)
    strum[note.lane].wobbleY = -10
    tween(strum[note.lane].wobbleY, 0, beats(0.5), "elasticOut")
end
Slow down, then speed up
function onEvent(p)
    scrollTo(0.6, beats(2))
    after(beats(4), function() scrollTo(1.4, beats(1)) end)
end

More in Modcharts and strum[lane].

Fighters (fights only)

Hearts on every Sick (uses onHit)
function onHit(n)
    if n.judgment == "sick" then particle("heart", "player", 2, 0.4) end
end
Fire around the opponent on every beat (uses onBeat)
function onBeat(b)
    particle("flame", "opponent", 10, 0.6)
end
The opponent catches fire for the drop (fights, uses onSection)
function onSection(n)
    if n == 8 then opponent.burning = true end
    if n == 12 then opponent.burning = false end
end
A knight's look for the opponent (fights, uses onStart)
function onStart()
    opponent.helmet = "iron_helmet"
    opponent.chestplate = "iron_chestplate"
    opponent.mainHand = "iron_sword"
    opponent.offHand = "shield"
end
You glow in the dark part (fights, uses onSection)
function onSection(n)
    if n == 6 then
        stage.dayTime = 18000
        player.glow = 1
    end
end
Both fighters bounce on every beat
function onBeat(b)
    for who = 0, 1 do
        fighter[who].squash = 0.18
        tween(fighter[who].squash, 0, beats(0.8), "elasticOut")
    end
end
The opponent flinches when you hit a sick
function onHit(note)
    if note.judgment != "sick" then return end
    opponent.pitch = -8
    tween(opponent.pitch, 0, beats(0.5), "backOut")
end
The opponent turns red as your combo grows
function onFrame(dt)
    local heat = min(1, player.combo / 100)
    opponent.color = mix(#FFFFFF, #FF4040, heat)
end
A new mob every 8 beats (against the dummy)
function onBeat(b)
    if b % 16 == 0 then setFigure("opponent", "zombie") end
    if b % 16 == 8 then setFigure("opponent", "creeper") end
end
The dummy turns into a skeleton for the drop, then comes back
function onSection(n)
    if n == 16 then setFigure("opponent", "skeleton") end
    if n == 24 then setFigure("opponent", "") end
end
Plain skins for this song (Figura avatars off)
function onStart()
    player.figura = false
    opponent.figura = false
end

More in The fighters.

Sprite characters

A dancing GF that cheers every 25 notes (uses onStart)
function onStart()
    character[2].file = "characters/gf.png"     -- + gf.xml next to it
    character[2].x = 0.5
    character[2].y = 0.8
    character[2].cheerEvery = 25
    characterPose(2, "danceLeft", "GF Dancing Beat", 0, -9, "30, 0-14")
    characterPose(2, "danceRight", "GF Dancing Beat", 0, -9, "15-29")
    characterPose(2, "cheer", "GF Cheer")
end
The opponent sprite jumps on the drop (uses onSection)
function onSection(n)
    if n == 16 then characterPlay(1, "hey", beats(1)) end
end

Sound

A Minecraft bell on every fourth beat (uses onBeat)
function onBeat(b)
    if b % 4 == 0 then playGameSound("block.note_block.bell", 0.6, 1.5) end
end
A sound on the drop
function onEvent(p)
    playSound("impact.ogg", 0.8)   -- a file in the song folder or events/
    camera.bump += 0.08
end
The opponent's voice drops out for a bar
function onEvent(p)
    tween(volume.opponent, 0, beats(0.5))
    after(beats(4), function() tween(volume.opponent, 1, beats(0.5)) end)
end

The game window

More in Game window and pop-outs.

The window shakes on every miss
function onMiss(note)
    window.x = 14
    tween(window.x, 0, beats(0.5), "elasticOut")
end
The judgments in a window of their own, floating above the game
function onEvent(p)
    popout[0].show = "judgments"
    tween(popout[0].y, -260, beats(2), "sineInOut")
end
Each lane flies out into its own window and circles the screen
local circling = false

function onEvent(p)
    popout[0].show = "left"
    popout[1].show = "down"
    popout[2].show = "up"
    popout[3].show = "right"
    circling = true
    after(beats(16), function()
        circling = false
        resetWindow(beats(2))    -- glide home, then close
    end)
end

function onFrame(dt)
    if not circling then return end
    for i = 0, 3 do
        local a = time / 1000 + i * pi / 2
        popout[i].x = cos(a) * 300
        popout[i].y = sin(a) * 150
    end
end