A unified API for Garry's Mod admin mods. Write once, work with any supported admin system.
- Download
sh_papi.luafrom GitHub releases. - Add
sh_papi.luato your addon. - Run
includeonsh_papi.lua. (It's already calls AddCSLuaFile for you!)
Not all functions can be used at startup because the loading order of admin mods matters. You can only use Papi once all addons have finished loading.
To put it another way: to make sure the server’s active admin mod is fully loaded, we need a reliable point where everything is consistent. Since an admin mod might load earlier or later, Papi should only be used after all loading is complete.
Any function inside sh_papi.lua that makes use of the internal queue system can be safely called at any stage, even before all addons or admin mods finish loading, since queued actions are automatically executed once everything is ready.
You must call Papi.AddPermission on both server and client.
localactive_mod=Papi.GetActiveAdminMod()
ifactive_modthenprint("Active admin mod:", active_mod) -- e.g. "Lyn", "SAM", "ULX"elseprint("No supported admin mod detected")
endlocalPapi=include("sh_papi.lua")
-- Add a permissionPapi.AddPermission("my_permission", "admin", "MyCategory")
-- Check if player has permissionifPapi.PlayerHasPermission(ply, "my_permission") then-- Do somethingend-- Get all players with permission, returns an array of player, eg. {ply1, ply2, ...}localplayers=Papi.GetPlayersWithPermission("my_permission")
-- Get all permissions, returns an array of permission names, eg. {"kick", "ban", ...}localperms=Papi.GetPermissions()-- Get player's roles, returns an array of role names, eg. {"admin", "moderator", ...}localroles=Papi.GetPlayerRoles(ply)
-- Get all available roles, returns an array of role names, eg. {"admin", "moderator", ...}localallRoles=Papi.GetRoles()
-- Listen for role changes, make sure identifier is unique as it's just a wrapper on top of hook.AddPapi.OnRoleChanges("my_listener", function(ply, steamid64)
-- Called when a player's role changes-- ply can be nil if player is not connectedend)
-- Remove listenerPapi.OnRoleChanges("my_listener", nil)-- Check if SteamID64 is banned (SERVER only)Papi.IsSteamid64Banned("76561198000000000", function(is_banned)
ifis_bannedthenprint("Player is banned")
elseprint("Player is not banned")
endend)-- Kick playerPapi.Commands.Kick(ply, "Reason here")
-- Ban player (length in seconds)Papi.Commands.Ban(ply, 3600, "Ban reason")
-- Ban by SteamID64 (length in seconds)Papi.Commands.BanID64("76561198000000000", 3600, "Ban reason")
-- Unban by SteamID64Papi.Commands.UnbanID64("76561198000000000")
-- Freeze/UnfreezePapi.Commands.Freeze(ply)
Papi.Commands.Unfreeze(ply)
-- Teleport commands (CLIENT only)Papi.Commands.Goto(ply) -- Teleport to playerPapi.Commands.Bring(ply) -- Bring player to youPapi.Commands.Return(ply) -- Return player to original positionDrop the file into your addon and include it where needed:
localPapi=include("path/to/papi.lua")- Automatically detects which admin mod is installed
- Errors if no supported admin mod is found
- Teleport commands (Goto, Bring, Return) are client-side only
- More common commands
- FAdmin support maybe?
- Allow registering custom commands? (Will be simple wrapper functions)
MathsCalculator - Helped implementing half of the admin mods and testing.