-- touseefx message: I GOT TO RECODE SOME THINGS BRUHHH
-- <- Services -> --
local Players = game:GetService('Players');
-- <- Private Variables -> --
local Generator = script:FindFirstAncestorWhichIsA('Model');
local Remotes = Generator:FindFirstChild('Remotes');
local RF = Remotes:FindFirstChild('RF');
local BE = Remotes:FindFirstChild('BE');
local RE = Remotes:FindFirstChild('RE');
-- <-Modules -> --
local Actor = require(game.ReplicatedStorage.Modules.Actors)
local Util = require(game.ReplicatedStorage.Modules.Util)
local Objectives = require(game.ReplicatedStorage.Modules.Objectives)
local GensManager =
require(game.ReplicatedStorage.Modules.CommonObjectives.SetupGenerators)
local Stauts = require(game.ReplicatedStorage.Modules.Statuses)
local Network = require(game.ReplicatedStorage.Modules.Network)
-- <- Functions -> --
function GetNearGenerator(Player: Player)
local GetNearGenerator, GeneratorMag
local Character = Player.Character
if not Character then
return
end
--
local PlayerPos = Character.PrimaryPart.Position
--
for Index, Value in workspace.Map.Ingame:GetDescendants() do
if Value.Name == 'FakeGenerator' then
local Main = Value:FindFirstChild('Main');
if Main and Main:IsA('BasePart') then
if GetNearGenerator then
local CurrentMag = (Main.Position -
PlayerPos).Magnitude
--
if CurrentMag < GeneratorMag then
GetNearGenerator = Value
GeneratorMag = (Main.Position -
PlayerPos).Magnitude
end
else
GetNearGenerator = Value
GeneratorMag = (Main.Position - PlayerPos).Magnitude
end
end
end
end
--
return GetNearGenerator, GeneratorMag
end
function GetPosition(Player: Player, GeneratorFound: Model)
local Position, PositionMag, InstanceXd
local Character = Player.Character
if not Character then
return
end
--
local PlayerPos = Character.PrimaryPart.Position
--
for Index, Value in GeneratorFound:GetChildren() do
if Value:IsA('Folder') and Value.Name == 'Positions' then
for _, Things in Value:GetChildren() do
if Things and Things:IsA('BasePart') then
if Position then
local CurrentMag = (Things.Position -
PlayerPos).Magnitude
if CurrentMag < PositionMag then
Position = Things.Name
InstanceXd = Things
PositionMag = (Things.Position -
PlayerPos).Magnitude
end
else
Position = Things.Name
InstanceXd = Things
PositionMag = (Things.Position -
PlayerPos).Magnitude
end
end
end
end
end
--
return Position, InstanceXd
end
function HandleRF(Player: Player, Action: string)
local GeneratorFound, Magnitude = GetNearGenerator(Player);
if not GeneratorFound then
return
end
--
local Character = Player.Character
if not Character then
return
end
--
if Action == 'enter' then
local Position, PositionInstance = GetPosition(Player, GeneratorFound);
--
if Magnitude >= 10 then
return 'tooFar'
end
--
if Character.Parent.Name == 'Spectating' then
return 'isUnknownTeam'
end
--
if Character.Parent.Name == 'Killers' then
return 'isKiller'
end
--
if GeneratorFound:GetAttribute('Completed') then
return 'alreadyFixed'
end
--
if PositionInstance:GetAttribute('Used') then
return 'positionOccupied'
end
--
if Character:FindFirstChild('Humanoid') then
local Humanoid = Character:FindFirstChild('Humanoid')
if Humanoid.Health == 0 or Humanoid.Health == 1 then
return 'dead'
end
end
--
local NewValue = Instance.new('IntValue')
NewValue.Name = 'FixingGenerator'
NewValue.Parent = Player.Character
--
Character:PivotTo(PositionInstance.CFrame)
--
PositionInstance:SetAttribute('Used', true)
PositionInstance:SetAttribute('Player', Player.Name)
--
return 'fixing', Position, GeneratorFound
elseif Action == 'leave' then
Player:SetAttribute('CompletedGenPuzzle', nil);
--
local Position, PositionInstance = GetPosition(Player, GeneratorFound);
PositionInstance:SetAttribute('Used', nil);
--
if Player:FindFirstChild('FixingGenerator') then
Player:FindFirstChild('FixingGenerator'):Destroy()
end
--
if Player.Character:FindFirstChild('FixingGenerator') then
Player.Character:FindFirstChild('FixingGenerator'):Destroy()
end
--
if
Player.Character:FindFirstChild("SpeedMultipliers"):FindFirstChild('FixingGenerator
') then
Player.Character:FindFirstChild("SpeedMultipliers"):FindFirstChild('FixingGenerator
'):Destroy()
end
--
return 'notFixing'
end
end
function HandleBE(Player, LastestProgress: number) -- WIP
if not Player then return end
-- player is a gen at end
local Killer =
workspace:FindFirstChild('Players'):FindFirstChild('Killers'):FindFirstChild('NoliR
ework')
if Player:IsA('Player') then
local notificationText = {}
local rewardInfo = {
Money = 5,
EXP = 15,
Action = 'Compeleted Generator Puzzle'
}
local moneyText = rewardInfo.Money and string.format("$%s",
tostring(rewardInfo.Money))
local expText = rewardInfo.EXP and string.format("%s EXP",
tostring(rewardInfo.EXP))
-- fake gen awared message
if moneyText then table.insert(notificationText, moneyText) end
if expText then table.insert(notificationText, expText) end
Network:FireClientConnection(Player, "SendNotif", "REMOTE_EVENT",
string.format("+ %s: %s", table.concat(notificationText, " & "),
rewardInfo.Action), "Objective")
else
if LastestProgress >= 100 then
Player:SetAttribute('PowerGain', LastestProgress)
Player:FindFirstChild('Progress'):SetAttribute('Completed', true)
Player:SetAttribute('Completed', true)
for Index, Value: BasePart in
Player:FindFirstChild('Positions'):GetChildren() do
Player = Value:GetAttribute('Player');
if not Player then
continue
end
Player = game.Players:FindFirstChild(Player);
Player:SetAttribute('CompletedGenPuzzle', true);
Stauts:ApplyStatus(Player.Character, 'Hallucination', {
Level = 2;
Duration = 15;
Killer =
Actor.CurrentActors[game.Players:GetPlayerFromCharacter(Killer)];
})
end
end
end
end
function HandleRE(Player: Player, ...) -- CompletedGenPuzzle
local GeneratorFound, Magnitude = GetNearGenerator(Player)
if not GeneratorFound then return 'no gen' end
--
local Progress = GeneratorFound:FindFirstChild('Progress')
if not Progress then return 'no progress?' end
--
if not Player then return 'no player??' end
--
if not Actor then return 'no actor' end
--
Progress.Value += GeneratorFound:GetAttribute('PowerGain')
--
if Progress.Value >= 100 and not GeneratorFound:GetAttribute('Completed')
then
BE:Fire(GeneratorFound, Progress.Value)
else
BE:Fire(Player, Progress.Value)
end
end
-- <- Connections -> --
RF.OnServerInvoke = function(Player: Player, ...)
return HandleRF(Player, ...)
end
RE.OnServerEvent:Connect(HandleRE)
BE.Event:Connect(HandleBE)