Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ReplicatedStorage = game:GetService('ReplicatedStorage')
- local Knit = require(ReplicatedStorage.Packages.Knit)
- type Party = {
- Captain: Player,
- Player: Player
- }
- local PartyService = Knit.CreateService {
- Name = "PartyService",
- Parties = {},
- InviteTable = {},
- Client = {
- Invite = Knit.CreateSignal(),
- Leave = Knit.CreateSignal(),
- }
- }
- function PartyService.Client:CreateParty(player: Player)
- --Check if player in a party
- for i, p in PartyService.Parties do
- if p.Captain == player or p.Player == player then return end
- end
- local tempParty = {
- Captain = player,
- Player = nil
- } :: Party
- table.insert(PartyService.Parties, tempParty)
- return tempParty
- end
- function PartyService.Client:DisbandParty(player: Player)
- for i, p in PartyService.Parties do
- if p.Captain == p.Captain then
- PartyService.Parties[i] = nil
- table.remove(PartyService.Parties, i)
- if p.Player then PartyService.Client.Leave:Fire(p.Player) end
- return true
- end
- end
- end
- function PartyService.Client:LeaveParty(player:Player)
- for i, p in PartyService.Parties do
- if p.Player == player then
- PartyService.Parties[i].Player = nil
- return true
- end
- end
- return false
- end
- function PartyService.Client:InvitePlayer(captain: Player, party: Party, playerToInvite: Player)
- if party.Captain ~= captain then return false end
- if party.Player ~= nil then return false end
- if table.find(PartyService.InviteTable, playerToInvite) then return false end
- --Check if playerToInvite is in a party
- for i, p in PartyService.Parties do
- if p.Captain == playerToInvite or p.Player == playerToInvite then return false end
- end
- table.insert(PartyService.InviteTable, playerToInvite)
- return PartyService.Client.Invite:Fire(playerToInvite, captain)
- end
- function PartyService.Client:RejectInvite(player: Player)
- if table.find(PartyService.InviteTable, player) then
- table.remove(PartyService.InviteTable, table.find(PartyService.InviteTable, player))
- end
- end
- function PartyService.Client:JoinParty(player: Player, captain: Player)
- if table.find(PartyService.InviteTable, player) then
- table.remove(PartyService.InviteTable, table.find(PartyService.InviteTable, player))
- local tempParty = {
- Captain = captain,
- Player = player
- } :: Party
- for i, p in PartyService.Parties do
- if p.Captain == tempParty.Captain then
- PartyService.Parties[i] = tempParty
- return tempParty
- end
- end
- end
- end
- return PartyService
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement