teleports
- builtin
- by Takaro
- Takaro >=0.0.1
- 7 days to die
- rust
- minecraft
Built-in modules ship with Takaro — no import needed.
A set of commands to allow players to set their own teleport points and teleport to them.
Configuration 2
Settings you fill in when installing the module on a server.
| Setting | Type | Default | Description |
|---|---|---|---|
timeout Timeout | number | 1000 | The time one has to wait before teleporting again. |
allowPublicTeleports | boolean | false | Players can create public teleports. |
Raw config schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"timeout": {
"title": "Timeout",
"description": "The time one has to wait before teleporting again.",
"x-component": "duration",
"type": "number",
"minimum": 0,
"default": 1000
},
"allowPublicTeleports": {
"type": "boolean",
"description": "Players can create public teleports.",
"default": false
}
},
"required": [],
"additionalProperties": false
} Raw UI schema
{
"timeout": {
"ui:widget": "duration"
}
} Commands 10
Chat commands players trigger in game.
-
teleport
Teleports to one of your set locations.
Argument Type Default Help tpstring — The location to teleport to. Command source
import { takaro, data, TakaroUserError } from '@takaro/helpers'; import { findTp } from './utils.js'; async function main() { const { pog, gameServerId, arguments: args, module: mod } = data; const ownedTeleportRes = await findTp(args.tp, pog.playerId); let teleports = ownedTeleportRes.data.data; if (mod.userConfig.allowPublicTeleports) { const publicTeleportRes = await findTp(args.tp, null, true); teleports = teleports.concat(publicTeleportRes.data.data); } if (teleports.length === 0) { throw new TakaroUserError(`Teleport ${args.tp} does not exist.`); } const timeout = mod.userConfig.timeout; if (timeout > 0) { const lastExecuted = await takaro.variable.variableControllerSearch({ filters: { key: ['lastExecuted'], gameServerId: [gameServerId], playerId: [pog.playerId], moduleId: [mod.moduleId], }, }); let lastExecutedRecord = lastExecuted.data.data[0]; if (lastExecutedRecord) { const lastExecutedTime = new Date(lastExecutedRecord.value); const now = new Date(); const diff = now.getTime() - lastExecutedTime.getTime(); if (diff < timeout) { throw new TakaroUserError('You cannot teleport yet. Please wait before trying again.'); } } else { const createRes = await takaro.variable.variableControllerCreate({ key: 'lastExecuted', gameServerId, playerId: pog.playerId, moduleId: mod.moduleId, value: new Date().toISOString(), }); lastExecutedRecord = createRes.data.data; } const teleport = JSON.parse(teleports[0].value); await takaro.gameserver.gameServerControllerTeleportPlayer(gameServerId, pog.playerId, { x: teleport.x, y: teleport.y, z: teleport.z, dimension: teleport.dimension, }); await data.player.pm(`Teleported to ${teleport.name}.`); if (timeout !== 0 && lastExecutedRecord) { await takaro.variable.variableControllerUpdate(lastExecutedRecord.id, { value: new Date().toISOString(), }); } return; } const teleport = JSON.parse(teleports[0].value); await takaro.gameserver.gameServerControllerTeleportPlayer(gameServerId, pog.playerId, { x: teleport.x, y: teleport.y, z: teleport.z, dimension: teleport.dimension, }); await data.player.pm(`Teleported to ${teleport.name}.`); } await main(); //# sourceMappingURL=teleport.js.map -
tplist
Lists all your set locations.
Command source
import { takaro, data } from '@takaro/helpers'; import { getVariableKey } from './utils.js'; async function main() { const { pog, gameServerId, module: mod } = data; const prefix = (await takaro.settings.settingsControllerGetOne('commandPrefix', gameServerId)).data.data.value; const ownedTeleports = (await takaro.variable.variableControllerSearch({ filters: { gameServerId: [gameServerId], playerId: [pog.playerId], moduleId: [mod.moduleId], }, search: { key: [getVariableKey(undefined, false)], }, sortBy: 'key', sortDirection: 'asc', })).data.data; const publicTeleports = (await takaro.variable.variableControllerSearch({ filters: { gameServerId: [gameServerId], moduleId: [mod.moduleId], }, search: { key: [getVariableKey(undefined, true)], }, sortBy: 'key', sortDirection: 'asc', })).data.data // Filter out public teleports that are owned by the player // Since we'll be showing them in the owned teleports list .filter((teleport) => { return teleport.playerId !== pog.playerId; }); const teleports = [...ownedTeleports, ...publicTeleports]; if (teleports.length === 0) { await data.player.pm(`You have no teleports available, use ${prefix}settp <name> to set one.`); return; } await data.player.pm(`You have ${teleports.length} teleport${teleports.length === 1 ? '' : 's'} available`); for (const rawTeleport of teleports) { const teleport = JSON.parse(rawTeleport.value); await data.player.pm(`${teleport.name}: (${teleport.x},${teleport.y},${teleport.z}) ${rawTeleport.key.startsWith('pub') ? '(public)' : ''}`); } } await main(); //# sourceMappingURL=tplist.js.map -
settp
Sets a location to teleport to.
Argument Type Default Help tpstring — The location name. Command source
import { takaro, data, checkPermission, TakaroUserError } from '@takaro/helpers'; import { getVariableKey, findTp } from './utils.js'; async function main() { const { pog, gameServerId, module: mod, arguments: args } = data; const prefix = (await takaro.settings.settingsControllerGetOne('commandPrefix', gameServerId)).data.data.value; const existingVariable = await findTp(args.tp, pog.playerId); if (existingVariable.data.data.length > 0) { throw new TakaroUserError(`Teleport ${args.tp} already exists, use ${prefix}deletetp ${args.tp} to delete it.`); } const hasPermission = checkPermission(pog, 'TELEPORTS_USE'); const allPlayerTeleports = await takaro.variable.variableControllerSearch({ search: { key: [getVariableKey(undefined), getVariableKey(undefined, true)], }, filters: { gameServerId: [gameServerId], playerId: [pog.playerId], moduleId: [mod.moduleId], }, }); if (allPlayerTeleports.data.data.length >= hasPermission.count) { throw new TakaroUserError(`You have reached the maximum number of teleports for your role, maximum allowed is ${hasPermission.count}`); } await takaro.variable.variableControllerCreate({ key: getVariableKey(args.tp), value: JSON.stringify({ name: args.tp, x: data.pog.positionX, y: data.pog.positionY, z: data.pog.positionZ, dimension: data.pog.dimension, }), gameServerId, moduleId: mod.moduleId, playerId: pog.playerId, }); await data.player.pm(`Teleport ${args.tp} set.`); } await main(); //# sourceMappingURL=settp.js.map -
deletetp
Deletes a location.
Argument Type Default Help tpstring — The location name. Command source
import { takaro, data, TakaroUserError } from '@takaro/helpers'; import { getVariableKey } from './utils.js'; async function main() { const { pog, gameServerId, arguments: args, module: mod } = data; const existingVariable = await takaro.variable.variableControllerSearch({ filters: { key: [getVariableKey(args.tp), getVariableKey(args.tp, true)], gameServerId: [gameServerId], playerId: [pog.playerId], moduleId: [mod.moduleId], }, }); if (existingVariable.data.data.length === 0) { throw new TakaroUserError(`Teleport ${args.tp} does not exist.`); } await takaro.variable.variableControllerDelete(existingVariable.data.data[0].id); await data.player.pm(`Teleport ${args.tp} deleted.`); } await main(); //# sourceMappingURL=deletetp.js.map -
setpublic
Sets a teleport to be public, allowing other players to teleport to it.
Argument Type Default Help tpstring — The location name. Command source
import { takaro, data, checkPermission, TakaroUserError } from '@takaro/helpers'; import { getVariableKey } from './utils.js'; async function main() { const { pog, gameServerId, module: mod, arguments: args } = data; const prefix = (await takaro.settings.settingsControllerGetOne('commandPrefix', gameServerId)).data.data.value; if (!mod.userConfig.allowPublicTeleports) { throw new TakaroUserError('Public teleports are disabled.'); } const hasPermission = checkPermission(pog, 'TELEPORTS_CREATE_PUBLIC'); const existingPublicTeleportsForPlayerRes = await takaro.variable.variableControllerSearch({ search: { key: ['pubtp_'], }, filters: { gameServerId: [gameServerId], playerId: [pog.playerId], moduleId: [mod.moduleId], }, }); if (existingPublicTeleportsForPlayerRes.data.data.length >= hasPermission.count) { throw new TakaroUserError(`You have reached the maximum number of public teleports for your role, maximum allowed is ${hasPermission.count}`); } const teleports = (await takaro.variable.variableControllerSearch({ filters: { gameServerId: [gameServerId], playerId: [pog.playerId], moduleId: [mod.moduleId], key: [getVariableKey(args.tp)], }, sortBy: 'key', sortDirection: 'asc', })).data.data; if (teleports.length === 0) { throw new TakaroUserError(`No teleport with name ${args.tp} found, use ${prefix}settp <name> to set one first.`); } const teleportRecord = teleports[0]; const teleport = JSON.parse(teleportRecord.value); await takaro.variable.variableControllerUpdate(teleportRecord.id, { key: getVariableKey(args.tp, true), value: JSON.stringify(teleport), }); await data.player.pm(`Teleport ${args.tp} is now public.`); } await main(); //# sourceMappingURL=setpublic.js.map -
setprivate
Sets a teleport to be private, only the teleport owner can teleport to it.
Argument Type Default Help tpstring — The location name. Command source
import { takaro, data, TakaroUserError } from '@takaro/helpers'; import { getVariableKey } from './utils.js'; async function main() { const { pog, gameServerId, arguments: args, module: mod } = data; const prefix = (await takaro.settings.settingsControllerGetOne('commandPrefix', gameServerId)).data.data; const teleportRes = await takaro.variable.variableControllerSearch({ filters: { gameServerId: [gameServerId], playerId: [pog.playerId], key: [getVariableKey(args.tp, true)], moduleId: [mod.moduleId], }, sortBy: 'key', sortDirection: 'asc', }); const teleports = teleportRes.data.data; if (teleports.length === 0) { throw new TakaroUserError(`No public teleport with name ${args.tp} found, use ${prefix}settp <name> to set one first.`); } const teleportRecord = teleports[0]; const teleport = JSON.parse(teleportRecord.value); await takaro.variable.variableControllerUpdate(teleportRecord.id, { key: getVariableKey(args.tp), value: JSON.stringify(teleport), }); await data.player.pm(`Teleport ${args.tp} is now private.`); } await main(); //# sourceMappingURL=setprivate.js.map -
setwaypoint
Creates a new waypoint.
Argument Type Default Help waypointstring — The location name. Command source
import { takaro, data, TakaroUserError } from '@takaro/helpers'; import { getWaypointName, waypointReconciler } from './utils.js'; async function main() { const { pog, gameServerId, arguments: args, module: mod } = data; try { await takaro.variable.variableControllerCreate({ moduleId: mod.moduleId, gameServerId, key: getWaypointName(args.waypoint), value: JSON.stringify({ x: pog.positionX, y: pog.positionY, z: pog.positionZ, dimension: pog.dimension, }), }); } catch (error) { if (error.message === 'Request failed with status code 409') { throw new TakaroUserError(`Waypoint ${args.waypoint} already exists.`); } throw error; } await waypointReconciler(); await pog.pm(`Waypoint ${args.waypoint} set.`); } await main(); //# sourceMappingURL=setwaypoint.js.map -
deletewaypoint
Deletes a waypoint.
Argument Type Default Help waypointstring — The location name. Command source
import { takaro, data, TakaroUserError } from '@takaro/helpers'; import { getWaypointName, waypointReconciler } from './utils.js'; async function main() { const { pog, gameServerId, arguments: args, module: mod } = data; const variable = await takaro.variable.variableControllerSearch({ filters: { key: [getWaypointName(args.waypoint)], gameServerId: [gameServerId], moduleId: [mod.moduleId], }, }); if (!variable.data.data.length) { throw new TakaroUserError(`Waypoint ${args.waypoint} doesn't exist.`); } await takaro.variable.variableControllerDelete(variable.data.data[0].id); await waypointReconciler(); await pog.pm(`Waypoint ${args.waypoint} deleted.`); } await main(); //# sourceMappingURL=deletewaypoint.js.map -
listwaypoints
Lists all waypoints.
Command source
import { data, checkPermission } from '@takaro/helpers'; import { ensureWaypointsModule } from './utils.js'; async function main() { const { pog, gameServerId } = data; const { waypointsDefinition } = await ensureWaypointsModule(); const allWaypoints = waypointsDefinition.latestVersion.commands; const waypointsWithPermission = allWaypoints .filter((waypoint) => checkPermission(pog, `WAYPOINTS_USE_${waypoint.trigger.toUpperCase()}_${gameServerId}`)) .sort((a, b) => a.trigger.localeCompare(b.trigger)); if (!waypointsWithPermission.length) { await pog.pm('There are no waypoints available.'); return; } await pog.pm(`Available waypoints: ${waypointsWithPermission.map((waypoint) => waypoint.trigger).join(', ')}`); } await main(); //# sourceMappingURL=listwaypoints.js.map -
teleportwaypoint
Placeholder command, this will not be used directly. The module will install aliases for this command corresponding to the waypoint names.
Command source
import { takaro, data, TakaroUserError, checkPermission } from '@takaro/helpers'; function getWaypointName(name) { return `waypoint ${name}`; } async function main() { const { pog, gameServerId, trigger, module, itemId } = data; const triggeredCommand = module.version.commands.find((command) => command.id === itemId); if (!triggeredCommand) { throw new Error('Waypoint not found.'); } if (!triggeredCommand.name.includes(`server ${gameServerId}`)) { console.log(`Waypoint ${trigger} is not for this server.`); return; } if (!checkPermission(pog, `WAYPOINTS_USE_${trigger.toUpperCase()}_${gameServerId}`)) { throw new TakaroUserError(`You are not allowed to use the waypoint ${trigger}.`); } const teleportsModule = (await takaro.module.moduleControllerSearch({ filters: { builtin: ['teleports'], }, })).data.data[0]; const variable = await takaro.variable.variableControllerSearch({ filters: { key: [getWaypointName(trigger)], gameServerId: [gameServerId], moduleId: [teleportsModule.id], }, }); if (variable.data.data.length === 0) { throw new TakaroUserError(`Waypoint ${trigger} does not exist.`); } const waypoint = JSON.parse(variable.data.data[0].value); await takaro.gameserver.gameServerControllerTeleportPlayer(gameServerId, pog.playerId, { x: waypoint.x, y: waypoint.y, z: waypoint.z, dimension: waypoint.dimension, }); await pog.pm(`Teleported to waypoint ${trigger}.`); } await main(); //# sourceMappingURL=teleportwaypoint.js.map
Cron jobs 1
Work the module runs on a schedule.
-
Waypoint reconciler
Cron job source
import { waypointReconciler } from './utils.js'; async function main() { await waypointReconciler(); } await main(); //# sourceMappingURL=Waypoint%20reconciler.js.map
Functions 1
Shared helpers the module's commands, hooks and cron jobs import.
-
utils
Function source
import { takaro, data } from '@takaro/helpers'; export function getVariableKey(tpName, pub = false) { if (pub && tpName) { return `pubtp_${tpName}`; } if (pub && !tpName) { return 'pubtp_'; } if (tpName) { return `tp_${tpName}`; } return 'tp_'; } export async function findTp(tpName, playerId, pub = false) { const { gameServerId, module: mod } = data; if (pub) { return takaro.variable.variableControllerSearch({ filters: { key: [getVariableKey(tpName, true)], gameServerId: [gameServerId], playerId: [playerId].filter(Boolean), moduleId: [mod.moduleId], }, sortBy: 'key', sortDirection: 'asc', }); } return takaro.variable.variableControllerSearch({ filters: { key: [getVariableKey(tpName)], gameServerId: [gameServerId], playerId: [playerId].filter(Boolean), moduleId: [mod.moduleId], }, sortBy: 'key', sortDirection: 'asc', }); } export async function ensureWaypointsModule() { const { gameServerId } = data; let waypointsDefinition = (await takaro.module.moduleControllerSearch({ filters: { name: ['Waypoints'], }, })).data.data[0]; if (!waypointsDefinition) { console.log('Waypoints module definition not found, creating it.'); waypointsDefinition = (await takaro.module.moduleControllerCreate({ name: 'Waypoints', })).data.data; } let waypointsInstallation = (await takaro.module.moduleInstallationsControllerGetInstalledModules({ filters: { gameserverId: [gameServerId] }, })).data.data.find((module) => module.module.name === 'Waypoints'); if (!waypointsInstallation) { console.log('Waypoints installation not found, installing it.'); waypointsInstallation = (await takaro.module.moduleInstallationsControllerInstallModule({ gameServerId, versionId: waypointsDefinition.latestVersion.id, })).data.data; } return { waypointsInstallation, waypointsDefinition }; } export function getWaypointName(name) { return `waypoint ${name}`; } export function getWaypointId(varName) { const split = varName.split(' ')[1]; if (split) { return split; } return varName; } /** * This function is responsible to read all the configured waypoints (vars) * and then ensuring that the waypoints module has the correct config */ export async function waypointReconciler() { console.log('Reconciling waypoints'); const { waypointsInstallation, waypointsDefinition } = await ensureWaypointsModule(); const { gameServerId, module: mod } = data; // Get all the installed waypoints const waypointVars = (await takaro.variable.variableControllerSearch({ filters: { moduleId: [mod.moduleId], gameServerId: [gameServerId], }, search: { key: [getWaypointName('')], }, })).data.data; const waypointsInModule = waypointsDefinition.latestVersion.commands; // Check if any waypoints are missing in module const missingWaypoints = waypointVars.filter((waypointVar) => { const existingWaypointsForServer = waypointsInModule.filter((waypoint) => waypoint.name.includes(gameServerId)); return !existingWaypointsForServer.some((waypoint) => waypoint.trigger === getWaypointId(waypointVar.key)); }); // Check if there are waypoints too many in module compared to our vars const toDeleteWaypoints = waypointsInModule.filter((waypoint) => { // We ignore any commands that are not for this game server if (!waypoint.name.includes(gameServerId)) { return false; } return !waypointVars.some((waypointVar) => getWaypointId(waypointVar.key) === waypoint.trigger); }); if (!missingWaypoints.length && !toDeleteWaypoints.length) { // No changes in waypoints, exit return; } console.log('Missing waypoints:', missingWaypoints.map((waypoint) => waypoint.key)); console.log('To delete waypoints:', toDeleteWaypoints.map((waypoint) => waypoint.trigger)); // Fetch the teleporting code template const teleportCommand = await takaro.command.commandControllerSearch({ filters: { moduleId: [mod.moduleId], name: ['teleportwaypoint'], }, }); // Edit the module accordingly await Promise.all([ ...missingWaypoints.map((waypoint) => { return takaro.command.commandControllerCreate({ name: `waypoint ${getWaypointId(waypoint.key)} server ${gameServerId}`, trigger: getWaypointId(waypoint.key), helpText: `Teleport to waypoint ${getWaypointId(waypoint.key)}.`, function: teleportCommand.data.data[0].function.code, versionId: waypointsInstallation.versionId, }); }), ...toDeleteWaypoints.map((waypointVar) => { return takaro.command.commandControllerRemove(waypointVar.id); }), ]); // Update permissions const existingPermissions = waypointsDefinition.latestVersion.permissions || []; const permissionInputDTOs = existingPermissions.map((permission) => ({ permission: permission.permission, description: permission.description, friendlyName: permission.friendlyName, canHaveCount: permission.canHaveCount, })); // We need to filter out the permissions we deleted in the above lines const filteredPermissionsInputs = permissionInputDTOs.filter((permission) => { return !toDeleteWaypoints.some((waypoint) => permission.permission === `WAYPOINTS_USE_${waypoint.trigger.toUpperCase()}_${gameServerId}`); }); const gameServer = (await takaro.gameserver.gameServerControllerGetOne(gameServerId)).data.data; await takaro.module.moduleControllerUpdate(waypointsInstallation.moduleId, { latestVersion: { permissions: [ ...filteredPermissionsInputs, ...missingWaypoints.map((waypoint) => ({ permission: `WAYPOINTS_USE_${getWaypointId(waypoint.key).toUpperCase()}_${gameServerId}`, description: `Use the waypoint ${getWaypointId(waypoint.key)} on ${gameServer.name}.`, friendlyName: `Use waypoint ${getWaypointId(waypoint.key)} on ${gameServer.name}`, canHaveCount: false, })), ], }, }); } //# sourceMappingURL=utils.js.map
Permissions 3
Roles you can grant to decide who may use what.
-
Create Public Teleports
Allows the player to create public teleports.
-
Use Teleports
Allows the player to use teleports modules.
-
Manage waypoints
Allows creating, deleting, and managing waypoints.