PLAYER_SELECTED_TEMPLATES = {} PLAYER_UNLOCKED_TEMPLATES = {} -- TODO: support refund AddGlobalCallback("OnPlayerConnected", function(player) if PLAYER_UNLOCKED_TEMPLATES[player:GetUserId()] ~= nil then return end PLAYER_SELECTED_TEMPLATES[player:GetUserId()] = BUILDER_BOT_TEMPLATES.Soldier PLAYER_UNLOCKED_TEMPLATES[player:GetUserId()] = {} end) local function buyTemplate(activator, templateName) local cost = BUILDER_BOT_TEMPLATES[templateName].Cost or 0 local cash = activator.m_nCurrency if cost > cash then return false end activator:RemoveCurrency(cost) PLAYER_UNLOCKED_TEMPLATES[activator:GetUserId()][templateName] = true return true end local function doesOwn(activator, templateName) local template = BUILDER_BOT_TEMPLATES[templateName] local owned = false if not template.Cost or template.Cost <= 0 then owned = true else owned = PLAYER_UNLOCKED_TEMPLATES[activator:GetUserId()][templateName] ~= nil end return owned end function ShowBotBlueprintSelection(activator, category) local menu = { timeout = 0, title = "CHOOSE BOT BLUEPRINT", itemsPerPage = 10, flags = MENUFLAG_BUTTON_EXITBACK, onSelect = function(_player, _index, name) local template = BUILDER_BOT_TEMPLATES[name] local owned = doesOwn(activator, name) if not owned then local success = buyTemplate(activator, name) if not success then return end end print(activator:GetPlayerName() .. " selected " .. name) PLAYER_SELECTED_TEMPLATES[activator:GetUserId()] = template ShowBotCategorySelection(activator) end, onCancel = function() ShowBotCategorySelection(activator) end, } local templateNameByTemplate = {} local sortedTemplates = {} for name, template in pairs(BUILDER_BOT_TEMPLATES) do if template.Category and template.Category == category then table.insert(sortedTemplates, template) templateNameByTemplate[template] = name end end table.sort(sortedTemplates, function(a, b) return a.BotTier < b.BotTier end) local selectedTemplate = PLAYER_SELECTED_TEMPLATES[activator:GetUserId()] for i, template in ipairs(sortedTemplates) do local disabled = false local displayName = template.Name local text = displayName local templateName = templateNameByTemplate[template] local owned = doesOwn(activator, templateName) if not owned then text = text .. " ($" .. template.Cost .. ")" end local selected = template == selectedTemplate if selected then disabled = true text = displayName .. " [SELECTED]" end if not owned then local cost = BUILDER_BOT_TEMPLATES[templateName].Cost or 0 local cash = activator.m_nCurrency if cost > cash then disabled = true end end menu[i] = { text = text, value = templateNameByTemplate[template], disabled = disabled, } end activator:DisplayMenu(menu) end function ShowBotCategorySelection(activator) local menu = { timeout = 0, title = "CHOOSE BOT CATEGORY", itemsPerPage = 10, flags = MENUFLAG_BUTTON_EXIT, onSelect = function(_player, _index, category) ShowBotBlueprintSelection(activator, category) end, } for i, category in ipairs(BUILDER_BOT_CATEGORIES_SORTED) do menu[i] = { text = category, value = category, disabled = false, } end activator:DisplayMenu(menu) end -- show menu when entering an upgrade station. in the future this should be a separate station for _, station in pairs(ents.FindAllByClass("func_upgradestation")) do station:AddCallback(ON_START_TOUCH, function(_, player) if not player:IsRealPlayer() then return end player:Print(PRINT_TARGET_CENTER, "Bot blueprint selection menu opened") ShowBotCategorySelection(player) end) station:AddCallback(ON_END_TOUCH, function(_, player) if not player:IsRealPlayer() then return end for _ = 1, 2 do player:HideMenu() end end) end