This commit is contained in:
Thomas G 2022-09-16 03:40:04 +10:00
parent 070cb301fd
commit 2ec90a2630
1 changed files with 68 additions and 48 deletions

View File

@ -1,4 +1,17 @@
%6% %6%
function waitForProperty(instance, name)
while not instance[name] do
instance.Changed:wait()
end
end
function waitForChild(instance, name)
while not instance:FindFirstChild(name) do
instance.ChildAdded:wait()
end
end
local mainFrame local mainFrame
local choices = {} local choices = {}
local lastChoice local lastChoice
@ -23,6 +36,15 @@ local reenableDialogScript
local dialogMap = {} local dialogMap = {}
local dialogConnections = {} local dialogConnections = {}
local gui = nil
waitForChild(game,"CoreGui")
waitForChild(game.CoreGui,"RobloxGui")
if game.CoreGui.RobloxGui:FindFirstChild("ControlFrame") then
gui = game.CoreGui.RobloxGui.ControlFrame
else
gui = game.CoreGui.RobloxGui
end
function currentTone() function currentTone()
if currentConversationDialog then if currentConversationDialog then
return currentConversationDialog.Tone return currentConversationDialog.Tone
@ -404,7 +426,7 @@ end
function checkForLeaveArea() function checkForLeaveArea()
while currentConversationDialog do while currentConversationDialog do
if player:DistanceFromCharacter(currentConversationDialog.Parent.Position) >= currentConversationDialog.ConversationDistance then if currentConversationDialog.Parent and (player:DistanceFromCharacter(currentConversationDialog.Parent.Position) >= currentConversationDialog.ConversationDistance) then
wanderDialog() wanderDialog()
end end
wait(1) wait(1)
@ -431,19 +453,6 @@ function startDialog(dialog)
end end
end end
function waitForProperty(instance, name)
while not instance[name] do
instance.Changed:wait()
end
end
function waitForChild(instance, name)
while not instance:FindFirstChild(name) do
instance.ChildAdded:wait()
end
end
function removeDialog(dialog) function removeDialog(dialog)
if dialogMap[dialog] then if dialogMap[dialog] then
dialogMap[dialog]:Remove() dialogMap[dialog]:Remove()
@ -456,43 +465,57 @@ function removeDialog(dialog)
end end
function addDialog(dialog) function addDialog(dialog)
if dialog.Parent and dialog.Parent:IsA("BasePart") then if dialog.Parent then
local chatGui = chatNotificationGui:clone() if dialog.Parent:IsA("BasePart") then
chatGui.Enabled = not dialog.InUse local chatGui = chatNotificationGui:clone()
chatGui.Adornee = dialog.Parent chatGui.Enabled = not dialog.InUse
chatGui.RobloxLocked = true chatGui.Adornee = dialog.Parent
chatGui.Parent = game.CoreGui chatGui.RobloxLocked = true
chatGui.Image.Button.MouseButton1Click:connect(function() startDialog(dialog) end) chatGui.Parent = game.CoreGui
setChatNotificationTone(chatGui, dialog.Purpose, dialog.Tone) chatGui.Image.Button.MouseButton1Click:connect(function() startDialog(dialog) end)
setChatNotificationTone(chatGui, dialog.Purpose, dialog.Tone)
dialogMap[dialog] = chatGui dialogMap[dialog] = chatGui
dialogConnections[dialog] = dialog.Changed:connect(function(prop) dialogConnections[dialog] = dialog.Changed:connect(function(prop)
if prop == "Parent" and dialog.Parent then if prop == "Parent" and dialog.Parent then
--This handles the reparenting case, seperate from removal case --This handles the reparenting case, seperate from removal case
removeDialog(dialog) removeDialog(dialog)
addDialog(dialog) addDialog(dialog)
elseif prop == "InUse" then elseif prop == "InUse" then
chatGui.Enabled = not currentConversationDialog and not dialog.InUse chatGui.Enabled = not currentConversationDialog and not dialog.InUse
if dialog == currentConversationDialog then if dialog == currentConversationDialog then
timeoutDialog() timeoutDialog()
end end
elseif prop == "Tone" or prop == "Purpose" then elseif prop == "Tone" or prop == "Purpose" then
setChatNotificationTone(chatGui, dialog.Purpose, dialog.Tone) setChatNotificationTone(chatGui, dialog.Purpose, dialog.Tone)
end end
end) end)
else -- still need to listen to parent changes even if current parent is not a BasePart
dialogConnections[dialog] = dialog.Changed:connect(function(prop)
if prop == "Parent" and dialog.Parent then
--This handles the reparenting case, seperate from removal case
removeDialog(dialog)
addDialog(dialog)
end
end)
end
end end
end end
function fetchScripts() function fetchScripts()
--print("InsertService")
local model = game:GetService("InsertService"):LoadAsset(39226062) local model = game:GetService("InsertService"):LoadAsset(39226062)
--print(model) if type(model) == "string" then -- load failed, lets try again
while model == "No assetUrl set" do wait(0.1)
--print("Trying again to fetch Scripts")
model = game:GetService("InsertService"):LoadAsset(39226062) model = game:GetService("InsertService"):LoadAsset(39226062)
end end
if type(model) == "string" then -- not going to work, lets bail
return
end
waitForChild(model,"TimeoutScript")
timeoutScript = model.TimeoutScript timeoutScript = model.TimeoutScript
waitForChild(model,"ReenableDialogScript")
reenableDialogScript = model.ReenableDialogScript reenableDialogScript = model.ReenableDialogScript
end end
@ -507,16 +530,13 @@ function onLoad()
--print("Creating Guis") --print("Creating Guis")
createChatNotificationGui() createChatNotificationGui()
--print("Waiting for RobloxGui")
waitForChild(game.CoreGui, "RobloxGui")
--print("Creating MessageDialog") --print("Creating MessageDialog")
createMessageDialog() createMessageDialog()
messageDialog.RobloxLocked = true messageDialog.RobloxLocked = true
messageDialog.Parent = game.CoreGui.RobloxGui messageDialog.Parent = gui
--print("Waiting for BottomLeftControl") --print("Waiting for BottomLeftControl")
waitForChild(game.CoreGui.RobloxGui, "BottomLeftControl") waitForChild(gui, "BottomLeftControl")
--print("Initializing Frame") --print("Initializing Frame")
local frame = Instance.new("Frame") local frame = Instance.new("Frame")
@ -525,7 +545,7 @@ function onLoad()
frame.Size = UDim2.new(0,0,0,0) frame.Size = UDim2.new(0,0,0,0)
frame.BackgroundTransparency = 1 frame.BackgroundTransparency = 1
frame.RobloxLocked = true frame.RobloxLocked = true
frame.Parent = game.CoreGui.RobloxGui.BottomLeftControl frame.Parent = gui.BottomLeftControl
initialize(frame) initialize(frame)
--print("Adding Dialogs") --print("Adding Dialogs")