/sd-objective

Primary LanguageJavaScriptGNU General Public License v3.0GPL-3.0

sd-objective

It essentially serves as an 'Objective Tracker' that can be seamlessly integrated into any of your scripts, providing players with an aesthetically pleasing UI element that clearly indicates their progress through a certain task.

Feel free to star the repository and check out my store and discord @ Discord: https://discord.gg/samueldev & Store: https://fivem.samueldev.shop For support inquires please create a post in the support-forum channel on discord or create an issue here on Github.

Preview

FiveM_b2944_GTAProcess_66azQB4dB0FiveM_b2944_GTAProcess_P9Et3vNuca

Video Preview

https://www.youtube.com/watch?v=B0CuSTtjuiU&feature=youtu.be

Installation

  1. Clone or download this resource.
  2. Place it in the server's resource directory.
  3. Add the resource to your server config, if needed.

Usage

Exports

Exports are exclusively available on the client and can't be called from server-side files.

  • ShowObjectiveUI(title, description, steps)

    • title: The title of the objective (e.g., "Retrieve the Artifact").
    • description: A brief description of the objective (e.g., "Go to the ancient ruins and retrieve the artifact").
    • steps: Total number of steps required to complete the objective (e.g., if an objective has 4 steps, use 4
  • UpdateProgress(): Call this function to advance the objective's progress by one step.

  • HideObjectiveUI(): Immediately hide the UI, regardless of the objective's progress.

  • UpdateDescription(description): Call this function to change the description of the objective.

Event Handlers

Events can be called from client & server-side.

  • sd-objective:client:showUI (eg. ShowObjectiveUI)
  • sd-objective:client:updateProgress (eg. UpdateProgress)
  • sd-objective:client:hideUI (eg. HideObjectiveUI)
  • sd-objective:client:updateDescription (eg. UpdateDescription)

Example Usage

Utilizing Exports

-- Start an objective
exports['sd-objective']:ShowObjectiveUI('Title', 'Description', 4)

-- Update progress
exports['sd-objective']:UpdateProgress()

-- Update Description
exports['sd-objective']:UpdateDescription(description)

-- Hide the UI
exports['sd-objective']:HideObjectiveUI()

Utilizing Events

-- Start an objective
TriggerClientEvent('sd-objective:client:showUI', source, 'Title', 'Description', 4)

-- Update progress
TriggerClientEvent('sd-objective:client:updateProgress', source)

-- Update Description
TriggerClientEvent('sd-objective:client:updateDescription', source, 'Description')

-- Hide the UI
TriggerClientEvent('sd-objective:client:hideUI', source)

Contextual Example

RegisterNetEvent('sd-oxyrun:client:getBox', function()
    local player = PlayerPedId()

    if gettingBox then
        if not holdingBox then
            if not IsPedInAnyVehicle(player, false) then -- Check if player is not in a vehicle
                amountOfBox = deliveries
                TriggerServerEvent('sd-oxyrun:server:addItem', SupplierPosition, isOnRun)
                if currentBoxes < amountOfBox then
                    currentBoxes = currentBoxes + 1

                    exports['sd-objective']:UpdateProgress()

                    ShowNotification(''.. currentBoxes .. '/' .. amountOfBox .. '')

                    if currentBoxes == amountOfBox then
                        -- either let the objective fade out (if the task has fully ended) or change description.
                    end
                end
            end
        end
    end
end)



-- Call this when starting the box collection task
exports['sd-objective']:ShowObjectiveUI('Box Collection', 'Get a car to collect boxes', amountOfBox * 2 + 3) (Example calculation to determine the amount of steps the oxy run has)

-- Call this when you've gotten a car and now want to change the objective's description to collect boxes.
exports['sd-objective']:UpdateDescription('Go collect boxes from the Supplier')