1
This commit is contained in:
commit
a85391509d
211 files changed
+28903
No files matched your search
@@ -0,0 +1,48 @@
|
||||
--!strict
|
||||
-- Script in ServerScriptService.
|
||||
-- Passes a player's reload on to the other players, so they see it in third person.
|
||||
-- Client -> server: ReplicatedStorage.SniperReload:FireServer() (no arguments).
|
||||
-- Server -> other clients: SniperReload:FireClient(other, character, duration).
|
||||
-- Only accepted while the player holds the rifle, and at most once per reload time.
|
||||
|
||||
local Players = game:GetService("Players")
|
||||
local ReplicatedStorage = game:GetService("ReplicatedStorage")
|
||||
local StarterPlayer = game:GetService("StarterPlayer")
|
||||
|
||||
local TOOL_NAME = "SniperRifle"
|
||||
local remote = ReplicatedStorage:WaitForChild("SniperReload") :: RemoteEvent
|
||||
local config = StarterPlayer:WaitForChild("StarterPlayerScripts"):WaitForChild("SniperViewmodel")
|
||||
local Modes = require(ReplicatedStorage:WaitForChild("ArenaModes") :: ModuleScript)
|
||||
local round = ReplicatedStorage:WaitForChild("ArenaRound")
|
||||
|
||||
local nextReload: { [Player]: number } = {}
|
||||
|
||||
remote.OnServerEvent:Connect(function(player: Player)
|
||||
local character = player.Character
|
||||
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
|
||||
if player:GetAttribute("InArena") ~= true or not humanoid or humanoid.Health <= 0
|
||||
or not Modes.open(round, Modes.of(player), workspace:GetServerTimeNow()) then return end
|
||||
local tool = character and character:FindFirstChild(TOOL_NAME)
|
||||
if not character or not tool or not tool:IsA("Tool") then
|
||||
return
|
||||
end
|
||||
local reloadTime = (config:GetAttribute("ReloadTime") :: number?) or 2.6
|
||||
local now = os.clock()
|
||||
if now < (nextReload[player] or 0) then
|
||||
return -- still reloading (or spamming the remote)
|
||||
end
|
||||
if character:GetAttribute("LootReload") ~= nil then
|
||||
character:SetAttribute("LootReload", nil)
|
||||
reloadTime *= .5
|
||||
end
|
||||
nextReload[player] = now + reloadTime * .9
|
||||
for _, other in Players:GetPlayers() do
|
||||
if other ~= player and other:GetAttribute("InArena") == true and Modes.same(player, other) then
|
||||
remote:FireClient(other, character, reloadTime)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
Players.PlayerRemoving:Connect(function(player)
|
||||
nextReload[player] = nil
|
||||
end)
|
||||
Reference in new issue
Block a user