Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local eloData = game:GetService("DataStoreService"):GetDataStore("ELO")
- debugmode = true
- local UpdateRate = 3
- function debugprint(msg)
- if debugmode then
- print("DB="..msg)
- end
- end
- local PlayersInQueue = {}
- local JoinQueueQueue = {}
- function game.ReplicatedStorage.JoinQueue.OnServerInvoke(player)
- local PlayerData =
- {
- PlayerName = "";
- Elo = 0;
- Range = 2 ;
- Matched = false;
- }
- PlayerData["Elo"] = 0 --eloData:GetAsync(tostring(player.userId))
- PlayerData["PlayerName"] = player.Name
- table.insert(JoinQueueQueue,1,PlayerData)
- return true
- end
- local Matches = {}
- while true do
- print("Matchmaking tick")
- local function CreateMatch(FirstPlayer)
- print(FirstPlayer["PlayerName"])
- print("Creating new match!")
- local NewMatch = {}
- NewMatch["Average"] = FirstPlayer["Elo"]
- debugprint("Average set for new match = "..tostring(FirstPlayer["Elo"]))
- NewMatch["Range"] = 2
- FirstPlayer["Matched"] = true
- table.insert(NewMatch,1, FirstPlayer)
- table.insert(Matches,1,NewMatch)
- end
- wait(UpdateRate)
- print("Players in JoinQueueQueue = "..#JoinQueueQueue)
- if #JoinQueueQueue > 0 then
- for i = 1, #JoinQueueQueue do
- print("Transferred "..JoinQueueQueue[i]["PlayerName"].." into the player queue")
- print("Index = "..tostring(i))
- table.insert(PlayersInQueue,1,JoinQueueQueue[i])
- JoinQueueQueue[i] = nil
- end
- end
- print("PlayersInQueue = "..#PlayersInQueue)
- if #PlayersInQueue > 0 then
- for i = 1, #PlayersInQueue do
- debugprint("Scanning player "..PlayersInQueue[i]["PlayerName"])
- if PlayersInQueue[i]["Matched"] == false then
- debugprint("Matched = true")
- if #Matches ~= 0 then
- print("Matches ~= 0")
- for i_2=1,#Matches do
- local Diff = Matches[i_2]["Average"] - PlayersInQueue[i]["Elo"]
- if Diff < 0 then
- Diff = Diff * -1
- end
- if Matches[i_2]["Range"] >= Diff then
- --Is in range of Match
- print("Player is in range of match")
- table.insert(Matches[i_2],1,PlayersInQueue[i])
- PlayersInQueue[i]["Matched"] = true
- break
- end
- end
- else
- print("No matches exist, let's create one")
- CreateMatch(PlayersInQueue[i])
- end
- end
- end
- end
- print("Amount of matches = "..#Matches)
- if #Matches > 0 then --Potentially combine matches together
- for i = 1,#Matches do
- --if #Matches[i] == 0 then Matches[i] = nil end --clean up on aisle four
- Matches[i]["Range"] = Matches[i]["Range"] + 2 --Range increase per tick
- if #Matches[i] == 10 then
- print("Match made! Teleporting")
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement