DiedTeleport

  • community
  • community-management
  • by Limon
  • Takaro main
  • all
Version
View export JSON

Allows players to use /died command to return to their last death location. Automatically captures death locations and provides teleportation back.

Configuration 1

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

SettingTypeDefaultDescription
deathLocationExpiration number 3600 How long (in seconds) death locations remain valid before expiring. Default: 1 hour (3600 seconds), Min: 1 minute, Max: 24 hours
Raw config schema
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "deathLocationExpiration": {
      "type": "number",
      "default": 3600,
      "minimum": 60,
      "maximum": 86400,
      "description": "How long (in seconds) death locations remain valid before expiring. Default: 1 hour (3600 seconds), Min: 1 minute, Max: 24 hours"
    }
  },
  "additionalProperties": false
}
Raw UI schema
{
  "deathLocationExpiration": {
    "ui:help": "Prevents abuse by automatically expiring old death locations. Players won't be able to teleport to deaths older than this duration."
  }
}

Commands 1

Chat commands players trigger in game.

  • died

    Teleports you back to your last death location

    Command source
    import { data, takaro, TakaroUserError } from '@takaro/helpers';
    
    async function main() {
        const { gameServerId, player, pog, module } = data;
        
        console.log(`Player ${player.name} requested teleport to death location`);
        
        try {
            // Get the death location
            const deathVar = await takaro.variable.variableControllerSearch({
                filters: {
                    key: ['death_location'],
                    gameServerId: [gameServerId],
                    playerId: [player.id],
                    moduleId: [module.moduleId]
                }
            });
    
            if (deathVar.data.data.length === 0) {
                throw new TakaroUserError('No death location found. You need to die at least once to use this command.');
            }
    
            const deathLocation = JSON.parse(deathVar.data.data[0].value);
            
            // Get expiration duration from module config
            const expirationDuration = module.userConfig?.deathLocationExpiration || 3600; // Default 1 hour
            
            // Check if the death location has expired
            if (deathLocation.timestamp) {
                const deathTime = new Date(deathLocation.timestamp);
                const currentTime = new Date();
                const elapsedSeconds = (currentTime - deathTime) / 1000;
                
                if (elapsedSeconds > expirationDuration) {
                    const expirationMinutes = Math.floor(expirationDuration / 60);
                    throw new TakaroUserError(`Your death location has expired. Death locations expire after ${expirationMinutes} minutes.`);
                }
                
                // Show remaining time
                const remainingSeconds = Math.floor(expirationDuration - elapsedSeconds);
                const remainingMinutes = Math.floor(remainingSeconds / 60);
                const remainingSecondsOnly = remainingSeconds % 60;
                
                console.log(`Death location is still valid for ${remainingMinutes}m ${remainingSecondsOnly}s`);
            }
    
            // Teleport the player
            await takaro.gameserver.gameServerControllerTeleportPlayer(gameServerId, player.id, {
                x: deathLocation.x,
                y: deathLocation.y,
                z: deathLocation.z,
                dimension: deathLocation.dimension
            });
    
            await pog.pm('Teleported to your death location!');
            
            console.log(`Player ${player.name} teleported to death location: ${JSON.stringify(deathLocation)}`);
            
        } catch (error) {
            if (error instanceof TakaroUserError) {
                throw error;
            }
            console.error('Error in died command:', error);
            throw new TakaroUserError('Failed to teleport to death location. Please try again.');
        }
    }
    
    await main();

Hooks 1

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

  • Death Location Capture

    Hook for player-death events

    Hook source
    import { data, takaro } from '@takaro/helpers';
    
    async function main() {
        const { gameServerId, eventData, player, module } = data;
        
        console.log('Player death event captured:', JSON.stringify(eventData, null, 2));
        
        if (!player) {
            console.log('No player data available in death event');
            return;
        }
    
        // Extract position from the correct location in eventData
        const position = eventData.position;
        
        if (!position || typeof position.x === 'undefined' || typeof position.y === 'undefined' || typeof position.z === 'undefined') {
            console.log('Death event missing position data:', position);
            return;
        }
    
        // Store the death location in variables
        const deathLocation = {
            x: position.x,
            y: position.y,
            z: position.z,
            dimension: null, // 7DTD doesn't seem to provide dimension info
            timestamp: new Date().toISOString()
        };
    
        try {
            // Try to find existing death location variable for this player
            const existingVar = await takaro.variable.variableControllerSearch({
                filters: {
                    key: ['death_location'],
                    gameServerId: [gameServerId],
                    playerId: [player.id],
                    moduleId: [module.moduleId]
                }
            });
    
            if (existingVar.data.data.length > 0) {
                // Update existing death location
                await takaro.variable.variableControllerUpdate(existingVar.data.data[0].id, {
                    value: JSON.stringify(deathLocation)
                });
            } else {
                // Create new death location variable
                await takaro.variable.variableControllerCreate({
                    key: 'death_location',
                    value: JSON.stringify(deathLocation),
                    gameServerId,
                    playerId: player.id,
                    moduleId: module.moduleId
                });
            }
    
            console.log(`Death location saved for player ${player.name}: ${JSON.stringify(deathLocation)}`);
        } catch (error) {
            console.error('Error saving death location:', error);
        }
    }
    
    await main();

Permissions 1

Roles you can grant to decide who may use what.

  • Use Died Teleport

    Allows the player to use the /died command to return to their death location