# Functions/Events

### client/editable-main.lua

### Command-Based Job Start

Allows players to start duty using a command defined in `Config.JobStartCommand`.

```lua
if Config.JobStartMethod == "command" then
    RegisterCommand(Config.JobStartCommand, function()
        if not isWorking then
            StartJob()
            print("You have started your duty via command.")
        else
            print("You are already on duty.")
        end
    end, false)
end
```

* Prevents starting the job multiple times
* Command permissions can be restricted
* Simple and lightweight

***

### ox\_target Integration

Creates an interactive **target zone** using `ox_target`.

```lua
elseif Config.JobStartMethod == "oxtarget" then
    if exports.ox_target then
        local eventName = "bordercontrol:client:startjob"

        exports.ox_target:addBoxZone({
            coords = Config.Positions.jobStart,
            size = vec3(1, 1, 2),
            rotation = 45,
            debug = false,
            options = {
                {
                    name = 'start_duty_ox',
                    event = eventName,
                    icon = 'fa-solid fa-play',
                    label = Config.language.startimmigrationduty,
                    canInteract = function()
                        return not isWorking
                    end,
                }
            }
        })

        RegisterNetEvent(eventName, StartJob)
    else
        print("[ERROR] ox_target is not running.")
    end
end
```

#### Notes

* Interaction only appears if the player is **not on duty**
* Requires `ox_target` to be running
* Clean and immersive interaction

***

### qb-target Integration

Uses `qb-target` to allow players to start duty through interaction zones.

```lua
elseif Config.JobStartMethod == "qbtarget" then
    if exports['qb-target'] then
        local eventName = "bordercontrol:client:startjob"

        exports['qb-target']:AddBoxZone(
            "start_immigration_duty",
            Config.Positions.jobStart,
            2.0,
            2.0,
            {
                name = "start_immigration_duty",
                heading = 0.0,
                debugPoly = false,
                minZ = Config.Positions.jobStart.z - 1.0,
                maxZ = Config.Positions.jobStart.z + 1.0,
            },
            {
                options = {
                    {
                        type = "client",
                        event = eventName,
                        icon = "fas fa-play",
                        label = Config.language.startimmigrationduty,
                        canInteract = function()
                            return not isWorking
                        end,
                    },
                },
                distance = 2.5
            }
        )

        RegisterNetEvent(eventName, StartJob)
    else
        print("[ERROR] qb-target is not running.")
    end
end
```

***

### Standalone Mode (No Target Dependency)

Fallback system that works without any targeting resource.

```lua
else
    Citizen.CreateThread(function()
        while true do
            local wait = 1000
            local playerCoords = GetEntityCoords(PlayerPedId())
            local distance = #(playerCoords - Config.Positions.jobStart)

            if distance < 2.0 then
                wait = 5
                DrawText3D(
                    Config.Positions.jobStart,
                    Config.language.keystartimmigrationduty
                )

                if IsControlJustReleased(0, 38) then
                    StartJob()
                end
            end

            Citizen.Wait(wait)
        end
    end)
end
```

* Displays floating text when nearby
* Player presses **E** to start duty
* Optimized loop for performance

***

### 3D Text Helper

Displays floating text in the world.

```lua
function DrawText3D(coords, text)
    local onScreen, x, y = World3dToScreen2d(coords.x, coords.y, coords.z)
    if onScreen then
        SetTextScale(0.35, 0.35)
        SetTextFont(4)
        SetTextProportional(1)
        SetTextColour(255, 255, 255, 215)
        SetTextEntry("STRING")
        SetTextCentre(1)
        AddTextComponentString(text)
        DrawText(x, y)
    end
end
```

***

### Cross-Framework Notifications

Automatically uses QBCore notifications if available.

```lua
function crossNotify(QB, MSG, SCCS)
    if QB then
        QB.Functions.Notify(MSG, (SCCS and "error" or "success"))
    else
        TriggerEvent('chat:addMessage', {
            color = {255, 0, 0},
            args = {Config.language.job, MSG}
        })
    end
end
```

***

### Shift Start Event

Triggered when the job begins.

```lua
RegisterNetEvent('enyo-chekpointsim:startShift')
AddEventHandler('enyo-chekpointsim:startShift', function()
    -- Example usage:
    -- SendNUIMessage({ action = "hideHUD" })
    -- print("Shift started")
end)
```

***

### Shift End Event

Triggered when the job ends.

```lua
RegisterNetEvent('enyo-chekpointsim:endShift')
AddEventHandler('enyo-chekpointsim:endShift', function(CorruptionCaughtAmmount)
    -- Example usage:
    -- SendNUIMessage({ action = "showHUD" })
    -- print("Shift ended")
end)
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://enyo-scripts.gitbook.io/documentations/fivem-scripts/immigration-checkpoint-simulator/functions-events.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
