-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlotService.lua
94 lines (76 loc) · 2.46 KB
/
PlotService.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
local HttpService = game:GetService("HttpService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Plots = workspace:WaitForChild("Plots")
local PlotService = {}
function PlotService.InitializePlots()
for _, plot in pairs(Plots:GetChildren()) do
plot:SetAttribute("Occupant", "None")
end
end
function PlotService.GetPlot(plr)
for _, plot in pairs(Plots:GetChildren()) do
if plot:GetAttribute("Occupant") == plr.Name then
return plot
end
end
return nil
end
function PlotService.LeavePlot(plr)
local plot = PlotService.GetPlot(plr)
if plot then
plot:SetAttribute("Occupant", "None")
end
end
function PlotService.OwnPlot(plr, plot, saveName)
local DataService = require(ReplicatedStorage:WaitForChild("Modules").DataService)
local char = plr.Character or plr.CharacterAdded:Wait()
if not plot then return nil end
if not plot:IsA("BasePart") then return nil end
if plot:GetAttribute("Occupant") ~= "None" then return false end
local loadedPlot = DataService.LoadPlot(plr, plot, saveName)
plot:SetAttribute("Occupant", plr.Name)
local cf = plot.PlotSpawn.CFrame
char.HumanoidRootPart.CFrame = CFrame.new(cf.Position + Vector3.new(0, 5, 0))
return true, loadedPlot
end
function PlotService.GetAvailablePlots()
local availablePlots = {}
for i, plot in pairs(Plots:GetChildren()) do
if plot:GetAttribute("Occupant") == "None" then
table.insert(availablePlots, plot)
end
end
return availablePlots
end
function PlotService.EditPlot(player, plotName: string, instruction: string, value)
local DataService = require(ReplicatedStorage:WaitForChild("Modules").DataService)
local profile = DataService.GetProfile(player)
local plots = profile.Data["plots"]
if not plots then
profile.Data["plots"] = {}
end
local plotData = DataService.GetPlot(player, plotName)
if not plotData then
local plotID = HttpService:GenerateGUID(false)
profile.Data["plots"][plotID] = {
["items"] = {},
["name"] = tostring(plotName),
["id"] = tostring(plotID),
["lastUsed"] = nil,
}
end
if instruction == "name" then
plotData = profile.Data["plots"][plotData.plotID]
profile.Data["plots"][plotData.id] = {
["items"] = plotData.items,
["name"] = tostring(value),
["id"] = plotData.id,
["lastUsed"] = plotData.lastUsed,
}
plotData = nil
else
return false
end
return true
end
return PlotService