<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>TK Server easy script</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            padding: 20px;
            border: 1px solid #ccc;
            border-radius: 10px;
            background-color: #d3d3d3; /* 背景を灰色に変更 */
        }
        h1 {
            text-align: center;
        }
        label {
            display: block;
            margin: 10px 0 5px;
        }
        input[type="text"], input[type="number"] {
            width: 100%;
            padding: 8px;
            margin-bottom: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
        }
        button {
            padding: 10px 15px;
            border: none;
            border-radius: 5px;
            background-color: #28a745;
            color: white;
            cursor: pointer;
        }
        button:hover {
            background-color: #218838;
        }
        pre {
            background-color: #f8f9fa;
            padding: 15px;
            border: 1px solid #dee2e6;
            border-radius: 5px;
            white-space: pre-wrap;
            word-wrap: break-word;
        }
    </style>
</head>
<body>
    <h1>scripting tools</h1>
    <h1>made by TK</h1>
    <p><a href="https://gameguardian.net/forum/topic/17447-lua-scripting/#google_vignette" target="_blank">スクリプト作り方 - PRONTO編</a></p>
    <form id="scriptForm">
        <label for="menu_count">メニュー数:</label>
        <input type="number" id="menu_count" name="menu_count" min="1" onchange="generateMenuForms()" required>
        <div id="menuForms"></div>
        <button type="button" onclick="generateScript()">生成</button>
    </form>
    <h2>script:</h2>
    <pre id="generatedScript"></pre>
    <button id="downloadButton" style="display:none;" onclick="downloadScript()">Download</button>
    <h5>2次配布,転売厳禁</h5>
    <p><a href="https://discord.gg/SUJmgPeQR6" target="_blank">support Server discord</a></p>
    <script>
        function generateMenuForms() {
            const menuCount = document.getElementById('menu_count').value;
            const menuFormsContainer = document.getElementById('menuForms');
            menuFormsContainer.innerHTML = '';

            for (let i = 1; i <= menuCount; i++) {
                const menuDiv = document.createElement('div');
                menuDiv.innerHTML = `
                    <label for="menuName${i}">メニュー名${i}:</label>
                    <input type="text" id="menuName${i}" placeholder="メニュー名を入力" required>
                    
                    <label for="cheatCount${i}">チート数:</label>
                    <input type="number" id="cheatCount${i}" name="cheatCount${i}" min="1" value="1" onchange="generateCheatForms(${i})" required>

                    <div id="cheatForms${i}"></div>
                `;
                menuFormsContainer.appendChild(menuDiv);
                generateCheatForms(i);
            }
        }

        function generateCheatForms(menuIndex) {
            const cheatCount = document.getElementById(`cheatCount${menuIndex}`).value;
            const container = document.getElementById(`cheatForms${menuIndex}`);
            container.innerHTML = '';

            for (let j = 1; j <= cheatCount; j++) {
                const cheatDiv = document.createElement('div');
                cheatDiv.className = 'cheat-form';
                cheatDiv.innerHTML = `
                    <label for="cheatName${menuIndex}_${j}">チート${j} 名前:</label>
                    <input type="text" id="cheatName${menuIndex}_${j}" placeholder="チート名を入力" required>

                    <label for="onCode${menuIndex}_${j}">ONコード:</label>
                    <input type="text" id="onCode${menuIndex}_${j}" placeholder="ONコードを入力" required>

                    <label for="offCode${menuIndex}_${j}">OFFコード:</label>
                    <input type="text" id="offCode${menuIndex}_${j}" placeholder="OFFコードを入力" required>
                `;
                container.appendChild(cheatDiv);
            }
        }

        function generateScript() {
            const menuCount = document.getElementById('menu_count').value;

            let lua_script = `gg.clearResults()\ngg.alert("easy script \\nmade by TK", "start")\n\nfunction Main()\n    local menu = gg.choice({\n`;

            for (let i = 1; i <= menuCount; i++) {
                const menuName = document.getElementById(`menuName${i}`).value;
                lua_script += `        "${menuName}",\n`;
            }

            lua_script += `        "終了",\n    }, nil, "TK easy script")\n\n    if menu == nil then\n        return\n    end\n`;

            for (let i = 1; i <= menuCount; i++) {
                lua_script += `    if menu == ${i} then AAA${i}() end\n`;
            }

            lua_script += `    if menu == ${Number(menuCount) + 1} then exit() end\nend\n\n`;

            for (let i = 1; i <= menuCount; i++) {
                lua_script += `function AAA${i}()\n`;
                lua_script += `    local A${i} = gg.choice({\n`;

                const cheatCount = document.getElementById(`cheatCount${i}`).value;
                for (let j = 1; j <= cheatCount; j++) {
                    const cheatName = document.getElementById(`cheatName${i}_${j}`).value;
                    lua_script += `        "${cheatName}",\n`;
                }

                lua_script += `        "戻る",\n    }, nil, "TK easy script")\n\n    if A${i} == nil then return end\n`;

                for (let j = 1; j <= cheatCount; j++) {
                    lua_script += `    if A${i} == ${j} then B${i}_${j}() end\n`;
                }

                lua_script += `    if A${i} == ${Number(cheatCount) + 1} then Main() end\nend\n`;

                for (let j = 1; j <= cheatCount; j++) {
                    const onCode = document.getElementById(`onCode${i}_${j}`).value;
                    const offCode = document.getElementById(`offCode${i}_${j}`).value;

                    lua_script += `function B${i}_${j}()\n`;
                    lua_script += `    if toggle_${i}_${j} then\n`;
                    lua_script += `        gg.clearResults()\n${offCode}\n`;
                    lua_script += `    else\n`;
                    lua_script += `        gg.clearResults()\n${onCode}\n`;
                    lua_script += `    end\n`;
                    lua_script += `    toggle_${i}_${j} = not toggle_${i}_${j}\nend\n`;
                }
            }

            lua_script += `\nfunction exit()\n    gg.toast("made by TK")\n    gg.clearResults()\n    os.exit()\nend\n`;
            lua_script += `while true do\n    if gg.isVisible() then\n        gg.setVisible(false)\n        Main()\n    end\n    gg.sleep(10)\nend`;

            document.getElementById('generatedScript').textContent = lua_script;
            document.getElementById('downloadButton').style.display = 'block';
        }

        function downloadScript() {
            const scriptContent = document.getElementById('generatedScript').textContent;
            const blob = new Blob([scriptContent], { type: 'text/plain' });
            const url = URL.createObjectURL(blob);
            const a = document.createElement('a');
            a.href = url;
            a.download = 'generated_script.lua';
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
            URL.revokeObjectURL(url);
        }
    </script>
</body>
</html>