skills/hytopia-events/SKILL.md
Helps handle events and input in HYTOPIA SDK games. Use when users need to respond to player actions, game events, chat commands, or input handling. Covers event listeners, chat commands, player input, and game lifecycle events.
npx skillsauth add abstrucked/hytopia-skills hytopia-eventsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill helps you handle events and input in HYTOPIA SDK games.
Documentation: https://dev.hytopia.com/sdk-guides/events
Use this skill when the user:
import { World, Player } from 'hytopia';
// Listen for player join
world.onPlayerJoin = (player: Player) => {
console.log(`${player.username} joined!`);
player.sendMessage('Welcome to the game!');
};
// Listen for player leave
world.onPlayerLeave = (player: Player) => {
console.log(`${player.username} left!`);
};
// Listen for player chat
world.onPlayerChat = (player: Player, message: string) => {
console.log(`${player.username}: ${message}`);
return true; // Return false to block message
};
import { World, Player } from 'hytopia';
world.onPlayerChat = (player: Player, message: string) => {
if (message.startsWith('!')) {
const args = message.slice(1).split(' ');
const command = args[0];
switch (command) {
case 'help':
player.sendMessage('Available commands: !spawn, !teleport, !kit');
break;
case 'spawn':
player.setPosition({ x: 0, y: 100, z: 0 });
player.sendMessage('Teleported to spawn!');
break;
case 'kit':
giveStarterKit(player);
break;
default:
player.sendMessage(`Unknown command: ${command}`);
}
return false; // Don't broadcast command to other players
}
return true; // Allow normal chat
};
import { Player, Input } from 'hytopia';
// Handle player input
player.onInput = (input: Input) => {
if (input.isPressed('space')) {
// Jump
player.applyImpulse({ x: 0, y: 10, z: 0 });
}
if (input.isPressed('e')) {
// Interact
handleInteraction(player);
}
if (input.mouseDelta.x !== 0) {
// Mouse moved horizontally
player.rotation.y += input.mouseDelta.x * 0.1;
}
};
import { EventEmitter } from 'hytopia';
// Create custom event emitter
const gameEvents = new EventEmitter();
// Define event types
interface GameEvents {
'player-kill': { killer: Player; victim: Player };
'game-start': { map: string };
'game-end': { winner: Player };
}
// Listen for events
gameEvents.on('player-kill', ({ killer, victim }) => {
killer.sendMessage(`You eliminated ${victim.username}!`);
victim.sendMessage(`You were eliminated by ${killer.username}!`);
});
// Emit events
gameEvents.emit('player-kill', { killer: player1, victim: player2 });
player.onInput = (input: Input) => {
const moveSpeed = 5;
const moveDirection = new Vector3(0, 0, 0);
if (input.isPressed('w')) moveDirection.z += 1;
if (input.isPressed('s')) moveDirection.z -= 1;
if (input.isPressed('a')) moveDirection.x -= 1;
if (input.isPressed('d')) moveDirection.x += 1;
if (moveDirection.length() > 0) {
moveDirection.normalize().multiply(moveSpeed);
player.velocity.x = moveDirection.x;
player.velocity.z = moveDirection.z;
}
};
player.onInput = (input: Input) => {
// Left click
if (input.isMousePressed(0)) {
const raycast = world.raycast(player.position, player.lookDirection, 5);
if (raycast.hit && raycast.entity) {
// Attack entity
raycast.entity.takeDamage(10);
}
}
// Right click
if (input.isMousePressed(1)) {
// Place block or use item
useHeldItem(player);
}
};
import { Game } from 'hytopia';
const game = new Game();
game.onStart = () => {
console.log('Game started!');
// Initialize game state
};
game.onEnd = () => {
console.log('Game ended!');
// Cleanup, save state
};
game.onTick = (deltaTime: number) => {
// Update game logic every frame
updateGameTimer(deltaTime);
checkWinConditions();
};
development
Helps build and manage worlds in HYTOPIA SDK. Use when users need to create terrain, place blocks, manage chunks, or work with the world editor integration. Covers blocks, chunk loading, world generation, and build.hytopia.com workflow.
tools
Helps create and use plugins in HYTOPIA SDK games. Use when users need to add NPM packages, create reusable modules, or extend game functionality. Covers plugin requirements, installation, and best practices.
development
Helps implement physics and collision in HYTOPIA SDK games. Use when users need rigid bodies, collision detection, raycasting, forces, or physics-based gameplay. Covers PhysicsComponent, colliders, raycasting, and physics simulation.
development
Helps save and load persistent data in HYTOPIA SDK games. Use when users need to save player progress, leaderboards, game state, or any data that persists across sessions. Covers PersistenceManager, global data, and player data.