{
  "name": "arenaModule",
  "author": "Mad",
  "supportedGames": [
    "all"
  ],
  "takaroVersion": "v0.0.20",
  "versions": [
    {
      "tag": "latest",
      "description": "Provides an in-game Arena event system, teleporting players to a designated location to face challenges and earn rewards.\n\n  **Key Functionality:**\n\n  * **Arena Teleportation:** Players are teleported to a configurable arena location to participate in the event.\n  * **Event Management:** The module manages the arena event flow, potentially including timed challenges or waves of enemies (this would need to be implemented separately within the game server, this module just handles the teleportation and rewards).\n  * **Reward System:** Upon completion of the arena, players can receive both random and fixed rewards.\n        * `Random Items`: A configurable number of random items can be awarded from a predefined list.\n        * `Fixed Rewards`: Specific items are guaranteed to be given to players who complete the arena.\n  * **Permission Control:** Access to the arena event is controlled via a configurable permission.\n  * **Variable Tracking:** The module uses variables to track players' arena participation, ensuring they progress correctly and receive rewards.\n\n  **How to Use:**\n\n  1.  **Configuration:**\n      * `xlocation`, `ylocation`, `zlocation`:  Define the coordinates of the arena within the game world. `ylocation` can be set to -1 to teleport players to the highest block at the x,z coordinates.\n      * `randomitemnumber`:  Sets the number of random items to award.\n      * `randomitemlist`:  A list of possible items for the random rewards, including item names, amounts, and qualities.\n      * `fixedrewards`:  A list of items always awarded upon arena completion.\n  2.  **Permissions:** Assign the `ARENA_PERMISSION` to the player groups or individuals who should have access to the arena event (the trigger command is `arena` as seen in the code).\n  3.  **Game Server Integration:** This module *requires* corresponding setup within the 7 Days to Die game server to function correctly. This module handles player teleportation and reward distribution, but the actual arena challenges (e.g., spawning enemies, timed events) *must* be configured separately using server commands or mods.  The module uses the `th` command to teleport players in the background, but you may need to adjust this depending on your server setup.\n  4.  **Event Trigger:** Players initiate the arena event using the `/arena` command (or whatever trigger you set up).\n\n  **Important Considerations:**\n\n  * The module's functionality is limited to teleportation and reward distribution.  The actual arena gameplay must be configured independently on the game server.\n  * Coordinate configuration is critical for correct teleportation.\n  * Proper permission setup is essential to control access to the arena.\n  * The module interacts with the game server using commands; ensure compatibility with your server version and any other mods.\n  * Player death during the arena will cancel the event for that player and remove the tracking variable.\n",
      "configSchema": "{\"$schema\":\"http://json-schema.org/draft-07/schema#\",\"type\":\"object\",\"required\":[\"xlocation\",\"ylocation\",\"zlocation\"],\"additionalProperties\":false,\"properties\":{\"xlocation\":{\"title\":\"xlocation\",\"description\":\"East West Location\",\"default\":\"\",\"type\":\"string\",\"minLength\":1,\"maxLength\":6},\"ylocation\":{\"title\":\"ylocation\",\"description\":\"Height teleport location. -1 for the highest block\",\"default\":\"-1\",\"type\":\"string\",\"minLength\":1,\"maxLength\":3},\"zlocation\":{\"title\":\"zlocation\",\"description\":\"Set North South location. South is negative\",\"default\":\"\",\"type\":\"string\",\"minLength\":1,\"maxLength\":6},\"randomitemnumber\":{\"title\":\"randomitemnumber\",\"description\":\"Defines how many random items will be rewarded to the player, picked from randomitemlist config field.\\nThe quantities for each item picked is defined on the mentioned config field.\",\"default\":0,\"type\":\"number\"},\"randomitemlist\":{\"title\":\"Items\",\"description\":\"List of items that will be used to select a random reward for the vote, as many times as defined at randomitemnumber.\",\"x-component\":\"item\",\"type\":\"array\",\"uniqueItems\":true,\"items\":{\"type\":\"object\",\"title\":\"Item\",\"properties\":{\"item\":{\"type\":\"string\",\"title\":\"Item\"},\"amount\":{\"type\":\"number\",\"title\":\"Amount\"},\"quality\":{\"type\":\"string\",\"title\":\"Quality\"}}}},\"fixedrewards\":{\"title\":\"Items\",\"description\":\"All the items in this list will be given as a reward for completing the arena.\",\"x-component\":\"item\",\"type\":\"array\",\"uniqueItems\":true,\"items\":{\"type\":\"object\",\"title\":\"Item\",\"properties\":{\"item\":{\"type\":\"string\",\"title\":\"Item\"},\"amount\":{\"type\":\"number\",\"title\":\"Amount\"},\"quality\":{\"type\":\"string\",\"title\":\"Quality\"}}}}}}",
      "uiSchema": "{}",
      "commands": [
        {
          "name": "07 arena wait 85",
          "trigger": "arena",
          "helpText": "No help text available",
          "function": "import { takaro, data, checkPermission, TakaroUserError } from '@takaro/helpers';\nasync function main() {\n    const { player, gameServerId, module: mod, pog } = data;\n\n    // Check permission for the Arena command\n    if (!checkPermission(pog, 'ARENA_PERMISSION')) {\n        return;\n    };\n\n    const VARIABLE_KEY = 'arena'; // Key to look up\n\n    // Search for the variable with the specified key and filters\n    const arena = await takaro.variable.variableControllerSearch({\n        filters: {\n            key: [VARIABLE_KEY],\n            gameServerId: [gameServerId],\n            playerId: [data.player.id],\n        }\n    });\n\n    if (arena.data.data.length > 0) {\n        await takaro.gameserver.gameServerControllerExecuteCommand(gameServerId, {\n            command: `th \"${player.name}\" 20`,\n        });\n        await data.player.pm(`[02FEDC]Round 3[-]`);\n    };\n}\n\nawait main();",
          "arguments": []
        },
        {
          "name": "12 arena wait 195",
          "trigger": "arena",
          "helpText": "No help text available",
          "function": "import { takaro, data, TakaroUserError, checkPermission } from '@takaro/helpers';\n\nasync function main() {\n    const { pog, player, gameServerId } = data;\n    const { randomitemnumber, randomitemlist, fixedrewards } = data.module.userConfig;\n    const { steamId } = data.player;\n\n    if (!checkPermission(pog, 'ARENA_PERMISSION')) {\n        return;\n    };\n\n\n    const VARIABLE_KEY = 'arena'; // Key to look up\n\n    // Search for the variable with the specified key and filters\n    const arena = await takaro.variable.variableControllerSearch({\n        filters: {\n            key: [VARIABLE_KEY],\n            gameServerId: [gameServerId],\n            playerId: [data.player.id],\n        }\n    });\n\n    if (arena.data.data.length > 0) {\n        let actualrandomitemnumber;\n        if (randomitemnumber === 0) {\n            actualrandomitemnumber = 0;\n        } else {\n            actualrandomitemnumber = randomitemnumber > randomitemlist.length ? randomitemlist.length : randomitemnumber;\n        };\n\n\n        if (actualrandomitemnumber > 0) {\n            for (let i = 0; i < actualrandomitemnumber; i++) {\n                const randomIndex = Math.floor(Math.random() * randomitemlist.length);\n                const randomOption = randomitemlist.splice(randomIndex, 1)[0];\n                if (typeof randomOption === 'string') {\n                    console.log(`Giving random item ${i + 1}/${actualrandomitemnumber}:`, randomOption);\n                    await takaro.gameserver.gameServerControllerGiveItem(data.gameServerId, data.player.id, {\n                        name: randomOption,\n                        amount: 1,\n                        quality: '0',\n                    });\n                    await data.player.pm(`You received ${randomOption}! (item ${i + 1}/${actualrandomitemnumber + fixedrewards.length})`);\n                }\n                else {\n                    const item = (await takaro.item.itemControllerFindOne(randomOption.item)).data.data;\n                    console.log(`Giving random item ${i + 1}/${actualrandomitemnumber}:`, item.name);\n                    try {\n                        await takaro.gameserver.gameServerControllerGiveItem(data.gameServerId, data.player.id, {\n                            name: item.code,\n                            amount: randomOption.amount ?? '1',\n                            quality: randomOption.quality ?? '',\n                        });\n                    } catch (error) {\n                        await takaro.gameserver.gameServerControllerGiveItem(data.gameServerId, data.player.id, {\n                            name: item.code,\n                            amount: randomOption.amount ?? '1',\n                            quality: '',\n                        });\n                    }\n\n                    await data.player.pm(`You received ${randomOption.amount}x ${item.name}! (item ${i + 1}/${actualrandomitemnumber + fixedrewards.length})`);\n                }\n            }\n        }\n\n        if (fixedrewards.length > 0) {\n            let index = 1;\n            for (const each of fixedrewards) {\n                if (typeof each === 'string') {\n                    await takaro.gameserver.gameServerControllerGiveItem(data.gameServerId, data.player.id, {\n                        name: each,\n                        amount: 1,\n                        quality: '0',\n                    });\n                    await data.player.pm(`You received ${each}! (item ${index + actualrandomitemnumber}/${actualrandomitemnumber + fixedrewards.length})`);\n                }\n                else {\n                    const item = (await takaro.item.itemControllerFindOne(each.item)).data.data;\n                    try {\n                        await takaro.gameserver.gameServerControllerGiveItem(data.gameServerId, data.player.id, {\n                            name: item.code,\n                            amount: each.amount ?? 1,\n                            quality: each.quality ?? '',\n                        });\n                    } catch (error) {\n                        await takaro.gameserver.gameServerControllerGiveItem(data.gameServerId, data.player.id, {\n                            name: item.code,\n                            amount: each.amount ?? 1,\n                            quality: '',\n                        });\n                    }\n\n\n                    await data.player.pm(`You received ${each.amount}x ${item.name}! (item ${index + actualrandomitemnumber}/${actualrandomitemnumber + fixedrewards.length})`);\n                }\n                index++;\n            }\n        };\n    }\n\n    else { return };\n\n    const arenaVars = await takaro.variable.variableControllerSearch({\n        filters: {\n            playerId: [player.id],\n            gameServerId: [gameServerId],\n            key: ['arena'],\n        }\n    });\n\n    for (const variable of arenaVars.data.data) {\n        await takaro.variable.variableControllerDelete(variable.id);\n    }\n}\n\nawait main();",
          "arguments": []
        },
        {
          "name": "02 arena wait 2",
          "trigger": "arena",
          "helpText": "No help text available",
          "function": "import { takaro, data, checkPermission, TakaroUserError } from '@takaro/helpers';\nasync function main() {\n  const { player, gameServerId, module: mod, pog } = data;\n\n  // Check permission for the Arena command\n  if (!checkPermission(pog, 'ARENA_PERMISSION')) {\n    return;\n  };\n\n  await data.player.pm(`[02FEDC]${player.name}[-][-] do not teleport or die, you will not get your rewards. There is no way out except [FF595B]Death[-] or [AEE57A]Victory[-]`);\n};\n\nawait main();\n\n",
          "arguments": []
        },
        {
          "name": "03 arena wait 5",
          "trigger": "arena",
          "helpText": "No help text available",
          "function": "import { takaro, data, checkPermission, TakaroUserError } from '@takaro/helpers';\r\nasync function main() {\r\n  const { player, gameServerId, module: mod, pog } = data;\r\n\r\n  // Check permission for the Arena command\r\n  if (!checkPermission(pog, 'ARENA_PERMISSION')) {\r\n    return;\r\n  };\r\n\r\n  const VARIABLE_KEY = 'arena';\r\n\r\n  // Search for the variable with the specified key and filters\r\n  const arena = await takaro.variable.variableControllerSearch({\r\n    filters: {\r\n      key: [VARIABLE_KEY],\r\n      gameServerId: [gameServerId],\r\n      playerId: [data.player.id],\r\n    }\r\n  });\r\n\r\n  if (arena && arena.data.data.length > 0) {\r\n    await takaro.gameserver.gameServerControllerExecuteCommand(gameServerId, {\r\n      command: `th ${player.name} 20`,\r\n    });\r\n  }\r\n};\r\n\r\nawait main();",
          "arguments": []
        },
        {
          "name": "09 arena wait 125",
          "trigger": "arena",
          "helpText": "No help text available",
          "function": "import { takaro, data, checkPermission, TakaroUserError } from '@takaro/helpers';\nasync function main() {\n    const { player, gameServerId, module: mod, pog } = data;\n\n    // Check permission for the Arena command\n    if (!checkPermission(pog, 'ARENA_PERMISSION')) {\n        return;\n    };\n\n    const VARIABLE_KEY = 'arena'; // Key to look up\n\n    // Search for the variable with the specified key and filters\n    const arena = await takaro.variable.variableControllerSearch({\n        filters: {\n            key: [VARIABLE_KEY],\n            gameServerId: [gameServerId],\n            playerId: [data.player.id],\n        }\n    });\n\n    if (arena.data.data.length > 0) {\n        await takaro.gameserver.gameServerControllerExecuteCommand(gameServerId, {\n            command: `th \"${player.name}\" 20`,\n        });\n        await data.player.pm(`[02FEDC]Round 4[-]`);\n    };\n}\n\nawait main();",
          "arguments": []
        },
        {
          "name": "10 arena wait 135",
          "trigger": "arena",
          "helpText": "No help text available",
          "function": "import { takaro, data, checkPermission, TakaroUserError } from '@takaro/helpers';\nasync function main() {\n    const { player, gameServerId, module: mod, pog } = data;\n\n    // Check permission for the Arena command\n    if (!checkPermission(pog, 'ARENA_PERMISSION')) {\n        return;\n    }\n\n    const VARIABLE_KEY = 'arena'; // Key to look up\n\n    // Search for the variable with the specified key and filters\n    const arena = await takaro.variable.variableControllerSearch({\n        filters: {\n            key: [VARIABLE_KEY],\n            gameServerId: [gameServerId],\n            playerId: [data.player.id],\n        }\n    });\n\n    if (arena.data.data.length > 0) {\n        await takaro.gameserver.gameServerControllerExecuteCommand(gameServerId, {\n            command: `th \"${player.name}\" 20`,\n        });\n    }\n}\n\nawait main();",
          "arguments": []
        },
        {
          "name": "06 arena wait 55",
          "trigger": "arena",
          "helpText": "No help text available",
          "function": "import { takaro, data, checkPermission, TakaroUserError } from '@takaro/helpers';\nasync function main() {\n    const { player, gameServerId, module: mod, pog } = data;\n\n    // Check permission for the Arena command\n    if (!checkPermission(pog, 'ARENA_PERMISSION')) {\n        return;\n    }\n\n    const VARIABLE_KEY = 'arena'; // Key to look up\n\n    // Search for the variable with the specified key and filters\n    const arena = await takaro.variable.variableControllerSearch({\n        filters: {\n            key: [VARIABLE_KEY],\n            gameServerId: [gameServerId],\n            playerId: [data.player.id],\n        }\n    });\n\n    if (arena.data.data.length > 0) {\n        await takaro.gameserver.gameServerControllerExecuteCommand(gameServerId, {\n            command: `th \"${player.name}\" 20`,\n        });\n    }\n}\n\nawait main();",
          "arguments": []
        },
        {
          "name": "08 arena wait 95",
          "trigger": "arena",
          "helpText": "No help text available",
          "function": "import { takaro, data, checkPermission, TakaroUserError } from '@takaro/helpers';\nasync function main() {\n    const { player, gameServerId, module: mod, pog } = data;\n\n    // Check permission for the Arena command\n    if (!checkPermission(pog, 'ARENA_PERMISSION')) {\n        return;\n    }\n\n    const VARIABLE_KEY = 'arena'; // Key to look up\n\n    // Search for the variable with the specified key and filters\n    const arena = await takaro.variable.variableControllerSearch({\n        filters: {\n            key: [VARIABLE_KEY],\n            gameServerId: [gameServerId],\n            playerId: [data.player.id],\n        }\n    });\n\n    if (arena.data.data.length > 0) {\n        await takaro.gameserver.gameServerControllerExecuteCommand(gameServerId, {\n            command: `th \"${player.name}\" 20`,\n        });\n    }\n}\n\nawait main();",
          "arguments": []
        },
        {
          "name": "11 arena wait 165",
          "trigger": "arena",
          "helpText": "No help text available",
          "function": "import { takaro, data, checkPermission, TakaroUserError } from '@takaro/helpers';\nasync function main() {\n    const { player, gameServerId, module: mod, pog } = data;\n\n    // Check permission for the Arena command\n    if (!checkPermission(pog, 'ARENA_PERMISSION')) {\n        return;\n    };\n\n    const VARIABLE_KEY = 'arena'; // Key to look up\n\n    // Search for the variable with the specified key and filters\n    const arena = await takaro.variable.variableControllerSearch({\n        filters: {\n            key: [VARIABLE_KEY],\n            gameServerId: [gameServerId],\n            playerId: [data.player.id],\n        }\n    });\n\n    if (arena.data.data.length > 0) {\n        await takaro.gameserver.gameServerControllerExecuteCommand(gameServerId, {\n            command: `th \"${player.name}\" 20`,\n        });\n        await data.player.pm(`[edd521]You've made it to the end. You were victorious survivor![-]`);\n    };\n}\n\nawait main();",
          "arguments": []
        },
        {
          "name": "04 arena wait 15",
          "trigger": "arena",
          "helpText": "No help text available",
          "function": "import { takaro, data, checkPermission, TakaroUserError } from '@takaro/helpers';\nasync function main() {\n    const { player, gameServerId, module: mod, pog } = data;\n\n    // Check permission for the Arena command\n    if (!checkPermission(pog, 'ARENA_PERMISSION')) {\n        return;\n    }\n\n    const VARIABLE_KEY = 'arena'; // Key to look up\n\n    // Search for the variable with the specified key and filters\n    const arena = await takaro.variable.variableControllerSearch({\n        filters: {\n            key: [VARIABLE_KEY],\n            gameServerId: [gameServerId],\n            playerId: [data.player.id],\n        }\n    });\n\n    if (arena.data.data.length > 0) {\n        await takaro.gameserver.gameServerControllerExecuteCommand(gameServerId, {\n            command: `th \"${player.name}\" 20`,\n        });\n    }\n}\n\nawait main();",
          "arguments": []
        },
        {
          "name": "01 arena",
          "trigger": "arena",
          "helpText": "A huge arena battle for only the finest soldiers",
          "function": "import { data, checkPermission, TakaroUserError, takaro } from '@takaro/helpers';\r\n\r\nasync function main() {\r\n  const { player, pog, gameServerId } = data;\r\n\r\n  if (!checkPermission(pog, 'ARENA_PERMISSION')) {\r\n    throw new TakaroUserError('You do not have permission to use the Arena command.');\r\n  }\r\n\r\n  // Announce Arena\r\n  await takaro.gameserver.gameServerControllerSendMessage(data.gameServerId, {\r\n    message: `[FFFF33]${player.name} has started an Arena Battle for huge rewards![-]`,\r\n  });\r\n\r\n  const xlocation = Number(data.module.userConfig.xlocation); // Convert to number\r\n  const ylocation = Number(data.module.userConfig.ylocation); // Convert to number\r\n  const zlocation = Number(data.module.userConfig.zlocation); // Convert to number\r\n\r\n  // Teleport player to user-configured location\r\n  await takaro.gameserver.gameServerControllerTeleportPlayer(gameServerId, pog.playerId, {\r\n    x: xlocation,\r\n    y: ylocation,\r\n    z: zlocation,\r\n  });\r\n\r\n  const VARIABLE_KEY = 'arena';\r\n\r\n  // Check if the variable already exists\r\n  const existingVar = await takaro.variable.variableControllerSearch({\r\n    filters: {\r\n      key: [VARIABLE_KEY],\r\n      gameServerId: [gameServerId],\r\n      playerId: [player.id],\r\n      moduleId: [data.module.moduleId]\r\n    }\r\n  });\r\n\r\n  if (existingVar.data.data.length > 0) {\r\n    // Variable exists, update it\r\n    await takaro.variable.variableControllerUpdate(existingVar.data.data[0].id, {\r\n      value: '1'\r\n    });\r\n  } else {\r\n\r\n    // Variable doesn't exist, create it\r\n    await takaro.variable.variableControllerCreate({\r\n      key: VARIABLE_KEY,\r\n      value: '1',\r\n      gameServerId: gameServerId,\r\n      playerId: player.id,\r\n      moduleId: data.module.moduleId\r\n    });\r\n  }\r\n\r\n  // Assign role\r\n  await takaro.player.playerControllerRemoveRole(player.id, \"fd4415e1-ff99-4aca-8390-cd97d574f1fe\");\r\n\r\n  return { success: true };\r\n}\r\n\r\nawait main();",
          "arguments": []
        },
        {
          "name": "05 arena wait 45",
          "trigger": "arena",
          "helpText": "No help text available",
          "function": "import { takaro, data, checkPermission, TakaroUserError } from '@takaro/helpers';\nasync function main() {\n    const { player, gameServerId, module: mod, pog } = data;\n\n    // Check permission for the Arena command\n    if (!checkPermission(pog, 'ARENA_PERMISSION')) {\n        return;\n    };\n\n    const VARIABLE_KEY = 'arena'; // Key to look up\n\n    // Search for the variable with the specified key and filters\n    const arena = await takaro.variable.variableControllerSearch({\n        filters: {\n            key: [VARIABLE_KEY],\n            gameServerId: [gameServerId],\n            playerId: [data.player.id],\n        }\n    });\n\n    if (arena.data.data.length > 0) {\n        await takaro.gameserver.gameServerControllerExecuteCommand(gameServerId, {\n            command: `th \"${player.name}\" 20`,\n        });\n        await data.player.pm(`[02FEDC]Round 2[-]`);\n    };\n}\n\nawait main();",
          "arguments": []
        }
      ],
      "hooks": [
        {
          "name": "PlayerDied",
          "eventType": "player-death",
          "description": "Hook for player-death events",
          "regex": null,
          "function": "import { takaro, data } from '@takaro/helpers';\n\nasync function main() {\n    const { player, gameServerId, moduleId } = data;\n\n    const arenaVars = await takaro.variable.variableControllerSearch({\n        filters: {\n            playerId: [player.id],\n            gameServerId: [gameServerId],\n            //moduleId: [mod.moduleId],\n            key: ['arena'],\n        }\n    });\n\n    for (const variable of arenaVars.data.data) {\n        await takaro.variable.variableControllerDelete(variable.id);\n    }\n};\n\nawait main();\n\n\n\n\n\n"
        }
      ],
      "cronJobs": [],
      "functions": [],
      "permissions": [
        {
          "permission": "ARENA_PERMISSION",
          "friendlyName": "Arena Permission",
          "description": "Gives players access to the arena command",
          "canHaveCount": false
        }
      ]
    }
  ]
}