I’m trying to get all the users that where matched together within a match. Not sure how I could do this?
My code:
local match_players = {}
local function setup_match_players_list(context)
local match = nk.match_get(context.match_id)
for _, value in pairs(match.users) do
match_players[#match_players+1] = value
end
end
@VastView How are you matchmaking your players? If you’re using the matchmaker you can register a hook and see the matchmaker output for each match as it’s formed.
I also learned that the state paramter passed through all the match handler hooks is what you should use to store local match data for every match on server memory.
Here’s my code for sharing a list of all matched players to my match handler:
local function makematch(context, matched_users)
-- print matched users
nk.logger_info("Matched users:")
for _, user in ipairs(matched_users) do
local presence = user.presence
nk.logger_info(string.format("Presence.user_id: %s", presence.user_id))
end
local modulename = "match_handler"
local setupstate = {
players_ordered = {}
}
for _, user in pairs(matched_users) do
setupstate.players_ordered[#setupstate.players_ordered+1] = user.presence
end
local matchid = nk.match_create(modulename, setupstate)
return matchid
end
nk.register_matchmaker_matched(makematch)