Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/rework-ui' into rew…
Browse files Browse the repository at this point in the history
…ork-ui
  • Loading branch information
solareon committed Jun 28, 2024
2 parents fdce15a + bde14af commit 9c13834
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
26 changes: 19 additions & 7 deletions server/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,25 @@ function api.pNotifyGroup(groupID, header, msg)
return lib.print.error('pNotifyGroup was sent an invalid groupID :'..groupID)
end

lib.triggerClientEvent('slrn_groups:client:CustomNotification', group:getGroupMembers(),
header or 'NO HEADER',
msg or 'NO MSG'
)
group:triggerGroupEvent('slrn_groups:client:CustomNotification', header or 'NO HEADER', msg or 'NO MSG')
end
utils.exportHandler('pNotifyGroup', api.pNotifyGroup)

---Triggers a client event for each member of a group (stolen from ox_lib)
---@param eventName string
---@param groupId number
---@param ... any
function api.triggerGroupEvent(eventName, groupId, ...)
local group = groups[groupId]

if not group then
return lib.print.error('triggerGroupEvent was sent an invalid groupID :'..groupId)
end

group:triggerGroupEvent(eventName, ...)
end
utils.exportHandler('triggerGroupEvent', api.triggerGroupEvent)

---@class BlipData
---@field entity number?
---@field netId number?
Expand All @@ -65,7 +77,7 @@ function api.CreateBlipForGroup(groupID, name, data)
return lib.print.error('CreateBlipForGroup was sent an invalid groupID :'..groupID)
end

lib.triggerClientEvent('groups:createBlip', group:getGroupMembers(), name, data)
group:triggerGroupEvent('groups:createBlip', name, data)
end
utils.exportHandler('CreateBlipForGroup', api.CreateBlipForGroup)

Expand All @@ -79,7 +91,7 @@ function api.RemoveBlipForGroup(groupID, name)
return lib.print.error('RemoveBlipForGroup was sent an invalid groupID :'..groupID)
end

lib.triggerClientEvent('slrn_groups:client:RemoveBlipForGroup', group:getGroupMembers(), name)
group:triggerGroupEvent('groups:removeBlip', name)
end
utils.exportHandler('RemoveBlipForGroup', api.RemoveBlipForGroup)

Expand Down Expand Up @@ -260,7 +272,7 @@ function api.setJobStatus(groupID, status, stages)
group.status = status
group.stage = stages

lib.triggerClientEvent('slrn_groups:client:updateGroupStage', group:getGroupMembers(), status, stages)
group:triggerGroupEvent('slrn_groups:client:updateGroupStage', status, stages)
end
utils.exportHandler('setJobStatus', api.setJobStatus)

Expand Down
12 changes: 12 additions & 0 deletions server/groups.lua
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@ end



---Triggers an event for all members of the group. (Stolen from ox_lib so thanks to the original author)
---@param eventName string
---@param ... any
function groups:triggerGroupEvent(eventName, ...)
local payload = msgpack.pack_args(...)
local payloadLen = #payload

for i = 1, #self.members do
TriggerClientEventInternal(eventName, self.members[i].Player --[[@as string]], payload, payloadLen)
end
end




Expand Down

0 comments on commit 9c13834

Please sign in to comment.