Game Events Reference#
All script event handlers use camelCase — but the engine matches them case-insensitively, so both onDeath and ondeath work. Use camelCase for readability.
Player Script Events#
Player events are defined in player script classes (e.g. player_events.js). The player instance is always this, not a player parameter. Think of each player as running the script themselves.
onLogin#
Called when the player logs in.
onDeath#
Called when the player dies.
function onDeath(killer) {
if (killer.type == 'player')
this.say(`I was killed by ${killer.name}!`);
}
killer— the entity that dealt the killing blow
onKill#
Called when this player kills another player.
function onKill(victim, rejectReason) {
if (!rejectReason)
this.say(`I defeated ${victim.name}!`);
}
victim— the killed playerrejectReason:string—"sameip","playerland","clanland", ornullif kill was counted
onRevive#
Called when the player revives after dying.
onEnterMap#
Called when the player enters a new map or warps.
map:object— map object (see Map Reference)template:string— map template nameoldpos:object— previous position{x, y, map, template}
onEnvironmentZone#
Called when the player moves into a different environment zone.
function onEnvironmentZone(oldEnvironment, newEnvironment) {
if (newEnvironment && newEnvironment.zone === "cave")
this.setambient(0.2, 0.2, 0.4);
}
oldEnvironment:object|null— previous zone object (contains.zone,.map,.weather,.x,.y, etc.)newEnvironment:object|null— new zone object
onPvPZoneChange#
Called when the player enters or exits a PvP zone.
isPvP:boolean—trueif now in a PvP zone
onHurt#
Called when the player takes damage.
attacker— the entity dealing damagedamage:number— damage amount- Return
{cancelled: true}to block the damage
onDamage#
Called when the player deals damage to another entity.
target— the entity receiving damagedamage:number— damage amount- Return
{damage: newValue, cancelled: bool}to modify or cancel
onWeaponChange#
Called when the player equips a different weapon.
oldWeapon:object— previous weapon objectnewWeapon:object— new weapon object
onCustomUpload#
Called when a player uploads a custom graphic.
function onCustomUpload(fileName, customType) {
this.echo(`Uploaded custom ${customType}: ${fileName}`)
}
fileName:string— the filename of the uploaded graphiccustomType:string— the type of custom (e.g.,"head","body","shield", etc.)
onCustomChecked#
Called when a staff member approves, rejects, or refunds a custom graphic.
function onCustomChecked(fileName, customType, uploaderUserID, status, reason) {
this.echo(uploaderUserID + "'s custom " + customType + " was " + status);
}
fileName:string— the filename of the checked custom graphiccustomType:string— the type of custom graphicuploaderUserID:number— the ID of the player who uploaded itstatus:string—"approved","rejected", or"refunded"reason:string— the reason provided (if rejected)
onPickupItem#
Called when the player picks up an item from the ground.
onSoldItems#
Called when the player sells items.
price:number— total sale priceitemid:string— item ID solditem— item config objectitemnr:number— quantity sold
onItemPurchase#
Called when the player purchases an item.
onJobDone#
Called when the player completes a job (e.g. harvesting, digging).
onSays#
Called when the player sends a chat message. Use this.chat to read it.
onNameChange#
Called when the player changes their display name.
onOnlineHour#
Called each hour the player is online.
onLikeSent#
Called when this player likes another player.
onLikeReceived#
Called when another player likes this player.
onSparWin#
Called when the player wins a spar.
onSparLost#
Called when the player loses a spar.
onClanJoin#
Called when the player joins a clan.
onClanCapture#
Called when the player's clan captures a building.
onStoryPublish#
Called when the player publishes a story.
onEquipPet#
Called when the player equips a pet.
onTradeFinished#
Called for both players when a trade has been completed.
function onTradeFinished(otherPlayer, myCoins, myItems, otherCoins, otherItems) {
this.showmessage(`Trade with ${otherPlayer.name} done!`);
}
otherPlayer— the trade partnermyCoins,myItems— what this player gave,otherCoins,otherItems— what the partner gave
onAttackTriggered#
Called when the player triggers an attack.
onTransferAccount#
Called when an admin transfers an account with /transferaccount, before the data is merged. Use it to transfer script data (e.g. DB tables).
Car Events#
Fired on the player script classes for cars (mounts with mounttype: "car"), e.g. for taxi or escort jobs.
onCarEnter#
Called when the player gets into a car.
onCarExit#
Called when the player gets out of a car.
onCarTaken#
Called when the player takes over a parked car or an NPC car (can be disabled with enablecarjacking: false in main.json).
function onCarTaken(parkedByUserid, itemid) {
if (parkedByUserid)
this.showmessage("You stole someone's car!");
}
parkedByUserid— user id of the player who left the car there, ornull
Related: player.cardamage, player.repaircar(), player.escortpassenger (see Player Reference).
Payment Events#
onLoadPaymentPackages#
Called when the client requests the coin packages; answer with player.sendpaymentpackages(data).
onCompletePayment#
Called after a purchase if completepaymentbyscript is enabled in main.json, instead of adding the coins automatically.
Item / Weapon Events#
onEquip#
Called on an item or weapon script when equipped.
// Server-side item scripts:
function onEquip(player, autoequip) { }
// Client-side weapon scripts:
function onEquip(player) { }
autoequip:boolean— true if auto-equipped on pickup
onUnequip#
Called when the item/weapon is unequipped.
Effect Events#
onEffectStart#
Called when a status effect is applied to the player.
onEffectEnd#
Called when a status effect ends.
Console Events#
These only fire for players with admin access who have the console open.
onConsoleOpen#
onConsoleClose#
onConsoleChat#
Called when the admin types in the console. Return true to suppress the default output.
function onConsoleChat(message) {
if (message == 'hello') {
this.echo('Hi from script!');
return true;
}
}
Client-Side Display Events#
These events fire on the client (in player_events.js or a client script class) when specific player properties change visually.
onCoinsChange#
Called when the player's coin count changes.
onBodyChange#
Called when the player's equipped body item changes.
onHatChange#
Called when the player's hat changes.
onHeadChange#
Called when the player's head item changes.
onShieldChange#
Called when the player's shield changes.
Custom / Scheduled Events#
onEVENT (custom)#
Triggered by this.scheduleevent(delay, "eventname", ...params).
this.scheduleevent(2, 'myEvent', 42);
function onMyEvent(value) {
this.say(`Triggered with: ${value}`);
}
onTimeout#
Triggered after this.settimeout(seconds).
onStoryEnd#
Triggered when a non-looping story finishes (via setstory).
See Also#
- Player Reference — Full player object API
- Scripting Guide — How to set up script classes and use events
- NPC Reference — NPC-specific events (onCreated, onPlayerTouchsMe, etc.)