Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: triggerGroupEvent #4

Merged
merged 3 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -90,6 +90,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