-
Notifications
You must be signed in to change notification settings - Fork 5
/
YogiNotificadorFruta.lua
137 lines (121 loc) · 4.68 KB
/
YogiNotificadorFruta.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
local player = game.Players.LocalPlayer
local gui = player:WaitForChild("PlayerGui")
:WaitForChild("Main")
local label = gui:WaitForChild("[OLD]Radar")
local codes_button = gui:WaitForChild("Code")
local settings_button = gui:WaitForChild("Settings")
local script_enabled = "Script enabled successfully"
local notifier_enabled = "Notifier enabled successfully"
local notifier_disabled = "Notifier disabled successfully"
local description = "Shows spawned fruits location"
local on = "Notifier (ON)"
local off = "Notifier (OFF)"
local location = "FRUIT DETECTED: "
local magnitude = "m away."
local collected = "Fruit despawned/collected"
if (game:GetService("LocalizationService").RobloxLocaleId == "pt-br") then
script_enabled = "Script ativado com sucesso"
notifier_enabled = "Notificador ativado com sucesso"
notifier_disabled = "Notificador desativado com sucesso"
description = "Mostra a localizacao das frutas spawnadas"
on = "Notificador (ATIVADO)"
off = "Notificador (DESATIVADO)"
location = "FRUTA DETECTADA: "
magnitude = "m de distancia."
collected = "Fruta despawnada/coletada"
end
-- if executed twice or more
if codes_button:FindFirstChild("NotifierLed") then
return
end
-- creates led to indicate notifier status
local led = Instance.new("Frame")
led.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
led.BackgroundTransparency = 0.3
led.Position = UDim2.new(1.3, 0, 0.35, 0)
led.Size = UDim2.new(0, 8, 0, 8)
led.Name = "NotifierLed"
led.Parent = codes_button
local border = Instance.new("UICorner", led)
border.CornerRadius = UDim.new(1)
-- creates notifier switch by making a copy of an existent blox fruits switch
local switch = settings_button:WaitForChild("DmgCounterButton"):Clone()
switch.Notify.Text = description
switch.TextLabel.Text = off
switch.Position = UDim2.new(-1.2, 0, -4.03, 0) -- above counter switch
switch.Size = UDim2.new(5, 0, 0.8, 0) -- similar size to other switchs
switch.Name = "NotifierSwitch"
switch.Parent = settings_button
settings_button.Activated:Connect(function()
switch.Visible = not switch.Visible
end)
-- stores the connection, so after we can disconnect
-- on switch click (also used to check switch state)
local workspace_connection
-- displays text on the label that locates fruits
local function showText(text, time)
label.Text = text
label.Visible = true
if (time ~= 0) then
task.wait(time)
label.Visible = false
end
end
-- used when a fruit spawns
local function playSound(asset_id, pb_speed)
local sound = Instance.new("Sound", workspace)
sound.SoundId = asset_id
sound.Volume = 1
sound.PlaybackSpeed = pb_speed
sound:Play()
sound.Ended:Connect(function()
sound:Destroy()
end)
end
-- called when a fruit spawns
local function enableNotifier(fruit)
local handle = fruit:WaitForChild("Handle")
local fruit_alive = true
playSound("rbxassetid://3997124966", 4)
-- keeps updating the distance if fruit is alive and switch is on
while fruit_alive and workspace_connection do
local dist = math.floor((player.Character:WaitForChild("HumanoidRootPart").Position - handle.Position)
.Magnitude * 0.15)
showText(location .. dist .. magnitude, 0)
task.wait(0.2)
fruit_alive = workspace:FindFirstChild(fruit.Name)
end
if not fruit_alive then
playSound("rbxassetid://4612375233", 1)
showText(collected, 3)
end
end
local function onSwitchClick()
-- enables/disables workspace connection listening for children added
if workspace_connection then -- check if we are connected
workspace_connection:Disconnect() -- disconnect the event and stop listening
workspace_connection = nil
led.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
switch.TextLabel.Text = off
showText(notifier_disabled, 2)
else
led.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
switch.TextLabel.Text = on
showText(notifier_enabled, 2)
-- connect event and starts listening
workspace_connection = workspace.ChildAdded:Connect(function(child)
if child.Name == "Fruit " then -- intended space
task.spawn(enableNotifier, child)
end
end)
-- looks for an already spawned fruit (need workspace_connection)
local fruit = workspace:FindFirstChild("Fruit ") -- intended space
if fruit then
task.spawn(enableNotifier, fruit)
end
end
end
showText(script_enabled, 3)
onSwitchClick()
switch.Activated:Connect(onSwitchClick)
-- euyogi