HasGroup
The SD.HasGroup module offers a versatile and dynamic approach to verifying player affiliations or roles within various frameworks. This module adapts to multiple frameworks, such as ESX and QB/QBX, providing tailored checks for player groups based on predefined or dynamic criteria.
Overview
Purpose: Determines if a player belongs to specific groups or roles defined in a game's framework, which may include jobs, duties, or other organizational roles.
CheckForDuty: A configurable boolean that, when set to true, requires that players be on duty for their group affiliation to be recognized (relevant in certain contexts like law enforcement roles).
Parameters
source(any): The identifier for the player. Typically a server ID or similar unique identifier.filter(string|table): The group or groups to check against. Can be a single group name, an array of names, or a hash table specifying minimum grades for roles.
Filter Types
String: Direct comparison to a single group name.
Array: Check against multiple group names; the player must belong to at least one.
Hash: Maps group names to minimum grade levels the player must meet or exceed.
Usage Example
Checking Single Group Membership
local isOfficer = SD.HasGroup(source, 'police')Checking Membership in Any Listed Group
local isInService = SD.HasGroup(source, {'police', 'ambulance'})Checking Membership with Grade Requirements
local canCommand = SD.HasGroup(source, {police = 5, sheriff = 3})Cop Callback
SD.Callback.Register('sd-oilrig:server:GetCops', function(source)
local players = GetPlayers()
local amount = 0
for i=1, #players do
local player = tonumber(players[i])
if SD.HasGroup(player, Config.PoliceJobs) then
amount = amount + 1
end
end
return(amount)
end)Last updated