Activity System Guide
This is the guide on how to use our built-in Activity System
Unique Features
Ability to script your own activities that can be done by a single gang or even multiple
Add in functions that LUA doesn't normally have We have added in the try and catch functions to aid with your scripting to avoid any run time errors
try { function() -- Do something end, catch { function(err) Debug.Show_Error("Task Completion", "Failed to complete task: "..err) end } }
How To
Each activity is a class with a entry point on the Server Side
.
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)
See the above example. This is the minimum code needed to run an activity.
The set_data
function sets the data for the activity primarily the gang and the triggering source
The doActivity
function is the trigger point for the activity and that is the function that will be called by the System
The sync
function is called whenever the Configuration for the script is updated, this can be used to update the active activity with any changes to the config that affects it
The finish
function is the exit point of your Activity, this is called by YOU
when you script the activity
if Activity then
SH_Activities.Possible_Activities['activitykey'].class = Activity
end
The above code is what registers your Activity for the System to recognize and trigger it when requested
The activity class needs 3 Mandatory Variables
self.gang
, self.source
and self.is_active
Without these the system will be unable to use your activity
Registering Your Activity
Located in the activities/shared/sh_activities.lua
file is the skeleton for all the activities.
It should look like this by default
SH_Activities.Possible_Activities = {
['gangshipment'] = {
label = 'Gang Shipment',
gangsNeeded = 1, -- Number of gangs needed to start the activity
description = "Transport and defend your gang's valuable shipment.", -- Description of the activity
icon = "fa-truck-fast", -- Font Awesome icon
timeLimit = 40, -- In Minutes
reward = {
notoriety = {
min = 1,
max = 3
}
}
},
}
Simply add your activity in this table for the 1st step of registration, here is a template
['activity'] = {
label = "Label Here",
gangsNeeded = 1, -- if more then 1, then multiple gangs can be selected VIA the activites page
description = "Description Here",
icon = "fontawesomeiconhere",
timeLimit = 5,
reward = {
notoriety = {
min = 2,
max = 5
},
money = {
min = 100,
max = 1000
}
}
}
Available Functions Some built-in functions can assist you with making unique activities. Please see Available Functions
Last updated