Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- [[ Services ]] --
- local ReplicatedStorage = game:GetService('ReplicatedStorage');
- local CollectionService = game:GetService("CollectionService")
- -- [[ Resources ]] --
- local CardinalSystem = require(ReplicatedStorage:WaitForChild('CardinalSystem'));
- -- [[ Variables ]] --
- local Assets = ReplicatedStorage:FindFirstChild("Assets");
- assert(Assets, "Assets not found.");
- local Outfits = Assets:FindFirstChild("Outfits");
- assert(Outfits, "Outfits couldn't be found.");
- local Katana = Assets:FindFirstChild("Katana");
- local Motors = Katana and Katana:FindFirstChild("Motors");
- assert(Motors, "Motors couldn't be found.");
- local Models = Katana and Katana:FindFirstChild("Models");
- assert(Models, "Katana Models couldn't be found.");
- -- [[ Service ]] --
- local CharacterService = CardinalSystem:CreateService({
- Name = 'CharacterService';
- });
- local function ToggleAnchor(Character : Model, Bool : boolean)
- for _,Basepart in pairs(Character:GetDescendants()) do
- if Basepart:IsA("BasePart") then
- Basepart.Anchored = Bool
- end
- end
- end
- function CharacterService:OnInit()
- self.Services = {
- DatastoreService = CardinalSystem:GetService('DatastoreService');
- BreathingService = CardinalSystem:GetService("BreathingService")
- };
- self.Resources = {
- StatusHandler = CardinalSystem:LoadLibrary('StatusHandler');
- LimbsHandler = CardinalSystem:LoadLibrary("Limbs");
- Janitor = CardinalSystem:LoadLibrary("Janitor");
- };
- self.Clothings = {};
- self.StatusHandlers = {};
- self.Limbs = {};
- end
- local _BaseStatus = {
- {
- Type = "Breathe",
- Value = 0;
- Min = 0;
- Max = 100;
- };
- }
- function CharacterService:AddStatusHandler(Character: Model)
- local StatusHandler = self.Resources.StatusHandler;
- local LimbsHandler = self.Resources.LimbsHandler;
- local Janitor = self.Resources.Janitor;
- local Handler = StatusHandler.new(Character);
- local Limbs = LimbsHandler.new(Character);
- local _Janitor = Janitor.new();
- _Janitor:Add(function()
- Handler:Destroy();
- Limbs:Destroy();
- self.Limbs[Character] = nil;
- self.StatusHandlers[Character] = nil;
- end, true);
- _Janitor:LinkToInstance(Character);
- Character.Humanoid.Died:Connect(function()
- Character:BreakJoints()
- _Janitor:Cleanup()
- end)
- self.StatusHandlers[Character] = Handler;
- self.Limbs[Character] = Limbs;
- for _, Table in pairs(_BaseStatus) do
- Handler:AddStatus(Table)
- end
- self.Services.BreathingService:InitPlayer(Character, Handler)
- return Handler;
- end
- function CharacterService:HandleRagdoll(Character : Model, Humanoid : Humanoid)
- local Janitor = self.Resources.Janitor
- local _Janitor = Janitor.new()
- print("HandleRagdoll")
- _Janitor:Add(Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
- local NewHealth = math.ceil(Humanoid.Health)
- if CollectionService:HasTag(Character, "Ragdolled") then
- if NewHealth >= 20 then
- CollectionService:RemoveTag(Character, "Ragdolled")
- ToggleAnchor(Character, false)
- task.wait(.1)
- Humanoid:ChangeState(Enum.HumanoidStateType.GettingUp)
- end
- else
- if NewHealth <= 0 and not CollectionService:HasTag(Character, "Ragdolled") then
- print("Activating ragdoll")
- task.wait(.1)
- CollectionService:AddTag(Character, "Ragdolled")
- Humanoid:ChangeState(Enum.HumanoidStateType.Ragdoll)
- --Character.HumanoidRootPart:ApplyAngularImpulse(Vector3.new(-90, 0, 0))
- end
- end
- end), "Disconnect")
- _Janitor:LinkToInstance(Character)
- Humanoid.BreakJointsOnDeath = false
- Humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, true)
- Humanoid:SetStateEnabled(Enum.HumanoidStateType.Dead, false)
- end
- local function Weld(P0, P1, RefPart) -- P0 for Character Part, P1 For new part
- P1.CFrame = P0.CFrame * (RefPart.CFrame:Inverse() * P1.CFrame)
- local WeldConst = Instance.new("WeldConstraint", P1)
- WeldConst.Part0 = P0
- WeldConst.Part1 = P1
- return WeldConst
- end
- function CharacterService:SetupHaori(Character, Style: string)
- local HaoriModel = Assets.Models.Haoris:FindFirstChild("Haori "..Style)
- local HaoriRef = HaoriModel
- if HaoriModel then
- local StoreFolder = Instance.new("Folder", Character); StoreFolder.Name = "Haori"
- HaoriModel = HaoriModel.Haori:Clone()
- HaoriModel.Parent = Character
- local function SetupBaseparts()
- for _, Basepart in pairs(HaoriModel:GetChildren()) do
- if Basepart:IsA("BasePart") then
- Basepart.Parent = StoreFolder
- Weld(Character:FindFirstChild(Basepart.Name), Basepart, HaoriRef.Rig:FindFirstChild(Basepart.Name))
- end
- end
- end
- SetupBaseparts()
- end
- end
- function CharacterService:SetupUniform(Character, Style: string)
- local UniModel = Assets.Models.Uniforms:FindFirstChild(Style)
- local ReferenceModel = UniModel
- if UniModel then
- local StoreFolder = Instance.new("Folder", Character); StoreFolder.Name = Style
- UniModel = UniModel.Cloth:Clone()
- UniModel.Parent = Character
- local function SetupBaseparts()
- for _, Basepart in pairs(UniModel:GetChildren()) do
- if Basepart:IsA("BasePart") then
- Basepart.Parent = StoreFolder
- Weld(Character:FindFirstChild(Basepart.Name), Basepart, ReferenceModel.Rig:FindFirstChild(Basepart.Name))
- end
- end
- end
- SetupBaseparts()
- end
- end
- function CharacterService:UpdateClothing(Player: Player)
- local DatastoreService = self.Services.DatastoreService;
- if not DatastoreService then
- return
- end
- local Clothing = self.Clothings[Player];
- if not Clothing then
- repeat
- Clothing = self.Clothings[Player];
- task.wait();
- until Clothing;
- end
- local Shirt = Clothing.Shirt;
- local Pants = Clothing.Pants;
- DatastoreService:GetPlayerProfile(Player):andThen(function(Profile)
- local Data = Profile:GetData();
- if not Data then return end
- local Success, Selected = pcall(function()
- return Outfits[tostring(Data.Customization.Shirt.Id)].Shirt;
- end)
- if Success and Shirt and Selected then
- Shirt.ShirtTemplate = Selected.ShirtTemplate;
- end
- Success, Selected = pcall(function()
- return Outfits[tostring(Data.Customization.Pants.Id)].Pants;
- end)
- if Success and Pants and Selected then
- Pants.PantsTemplate = Selected.PantsTemplate;
- end
- end)
- end
- function CharacterService:OnCharacterAdded(Character: Model, Player: Player)
- local DatastoreService = self.Services.DatastoreService;
- if not DatastoreService then
- return
- end
- local Hrp = Character:WaitForChild("HumanoidRootPart");
- Character.Parent = workspace:FindFirstChild("Living");
- DatastoreService:GetPlayerProfile(Player):andThen(function(Profile)
- local Data = Profile:GetData();
- if not Data then return end
- local Location = Data.Stats.Location;
- Hrp.CFrame = CFrame.new(Location.X, Location.Y, Location.Z);
- if Data.Stats.Race == "Human" then
- local Torso = Character:FindFirstChild("Torso");
- local Folder = Models:FindFirstChild(tostring(Data.Customization.Nichirin.Id));
- if Torso and Folder then
- local Weapon = Folder:FindFirstChild("Weapon");
- if Weapon then
- local Motor = Motors.Handle:Clone();
- Motor.Part0 = Character["Right Arm"];
- Motor.Enabled = false;
- Weapon = Weapon:Clone();
- Motor.Part1 = Weapon.PrimaryPart;
- Motor.Parent = Weapon.Welds;
- Weapon.Parent = Character;
- end
- local Sheathe = Folder:FindFirstChild("Sheathe");
- if Sheathe then
- local Motor = Motors.Sheathe:Clone();
- Motor.Part0 = Torso;
- local Motor1 = Motors.DefaultSheathe:Clone();
- Sheathe = Sheathe:Clone();
- Motor.Part1 = Sheathe.PrimaryPart;
- Motor1.Part0 = Sheathe.PrimaryPart;
- Motor1.Part1 = Character:FindFirstChild("Weapon") and Character.Weapon.PrimaryPart;
- Motor.Parent = Sheathe.Welds;
- Motor1.Parent = Sheathe.Welds;
- Motor.Enabled = true;
- Motor1.Enabled = true;
- Sheathe.Parent = Character;
- end
- end
- end
- end)
- local Shirt = Character:FindFirstChild("Shirt");
- local Pants = Character:FindFirstChild("Pants");
- if not Shirt then
- Shirt = Instance.new("Shirt");
- Shirt.Name = "Shirt";
- Shirt.Parent = Character;
- end
- if not Pants then
- Pants = Instance.new("Pants");
- Shirt.Name = "Pants";
- Pants.Parent = Character;
- end
- self.Clothings[Player] = {
- Shirt = Shirt;
- Pants = Pants;
- }
- self:UpdateClothing(Player);
- self:AddStatusHandler(Character);
- self:SetupUniform(Character, "Slayers")
- local Humanoid = Character:WaitForChild("Humanoid",20)
- self:HandleRagdoll(Character, Humanoid)
- end
- function CharacterService:OnHeartbeat(dt)
- for _, Handler in pairs(self.StatusHandlers) do
- task.spawn(Handler._OnHeartbeat, Handler, dt);
- end
- end
- return CharacterService;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement