0% found this document useful (0 votes)
8 views11 pages

Cooking Assistant GUI Script

The document outlines a Lua script for a cooking assistant interface in a game, utilizing services like Players and TweenService. It includes functions for loading recipes from Pastebin, managing GUI elements, and updating food and rarity based on player interactions. The script also handles the display of ingredients and toggles for enabling or disabling the assistant feature.

Uploaded by

clentinho89
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views11 pages

Cooking Assistant GUI Script

The document outlines a Lua script for a cooking assistant interface in a game, utilizing services like Players and TweenService. It includes functions for loading recipes from Pastebin, managing GUI elements, and updating food and rarity based on player interactions. The script also handles the display of ingredients and toggles for enabling or disabling the assistant feature.

Uploaded by

clentinho89
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

-- Serviços

local Players = game:GetService("Players")


local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local CoreGui = game:GetService("CoreGui")

local player = [Link]

-- Função para pegar CoreGui ou PlayerGui (fallback)


local function getGui()
local success, result = pcall(function()
return CoreGui
end)
if success and result then
return result
else
return player:WaitForChild("PlayerGui")
end
end

local parentGui = getGui()

-- Carregar receitas via Pastebin com proteção


local success, recipes = pcall(function()
return loadstring(game:HttpGet("[Link]
end)

if not success or type(recipes) ~= "table" then


error("❌ Falha ao carregar receitas do Pastebin.")
end

-- Cores para raridades


local rarityColors = {
["Common"] = [Link](155, 155, 155),
["Uncommon"] = [Link](85, 255, 85),
["Rare"] = [Link](85, 170, 255),
["Legendary"] = [Link](255, 170, 0),
["Mythical"] = [Link](255, 85, 255),
["Divine"] = [Link](255, 255, 85),
["Prismatic"] = [Link](170, 255, 255)
}

-- Variáveis globais
local isEnabled = false
local currentFood = nil -- vai setar pelo porco
local currentRarity = nil -- vai setar automaticamente
local currentCraving = "Aguardando..."
local gui = nil
local monitorConnection = nil

-- Destruir GUI antiga (se houver)


local function destroyExistingGui()
if gui then
gui:Destroy()
gui = nil
end
if monitorConnection then
monitorConnection:Disconnect()
monitorConnection = nil
end

-- Limpar GUIs antigas também


local oldGuis = {}
pcall(function()
for _, child in pairs(CoreGui:GetChildren()) do
if [Link] == "CookingInterface" then
[Link](oldGuis, child)
end
end
end)
pcall(function()
for _, child in pairs([Link]:GetChildren()) do
if [Link] == "CookingInterface" then
[Link](oldGuis, child)
end
end
end)
for _, oldGui in pairs(oldGuis) do
oldGui:Destroy()
end
end

-- Pegar texto do porco (craving) no workspace (compatível)


local function getCravingText()
local success, result = pcall(function()
local path = {
"Interaction",
"UpdateItems",
"CookingEvent",
"CookingEventModel",
"PigChefFolder",
"PigChef",
"Cravings",
"CravingThoughtBubblePart",
"CravingBillboard",
"BG",
"CravingTextLabel"
}
local current = workspace
for _, childName in pairs(path) do
current = current:FindFirstChild(childName)
if not current then
return nil
end
end
if current and current:IsA("TextLabel") then
local text = [Link]
local extracted = [Link](text, ">([^<]+)<") or [Link](text,
"([%w%s]+)")
return extracted
end
return nil
end)
if success and result then
return result
else
return nil
end
end

-- Atualizar comida e raridade de acordo com o que o porco pediu


local function updateCurrentFoodAndRarity(cravingText)
if not cravingText then return end
-- Verifica se a comida existe na tabela de receitas
for foodName, rarities in pairs(recipes) do
-- O texto do porco geralmente tem o nome da comida, então verifica se o
texto contém o nome da comida (case insensitive)
if [Link]([Link](cravingText), [Link](foodName)) then
currentFood = foodName
-- Escolher a raridade com mais chances (ex: prismatic se tiver, senão
legendary, etc)
-- Prioridade para raridades mais raras para mostrar melhor a receita
local rarityOrder = {"Prismatic", "Divine", "Legendary", "Mythical",
"Rare", "Uncommon", "Common"}
for _, rarity in ipairs(rarityOrder) do
if rarities[rarity] then
currentRarity = rarity
break
end
end
return
end
end
-- Se não encontrou, zera
currentFood = nil
currentRarity = nil
end

-- Criar interface
local function createInterface()
destroyExistingGui()

gui = [Link]("ScreenGui")
[Link] = "CookingInterface"
[Link] = false
[Link] = parentGui

pcall(function()
[Link] = true
end)

local mainFrame = [Link]("Frame")


[Link] = "MainFrame"
[Link] = [Link](0, 320, 0, 420)
[Link] = [Link](0, 50, 0, 50)
mainFrame.BackgroundColor3 = [Link](45, 45, 45)
[Link] = 0
[Link] = true
[Link] = true
[Link] = gui

local corner = [Link]("UICorner")


[Link] = [Link](0, 15)
[Link] = mainFrame

-- Título
local titleLabel = [Link]("TextLabel")
[Link] = "TitleLabel"
[Link] = [Link](1, -20, 0, 30)
[Link] = [Link](0, 10, 0, 5)
[Link] = 1
[Link] = "🍳 Cooking Assistant"
titleLabel.TextColor3 = [Link](255, 255, 255)
[Link] = true
[Link] = [Link]
[Link] = mainFrame

-- Label do que o porco está pedindo


local cravingLabel = [Link]("TextLabel")
[Link] = "CravingLabel"
[Link] = [Link](1, -20, 0, 50)
[Link] = [Link](0, 10, 0, 40)
cravingLabel.BackgroundColor3 = [Link](35, 35, 35)
[Link] = 0
[Link] = currentCraving
cravingLabel.TextColor3 = [Link](255, 255, 255)
[Link] = true
[Link] = [Link]
[Link] = mainFrame

local cravingCorner = [Link]("UICorner")


[Link] = [Link](0, 8)
[Link] = cravingLabel

-- Dropdown para comidas


local foodFrame = [Link]("Frame")
[Link] = "FoodFrame"
[Link] = [Link](1, -20, 0, 40)
[Link] = [Link](0, 10, 0, 100)
foodFrame.BackgroundColor3 = [Link](35, 35, 35)
[Link] = 0
[Link] = mainFrame

local foodCorner = [Link]("UICorner")


[Link] = [Link](0, 8)
[Link] = foodFrame

local foodButton = [Link]("TextButton")


[Link] = "FoodButton"
[Link] = [Link](1, 0, 1, 0)
[Link] = [Link](0, 0, 0, 0)
[Link] = 1
[Link] = "Selecione a comida ▼"
foodButton.TextColor3 = [Link](255, 255, 255)
[Link] = true
[Link] = [Link]
[Link] = foodFrame

-- Dropdown para raridades


local rarityFrame = [Link]("Frame")
[Link] = "RarityFrame"
[Link] = [Link](1, -20, 0, 40)
[Link] = [Link](0, 10, 0, 150)
rarityFrame.BackgroundColor3 = [Link](35, 35, 35)
[Link] = 0
[Link] = mainFrame
local rarityCorner = [Link]("UICorner")
[Link] = [Link](0, 8)
[Link] = rarityFrame

local rarityButton = [Link]("TextButton")


[Link] = "RarityButton"
[Link] = [Link](1, 0, 1, 0)
[Link] = [Link](0, 0, 0, 0)
[Link] = 1
[Link] = "Selecione a raridade ▼"
rarityButton.TextColor3 = [Link](255, 255, 255)
[Link] = true
[Link] = [Link]
[Link] = rarityFrame

-- Frame para mostrar ingredientes


local ingredientsFrame = [Link]("Frame")
[Link] = "IngredientsFrame"
[Link] = [Link](1, -20, 0, 100)
[Link] = [Link](0, 10, 0, 200)
ingredientsFrame.BackgroundColor3 = [Link](35, 35, 35)
[Link] = 0
[Link] = mainFrame

local ingredientsCorner = [Link]("UICorner")


[Link] = [Link](0, 8)
[Link] = ingredientsFrame

local ingredientsLabel = [Link]("TextLabel")


[Link] = "IngredientsLabel"
[Link] = [Link](1, -10, 1, -10)
[Link] = [Link](0, 5, 0, 5)
[Link] = 1
[Link] = "Aguardando seleção..."
ingredientsLabel.TextColor3 = [Link](255, 255, 255)
[Link] = true
[Link] = [Link]
[Link] = true
[Link] = ingredientsFrame

-- Botão ON/OFF
local toggleFrame = [Link]("Frame")
[Link] = "ToggleFrame"
[Link] = [Link](1, -20, 0, 50)
[Link] = [Link](0, 10, 0, 310)
toggleFrame.BackgroundColor3 = [Link](200, 50, 50)
[Link] = 0
[Link] = mainFrame

local toggleCorner = [Link]("UICorner")


[Link] = [Link](0, 25)
[Link] = toggleFrame

local toggleButton = [Link]("TextButton")


[Link] = "ToggleButton"
[Link] = [Link](1, 0, 1, 0)
[Link] = [Link](0, 0, 0, 0)
[Link] = 1
[Link] = "OFF"
toggleButton.TextColor3 = [Link](255, 255, 255)
[Link] = true
[Link] = [Link]
[Link] = toggleFrame

-- Botão fechar
local closeButton = [Link]("TextButton")
[Link] = "CloseButton"
[Link] = [Link](0, 30, 0, 30)
[Link] = [Link](1, -35, 0, 5)
closeButton.BackgroundColor3 = [Link](255, 50, 50)
[Link] = 0
[Link] = "✕"
closeButton.TextColor3 = [Link](255, 255, 255)
[Link] = true
[Link] = [Link]
[Link] = mainFrame

local closeCorner = [Link]("UICorner")


[Link] = [Link](0, 15)
[Link] = closeButton

-- Atualizar ingredientes mostrado


local function updateIngredients()
if currentFood and currentRarity and recipes[currentFood] and
recipes[currentFood][currentRarity] then
local ingredients = recipes[currentFood][currentRarity]
if #ingredients > 0 then
[Link] = ingredients[1]
else
[Link] = "Nenhuma receita encontrada"
end
else
[Link] = "Aguardando seleção..."
end
end

-- Atualizar texto e cor do toggle ON/OFF


local function updateToggle()
if isEnabled then
toggleFrame.BackgroundColor3 = [Link](50, 200, 50)
[Link] = "ON"
else
toggleFrame.BackgroundColor3 = [Link](200, 50, 50)
[Link] = "OFF"
end
end

-- Criar dropdown comida


local function createFoodDropdown()
local dropdown = [Link]("Frame")
[Link] = "FoodDropdown"
[Link] = [Link](1, 0, 0, 200)
[Link] = [Link](0, 0, 1, 5)
dropdown.BackgroundColor3 = [Link](25, 25, 25)
[Link] = 1
dropdown.BorderColor3 = [Link](100, 100, 100)
[Link] = false
[Link] = 10
[Link] = foodFrame

local dropdownCorner = [Link]("UICorner")


[Link] = [Link](0, 8)
[Link] = dropdown

local scrollFrame = [Link]("ScrollingFrame")


[Link] = "ScrollFrame"
[Link] = [Link](1, -10, 1, -10)
[Link] = [Link](0, 5, 0, 5)
[Link] = 1
[Link] = 6
scrollFrame.ScrollBarImageColor3 = [Link](100, 100, 100)
[Link] = dropdown

local layout = [Link]("UIListLayout")


[Link] = [Link]
[Link] = [Link](0, 2)
[Link] = scrollFrame

for foodName, _ in pairs(recipes) do


local button = [Link]("TextButton")
[Link] = foodName
[Link] = [Link](1, -12, 0, 30)
button.BackgroundColor3 = [Link](35, 35, 35)
[Link] = 0
[Link] = foodName
button.TextColor3 = [Link](255, 255, 255)
[Link] = true
[Link] = [Link]
[Link] = scrollFrame

local buttonCorner = [Link]("UICorner")


[Link] = [Link](0, 4)
[Link] = button

button.MouseButton1Click:Connect(function()
currentFood = foodName
[Link] = currentFood .. " ▼"
[Link] = false

-- Reset rarity if not available


if not recipes[currentFood][currentRarity] then
for rarity, _ in pairs(recipes[currentFood]) do
currentRarity = rarity
break
end
[Link] = currentRarity .. " ▼"
rarityButton.TextColor3 = rarityColors[currentRarity] or
[Link](255, 255, 255)
end

updateIngredients()
end)

[Link]:Connect(function()
button.BackgroundColor3 = [Link](50, 50, 50)
end)
[Link]:Connect(function()
button.BackgroundColor3 = [Link](35, 35, 35)
end)
end

[Link] = [Link](0, 0, 0, [Link].Y)


layout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function()
[Link] = [Link](0, 0, 0,
[Link].Y)
end)

return dropdown
end

local function createRarityDropdown()


local dropdown = [Link]("Frame")
[Link] = "RarityDropdown"
[Link] = [Link](1, 0, 0, 150)
[Link] = [Link](0, 0, 1, 5)
dropdown.BackgroundColor3 = [Link](25, 25, 25)
[Link] = 1
dropdown.BorderColor3 = [Link](100, 100, 100)
[Link] = false
[Link] = 10
[Link] = rarityFrame

local dropdownCorner = [Link]("UICorner")


[Link] = [Link](0, 8)
[Link] = dropdown

local scrollFrame = [Link]("ScrollingFrame")


[Link] = "ScrollFrame"
[Link] = [Link](1, -10, 1, -10)
[Link] = [Link](0, 5, 0, 5)
[Link] = 1
[Link] = 6
scrollFrame.ScrollBarImageColor3 = [Link](100, 100, 100)
[Link] = dropdown

local layout = [Link]("UIListLayout")


[Link] = [Link]
[Link] = [Link](0, 2)
[Link] = scrollFrame

local function updateRarityDropdown()


for _, child in pairs(scrollFrame:GetChildren()) do
if child:IsA("TextButton") then
child:Destroy()
end
end

if recipes[currentFood] then
for rarity, _ in pairs(recipes[currentFood]) do
local button = [Link]("TextButton")
[Link] = rarity
[Link] = [Link](1, -12, 0, 30)
button.BackgroundColor3 = [Link](35, 35, 35)
[Link] = 0
[Link] = rarity
button.TextColor3 = rarityColors[rarity] or [Link](255,
255, 255)
[Link] = true
[Link] = [Link]
[Link] = scrollFrame

local buttonCorner = [Link]("UICorner")


[Link] = [Link](0, 4)
[Link] = button

button.MouseButton1Click:Connect(function()
currentRarity = rarity
[Link] = currentRarity .. " ▼"
rarityButton.TextColor3 = rarityColors[currentRarity] or
[Link](255, 255, 255)
[Link] = false
updateIngredients()
end)

[Link]:Connect(function()
button.BackgroundColor3 = [Link](50, 50, 50)
end)

[Link]:Connect(function()
button.BackgroundColor3 = [Link](35, 35, 35)
end)
end
end

[Link] = [Link](0, 0, 0,
[Link].Y)
end

updateRarityDropdown()
return dropdown, updateRarityDropdown
end

local foodDropdown = createFoodDropdown()


local rarityDropdown, updateRarityDropdownFunc = createRarityDropdown()

-- Eventos para abrir e fechar dropdowns


foodButton.MouseButton1Click:Connect(function()
[Link] = not [Link]
[Link] = false
end)

rarityButton.MouseButton1Click:Connect(function()
updateRarityDropdownFunc()
[Link] = not [Link]
[Link] = false
end)

-- Toggle ON/OFF
toggleButton.MouseButton1Click:Connect(function()
isEnabled = not isEnabled
updateToggle()
if isEnabled then
print("🍳 [COOKING] Sistema ativado!")
else
print("🍳 [COOKING] Sistema desativado!")
end
end)

-- Botão fechar GUI


closeButton.MouseButton1Click:Connect(function()
destroyExistingGui()
end)

-- Atualiza ingredientes mostrado


local function updateIngredients()
if recipes[currentFood] and recipes[currentFood][currentRarity] then
local ingredients = recipes[currentFood][currentRarity]
if #ingredients > 0 then
[Link] = ingredients[1]
else
[Link] = "Nenhuma receita encontrada"
end
else
[Link] = "Receita não disponível"
end
end

-- Atualiza botão toggle


local function updateToggle()
if isEnabled then
toggleFrame.BackgroundColor3 = [Link](50, 200, 50)
[Link] = "ON"
else
toggleFrame.BackgroundColor3 = [Link](200, 50, 50)
[Link] = "OFF"
end
end

-- Atualiza comida atual para o que o porco está pedindo


local function updateCurrentFoodFromCraving(cravingText)
-- Busca qual comida corresponde ao texto do porco
-- Vamos procurar em todas receitas se algum nome está contido no texto
pedido pelo porco
for foodName, rarities in pairs(recipes) do
-- Para cada raridade da comida
for rarity, ingredients in pairs(rarities) do
for _, ingredientText in ipairs(ingredients) do
-- Se o texto do porco contém o nome da comida (simplificado)
if [Link](cravingText:lower(), foodName:lower()) then
currentFood = foodName
currentRarity = rarity
[Link] = currentFood .. " ▼"
[Link] = currentRarity .. " ▼"
rarityButton.TextColor3 = rarityColors[currentRarity] or
[Link](255, 255, 255)
updateIngredients()
return
end
end
end
end
end
-- Loop para monitorar o porco e atualizar interface automaticamente
monitorConnection = spawn(function()
while gui and [Link] do
if isEnabled then
local craving = getCravingText()
if craving and craving ~= "" then
currentCraving = craving
[Link] = "🐷 " .. craving
cravingLabel.TextColor3 = [Link](85, 255, 85)

-- Atualiza comida e raridade baseada no pedido do porco


updateCurrentFoodFromCraving(craving)
else
currentCraving = "Aguardando..."
[Link] = "🐷 Aguardando..."
cravingLabel.TextColor3 = [Link](255, 255, 255)
end
else
[Link] = "🔴 Sistema Desativado"
cravingLabel.TextColor3 = [Link](255, 85, 85)
end
wait(1)
end
end)

-- Inicializa interface
updateIngredients()
updateToggle()

-- Fecha dropdowns ao clicar fora


gui.MouseButton1Click:Connect(function()
[Link] = false
[Link] = false
end)

return gui
end

print("🍳 Carregando Cooking Assistant...")


createInterface()
print("🍳 Interface criada com sucesso!")
print("🍳 Monitora automaticamente o que o porco está pedindo")
print("🍳 Use o botão ON/OFF para ativar/desativar o sistema")
print("🍳 Arraste a interface para mover")

Common questions

Powered by AI

The primary function of the script is to create a "Cooking Assistant" user interface in a game environment that assists players by monitoring and responding to a character's, referred to as 'the pig,' cravings. The script uses CoreGui or PlayerGui to display the interface, updates the GUI based on the pig's current cravings, and helps the player select a food item and its rarity according to a preset recipe list fetched from Pastebin. The script achieves this by destroying any old GUIs, creating a new interface with multiple components including text labels and buttons, and continuously monitoring the cravings of the pig to update the ingredients accordingly .

The script employs several strategies for ensuring a user-friendly design within the cooking interface. It uses intuitive naming and clear labels like 'CravingLabel' and 'FoodButton', accompanied by visual cues such as color changes and icon labels to guide users in their interactions. The interface is also designed to be draggable, aligning with common UI interaction principles to enhance accessibility and usability. Moreover, it uses logical feedback mechanisms like dropdown menus for selection, coherent text messages for status updates, and enables toggling for state changes, all contributing to an overall user-friendly experience .

Using global variables in the script for managing state, such as currentFood, currentRarity, and isEnabled, poses both benefits and challenges. While global variables provide convenient access to values across multiple functions, making the script more straightforward to manage and understand, they can introduce risks such as unintended data manipulation or conflicts if multiple scripts interact with the same variables. Therefore, careful naming conventions and controlled access methods can be crucial to mitigate these risks. The script, by keeping global variables localized within scope such as the Cooking Assistant interface, balances these concerns effectively in a single-script context .

The script manages user interaction through a GUI that includes dropdown menus for selecting food and its rarity. These are implemented as frames containing buttons that, when clicked, update the GUI text to display the selected food item or rarity. The system is interactive as it listens for user clicks to toggle visibility of dropdowns and updates selections. Interaction is visually supported by text and color changes reflecting the current selection, thus providing users clear feedback on their actions .

The 'toggle' feature in the script functions as an activation mechanism for the Cooking Assistant system. The toggle button, when clicked, changes the state of a global variable 'isEnabled', which controls whether the script actively monitors the pig's cravings and updates the GUI. This feature allows the user to turn the assistant on or off, which is indicated by changes in the button's text and background color. The toggle enhances user control over the script's functionality, allowing customization of their gameplay experience .

The script facilitates adaptability to structural changes in the game environment by deploying functions such as 'destroyExistingGui' which clean up previous instances of the GUI before creating new ones. This ensures that any changes in the GUI layout or component names can be seamlessly integrated without residual effects from older instances. Moreover, the use of dynamic path finding for critical elements like the 'craving text' embedding ensures it adapts to changes in parent-child structures in the game's workspace, making it robust against alterations in the game environment .

The rarity dropping system in the script prioritizes assigning higher rarities to food items whenever possible. This is evident in the script's logic where it assigns rarities based on a priority from 'Prismatic' to 'Common'. The purpose of such a system is likely to encourage gameplay scenarios where acquiring or aiming for higher rarity items is more rewarding, as they may yield better in-game outcomes. This design can enhance player engagement by adding a layer of strategy in trying to acquire higher rarity items .

The monitoring loop is crucial for maintaining the script's functionality as it continuously observes changes in the game, particularly the pig's cravings, and updates the user interface accordingly. Without this loop, the system would not automatically update in response to changes, leading to potential desynchronization between the player's actions and the GUI's status display, thus impairing the system's utility. Additionally, the absence of real-time updates could degrade the user experience by requiring manual interface refreshes or causing a lag in response to gameplay interactions .

The script dynamically updates the interface by setting up a continuous monitoring loop within a "spawn" function that checks for changes in the pig's craving text within the game workspace. When a change is detected, the script updates the 'currentCraving' variable and adjusts the GUI elements like 'cravingLabel' to reflect the new craving state. It also calls the 'updateCurrentFoodFromCraving' function to check which food name matches the craving text and updates the food and rarity buttons accordingly .

The method to fetch recipes from an external source, specifically Pastebin, involves using 'pcall' and 'HttpGet' functions for data retrieval and error checking. The script checks if recipes are successfully loaded and verifies that the data type is a table before proceeding to use them. If these conditions are not met, an error is thrown. This method is robust as it catches any unexpected issues during the fetching process and provides a fallback mechanism by ensuring data integrity before further script execution .

You might also like