Skip to main content

FetchByRole

Server
Lyn.Player.FetchByRole(string role, table? include, function callback)Function

Description

Fetches all players that have a specific role.

Params

  1. string role
  2. table? include

    Optional list of fields to include from lyn_player (e.g. "name", "playtime").

  3. function callback

    Callback function when operation completes/fails.

    Callback params(s):

    1. table | nil err

      Error message if failed.

    2. table players

      Array of players with the role.

Example:

-- Basic usage (steamid64 only)
Lyn.Player.FetchByRole("admin", function(err, players)
if err then
-- database error already printed in console by Lyn
print("Error fetching players")
return
end

PrintTable(players)
--[[
{
{ steamid64 = "76561198261855442" },
{ steamid64 = "76561198000000000" }
}
]]
end)

-- With included fields
Lyn.Player.FetchByRole("admin", {"name", "playtime"}, function(err, players)
if err then
-- database error already printed in console by Lyn
print("Error fetching players")
return
end

PrintTable(players)
--[[
{
{ steamid64 = "76561198261855442", name = "Srlion", playtime = 5000 },
{ steamid64 = "76561198000000000", name = "", playtime = 0 }
}
]]
end)