Activity System Guide
This is the guide on how to use our built-in Activity System
try { function() -- Do something end, catch { function(err) Debug.Show_Error("Task Completion", "Failed to complete task: "..err) end } }
OJ = {}
OJ.__index = OJ
function OJ:new()
local self = setmetatable({}, {__index = OJ})
self.gang = nil
self.source = nil
self.is_active = false
self.target_coords = nil
return self
end
function OJ:set_data(gang, source)
if not gang or not(type(gang) == "string") then return end
if not source or not(type(source) == "number") then return end
self.gang = gang
sef.source = nil
end
--- @param gang string
--- @param source number
--- @param opponents string[] - ["ballas", "triads"](example)
function OJ:doActivity(gang, source, opponents)
if self.is_active then return end -- The Activity is currently being done by a gang, so we don't override them.
self:set_data(gang, source)
end
function OJ:sync()
-- Set any data dynamically that is needed in the script
-- EXAMPLE:
self.target_coords = vector3(123, 456, 789)
end
function OJ:finish()
-- Add code here that ends your activity
TriggerEvent('veil-gangs:server:activities:activityCompleted', self.gang, 'activity', self.source) -- Triggers the event for activity completion | The event takes the gang, source and activity name parameters and distributes the rewards to the gang THIS IS NEEDED IN WHATEVER FUNCTION ENDS YOUR ACTIVITY IF IT GIVES OUT REWARDS
end
Activity = OJ:new()
if Activity then
SH_Activities.Possible_Activities['activitykey'].class = Activity
end
-- Handlers
AddEventHandler('onResourceStop', function(resource)
if resource == GetCurrentResourceName() and Activity.is_active then
Activity:finish(false)
end
end)
-- This handler is triggered when the configuration is updated from the UI
AddEventHandler('veil-gangs:shared:updated', function(new_data) -- This can be used both client and server side
Activity:sync() -- Syncs the data from the shared state
end)Last updated