Skip to content
Back to skills

Hytopia Events

ASecurity

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.

  • 225 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added September 4, 2026
toolstypescriptapi

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 13 files and shows the line behind each finding

Scanned September 4, 2026

npx -y skills add NeverSight/skills_feed --skill hytopia-events --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Hytopia Events?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Hytopia Events
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/neversight-hytopia-events/badge)](https://www.skillsdirectory.com/skills/neversight-hytopia-events)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: hytopia-events
description: 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.
---

# HYTOPIA Events & Input

This skill helps you handle events and input in HYTOPIA SDK games.

## When to Use This Skill

Use this skill when the user:

- Wants to respond to player actions or game events
- Needs to handle chat commands
- Asks about player input (keyboard, mouse, touch)
- Wants to create custom events
- Needs to handle game lifecycle events (start, end, player join/leave)
- Asks about event prioritization or cancellation

## Core Event Concepts

### Event Listeners

```typescript
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
};
```

### Chat Commands

```typescript
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
};
```

### Player Input

```typescript
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;
  }
};
```

### Custom Events

```typescript
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 });
```

## Input Handling Patterns

### Movement Input

```typescript
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;
  }
};
```

### Mouse/Click Handling

```typescript
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);
  }
};
```

## Game Lifecycle Events

```typescript
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();
};
```

## Best Practices

1. **Keep event handlers short** - delegate to functions for complex logic
2. **Return false to cancel** - prevent default behavior when needed
3. **Use typed events** - define interfaces for custom events
4. **Clean up listeners** - remove listeners when entities despawn
5. **Debounce rapid inputs** - prevent spamming with cooldowns

## Common Mistakes

- Don't forget to return boolean in chat handler
- Don't block all chat when handling commands (return true for normal messages)
- Don't forget input can be null if player disconnects mid-frame
- Don't rely on client-side input alone - validate on server

Files in this skill

  • SKILL.md5 KB
  • description_ar.txt450 B
  • description_cn.txt227 B
  • description_de.txt298 B
  • description_en.txt229 B
  • description_es.txt303 B
  • description_fr.txt375 B
  • description_it.txt310 B
  • description_ja.txt409 B
  • description_ko.txt323 B
  • description_ru.txt532 B
  • description_tw.txt227 B
  • stats.json65 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in tools →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.