backTeleports

  • community
  • administration
  • Takaro v0.3.3
  • all
Version
View export JSON

This command will make it possible for the player when they teleport to home, to save their last location, so that they can do the back command and get teleported back to the previous location.

Do note it checks for the word HOME to save the coordinates! you can change it in the hook config.

Configuration 0

Settings you fill in when installing the module on a server.

This module takes no configuration.

Raw config schema
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "required": [],
  "additionalProperties": false
}
Raw UI schema
{}

Commands 1

Chat commands players trigger in game.

  • back

    No help text available

    Command source
    // commands/back.js
    import { takaro, data, checkPermission, TakaroUserError } from '@takaro/helpers';
    
    async function main() {
        const { pog, gameServerId, module: mod } = data;
    
        if (!checkPermission(pog, 'BACK_TELEPORT_USE')) {
            throw new TakaroUserError('You do not have permission to use back teleport.');
        }
    
        // Get back location
        const backVar = await takaro.variable.variableControllerSearch({
            filters: {
                key: ['back_location'],
                gameServerId: [gameServerId],
                playerId: [pog.playerId],
                moduleId: [mod.moduleId],
            },
        });
    
        if (backVar.data.data.length === 0) {
            throw new TakaroUserError('No previous location found. Teleport somewhere first to create a back location.');
        }
    
        const backLocation = JSON.parse(backVar.data.data[0].value);
    
        // Teleport to back location
        await takaro.gameserver.gameServerControllerTeleportPlayer(gameServerId, pog.playerId, {
            x: backLocation.x,
            y: backLocation.y,
            z: backLocation.z,
        });
    
        await data.player.pm('Teleported back to your previous location!');
    }
    
    await main();

Hooks 1

Code that runs in reaction to a game or Takaro event.

  • captureTeleportLocation

    log chat message

    Hook source
    // hooks/captureTeleportLocation.js
    import { takaro, data } from '@takaro/helpers';
    
    async function main() {
      const { pog, gameServerId, module: mod, eventData } = data;
    
      try {
        const chatMessage = eventData.msg;
        const prefix = (await takaro.settings.settingsControllerGetOne('commandPrefix', gameServerId)).data.data.value;
    
        // Check if this is a teleport command by looking at the chat message
        if (!chatMessage.startsWith(prefix)) {
          return; // Not a command
        }
    
        // Remove prefix and parse command
        const commandPart = chatMessage.slice(prefix.length).trim();
        const commandArgs = commandPart.split(' ');
        const commandName = commandArgs[0].toLowerCase();
    
        // Only capture location for teleport commands
        if (commandName !== 'tp' && commandName !== 'teleport') {
          return; // Not a teleport command
        }
    
        console.log('Teleport command detected, saving current location');
        console.log('Current player position:', { x: pog.positionX, y: pog.positionY, z: pog.positionZ });
    
        // Save the player's current location before they teleport
        const previousLocation = {
          x: pog.positionX,
          y: pog.positionY,
          z: pog.positionZ,
          timestamp: new Date().toISOString(),
        };
    
        console.log('Saving location:', previousLocation);
    
        // Check if back location already exists
        const backVar = await takaro.variable.variableControllerSearch({
          filters: {
            key: ['back_location'],
            gameServerId: [gameServerId],
            playerId: [pog.playerId],
            moduleId: [mod.moduleId],
          },
        });
    
        if (backVar.data.data.length > 0) {
          console.log('Updating existing back location variable');
          await takaro.variable.variableControllerUpdate(backVar.data.data[0].id, {
            value: JSON.stringify(previousLocation),
          });
        } else {
          console.log('Creating new back location variable');
          await takaro.variable.variableControllerCreate({
            key: 'back_location',
            value: JSON.stringify(previousLocation),
            gameServerId,
            moduleId: mod.moduleId,
            playerId: pog.playerId,
          });
        }
    
        console.log('Successfully saved back location');
      } catch (error) {
        console.error('Failed to capture pre-teleport location:', error);
      }
    }
    
    await main();

Permissions 1

Roles you can grant to decide who may use what.

  • BACK_TELEPORT_USE

    BACK_TELEPORT_USE