Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ServerStorage = game:GetService("ServerStorage")
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local sharedModules = ReplicatedStorage.SharedModules
- local serverModules = ServerStorage.ServerModules
- local ZoneInformation = require(sharedModules.ZoneInformation)
- local PlayerZoneManager = {}
- local zones = {}
- local function start()
- for _, zoneInfo in ipairs(ZoneInformation) do
- zones[zoneInfo.name] = {}
- end
- end
- local function getZone(zoneName)
- return zones[zoneName]
- end
- local function getPlayerZoneByName(player, zoneName)
- return getZone(zoneName)[player]
- end
- local function findPlayerZone(player)
- for zoneName, zone in pairs(zones) do
- local playerInZone = getPlayerZoneByName(player, zoneName)
- if playerInZone then
- return zoneName
- end
- end
- end
- local function setPlayerZone(player, zoneName, value)
- local zone = getZone(zoneName)
- if value then
- zone[player] = true
- PlayerZoneManager:onZonePlayerAdded(player, zoneName)
- else
- zone[player] = nil
- PlayerZoneManager:onZonePlayerRemoved(player, zoneName)
- end
- end
- function PlayerZoneManager:onZonePlayerAdded(player, zoneName)
- print(player, "added: " .. zoneName)
- end
- function PlayerZoneManager:onZonePlayerRemoved(player, zoneName)
- print(player, "removed: " .. zoneName)
- end
- function PlayerZoneManager:addPlayerToZone(player, zoneName)
- if not getZone(zoneName) or getPlayerZoneByName(player, zoneName) then return end
- self:findAndRemovePlayerZone(player)
- setPlayerZone(player, zoneName, true)
- end
- function PlayerZoneManager:removePlayerFromZone(player, zoneName)
- local zone = getZone(zoneName)
- if getPlayerZoneByName(player, zoneName) then
- setPlayerZone(player, zoneName, false)
- end
- end
- function PlayerZoneManager:findAndRemovePlayerZone(player)
- local zoneName = findPlayerZone(player)
- if zoneName then
- self:removePlayerFromZone(player, zoneName)
- end
- end
- start()
- return PlayerZoneManager
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement