Skip to content

Script integration ​

KubeJS, CraftTweaker and MineTweaker scripts can extend What Hit Me? on the server (script API 2):

FeatureWhat a script doesUsed in
Rules and templatesaddRule(rule), addTemplate(output, lines)rules (with then / else), templates
Settings and lockssetSetting(key, value, locked), setSettingRule(key, json), addLock(group, name), disableVariable(name)settings & locks, unlock conditions
Conditionsregisters name -> (player) => true/falserules and unlock conditions as script:<name> (!script:<name> negates)
Variablesregisters name -> (player, damage) => texttemplates as {script:<name>}, rule names / tips / death messages, trigger commands
Eventslistens to damageRecorded, death, respawn, alertchange the name / tip of a hit, add badges, hide fields, cancel a recording, add summary lines, run anything
Readthe last death, history, statistics, /whm test results, check(player, condition)anything

Everything is decided on the server and sent to the players, like the rules: players with the mod see script values in their own (translated) output, players without the mod get the server's English chat. The integration never makes a script mod required, and it loads only when the script mod is installed.

Supported versions ​

Script modFormMinecraft / loaderPage
KubeJS 8 / 7global WhatHitMe, events WhatHitMeEvents.* (server scripts)26.1.2 NeoForge, 1.21.1 NeoForgeKubeJS
KubeJS 6 (also the KubeJS 7 beta of NeoForge 1.20.4)the same1.20.4 NeoForge, 1.20.1 Forge / Fabric (also NeoForge 1.20.1 with the Forge jar), 1.19.2 Forge / FabricKubeJS
KubeJS 5 / 3global WhatHitMe, events onEvent('whathitme.*')1.18.2 Forge / Fabric, 1.17.1 Fabric, 1.16.5 Forge / FabricKubeJS
Old KubeJS (1.x / 2.x)global WhatHitMe, events events.listen('whathitme.*')1.16.1 Fabric, 1.15.2 Forge, 1.14.4 Forge, 1.12.2 ForgeKubeJS
CraftTweaker (new ZenScript)ZenScript class mods.whathitme.WhatHitMe1.21.1, 1.20.6 Fabric / NeoForge; 1.20.4 Forge / Fabric / NeoForge; 1.20.2 - 1.18.2 Forge / Fabric; 1.17.1 Forge; 1.16.5, 1.15.2, 1.14.4 ForgeCraftTweaker
CraftTweaker 1.12.2ZenScript class mods.whathitme.WhatHitMe1.12.2 ForgeCraftTweaker
MineTweaker 3 / CraftTweaker 3.x (also the GTNH fork)ZenScript class mods.whathitme.WhatHitMe1.11.2, 1.10.2, 1.9.4, 1.8.9, 1.7.10 Forge (MineTweaker 3.0.10B and CraftTweaker 3.0.9: partly)MineTweaker 3

No script mod exists for the other versions (1.21.3 - 1.21.11, 26.2, 26.3, KubeJS on Fabric / Forge 1.21+). There the recipes in Without a binding still work. KubeJS 8 on 26.1.2 needs Java 25 (it does not start on Java 27).

Pages ​

PageContents
KubeJSKubeJS 1.x - 8: script folders, event names per generation, examples
CraftTweakerCraftTweaker 1.12.2 and 1.14.4 - 1.21.1 (ZenScript), player types per version
MineTweaker 3 / CraftTweaker 3.x1.7.10 - 1.11.2, the Api / Player objects, the GTNH fork
API referenceRegistration, events, damage, death and reading methods; the Java API for mod developers

A first script ​

The same idea works in every script mod: a condition script:veteran used by a rule, and a death listener that adds a line to the summary. KubeJS 7 / 8:

js
// kubejs/server_scripts/whathitme.js
WhatHitMeEvents.register(event => {
  event.condition('veteran', 'Has the veteran tag', player => WhatHitMe.check(player, 'tag:veteran'))
  event.addRule({ match: '*@minecraft:wither', if: ['script:veteran'],
    then: { name: '&5The Withered King' }, 'else': { name: '???', hide: ['attacker', 'mod'] } })
  event.setSettingRule('command.stats', '{"if": ["script:veteran"], "value": "all", "else": {"value": "none"}}')
})

WhatHitMeEvents.death(event => {
  event.addSummaryLine('&7Deaths so far: ' + WhatHitMe.stats(event.player).deaths)
})

The same in the other script mods: CraftTweaker, MineTweaker 3.

Reload and errors ​

/whm reload with the "Scripts:" line: what the scripts registered

  • /whm reload and the script mod's reload rebuild everything cleanly: what scripts registered is removed, the scripts register again, the runtime entries are merged once. Rules from scripts come after the pack files' rules; settings and templates from scripts replace the pack files' entry of the same key; locks and switched-off variables add up.
  • /whm reload lists what scripts registered (Scripts: 2 conditions (...), 1 variable (...), listeners: death, ...) and warns about unknown script: names, about functions that failed and about a missing script mod.
  • A script function that throws counts as false (conditions) or empty (variables), the listener is skipped; the error is logged once per function. A broken script never breaks a death recap.
  • Without the script mod, script: conditions are false and /whm reload says so; nothing else changes.

Without a binding ​

These work on every version, also where no binding exists yet:

  • Tags and scores set by scripts, read by rules. A script adds a scoreboard tag (/tag <player> add boss_ready) or changes a score; a rule checks it with tag: / score:.
  • Triggers call scripts. A rule's triggers run any server command, including a command or function your script mod registers. {script:<name>} works in trigger commands where a binding exists.
json
{
  "rules": [
    { "match": "*@mymod:boss", "if": ["tag:boss_ready"],
      "then": { "triggers": { "commands": ["function mypack:boss_death"] } },
      "else": { "name": "???", "hide": ["attacker", "mod"], "triggers": { "commands": ["function mypack:boss_death"] } } }
  ]
}

Made by junjun1z. The mods are MIT licensed.