1
This commit is contained in:
commit
a85391509d
211 files changed
+28903
No files matched your search
@@ -0,0 +1,52 @@
|
||||
--!strict
|
||||
-- ModuleScript in ServerScriptService. Spawn markers belong to the player's arena.
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local Modes = require(ReplicatedStorage:WaitForChild("ArenaModes") :: ModuleScript)
|
||||
local random = Random.new()
|
||||
local ArenaSpawns = {}
|
||||
|
||||
function ArenaSpawns.choose(player: Player): SpawnLocation
|
||||
local arena = Modes.geometry(Modes.of(player))
|
||||
local folder = arena:WaitForChild("PlayerSpawns")
|
||||
local side = player:GetAttribute("ArenaTeam")
|
||||
local choices: {SpawnLocation} = {}
|
||||
for _, marker in folder:GetChildren() do
|
||||
local group = marker:GetAttribute("ArenaTeam")
|
||||
if marker:IsA("SpawnLocation") and marker.Enabled and (group == nil or group == side) then
|
||||
table.insert(choices, marker)
|
||||
end
|
||||
end
|
||||
assert(#choices > 0, arena.Name .. " has no enabled spawns for this team")
|
||||
local best = choices[random:NextInteger(1, #choices)]
|
||||
local bestDistance = -1
|
||||
for _, marker in choices do
|
||||
local nearest = 1000
|
||||
for _, other in Players:GetPlayers() do
|
||||
local character = other.Character
|
||||
local root = character and character:FindFirstChild("HumanoidRootPart")
|
||||
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
|
||||
if other ~= player and other:GetAttribute("InArena") == true and Modes.same(player, other)
|
||||
and root and root:IsA("BasePart") and humanoid and humanoid.Health > 0 then
|
||||
nearest = math.min(nearest, (root.Position - marker.Position).Magnitude)
|
||||
end
|
||||
end
|
||||
local score = nearest + random:NextNumber(0, 24)
|
||||
if score > bestDistance then
|
||||
bestDistance = score
|
||||
best = marker
|
||||
end
|
||||
end
|
||||
return best
|
||||
end
|
||||
|
||||
function ArenaSpawns.place(character: Model, marker: SpawnLocation)
|
||||
character:PivotTo(marker.CFrame + Vector3.new(0, 4, 0))
|
||||
local root = character:FindFirstChild("HumanoidRootPart")
|
||||
if root and root:IsA("BasePart") then
|
||||
root.AssemblyLinearVelocity = Vector3.zero
|
||||
root.AssemblyAngularVelocity = Vector3.zero
|
||||
end
|
||||
end
|
||||
|
||||
return ArenaSpawns
|
||||
Reference in new issue
Block a user