> ## Documentation Index
> Fetch the complete documentation index at: https://docs.projectx.gg/llms.txt
> Use this file to discover all available pages before exploring further.

# Open Source

> Open source files available for customization in the Bounty Hunter resource

Most of the core logic in this resource is handled by the bridge. The open source files are provided so you can customize the handler dialog, the payout, add hooks for custom systems, and extend the script without touching escrow.

## opensource/client/client.lua

This file handles zone creation, drawtext, evidence, and the handler dialog.

### Handler Dialog

`ShowDialog(data)` opens the handler conversation with `projectx-ui` when `Config.Dialog = "projectx"`. `AlertDialog(data)` is used for `Config.Dialog = "ox"`, or as a fallback when `projectx-ui` isn't started. You can replace either function to use your own dialog UI.

```lua theme={null}
-- Handler chat with ox_lib (Config.Dialog = "ox", or when projectx-ui isn't started)
function AlertDialog(data)
    return lib.alertDialog({
        header = data.header,
        content = data.text,
        centered = true,
        cancel = data.cancelLabel ~= nil,
        size = data.size or 'm',
        labels = {confirm = data.confirmLabel, cancel = data.cancelLabel}
    })
end
```

***

## opensource/server/server.lua

This file handles dispatch, item/money functions, the payout, logging, the admin command, and exposes several hooks you can use to run custom logic at specific points in a contract.

### Dispatch

`Dispatch(source, override)` sends the homicide alert. `override` can contain `Title`, `Message`, `Code`, and `Coords`, used instead of `Config.Dispatch` and the player's position.

### Payout

> [accordion] PayContract(source, amount)
>
> Pays the contract according to `Config.Payout`. Must return `false` if the player couldn't be paid, in which case the handler asks them to come back.
>
> ```lua theme={null}
> function PayContract(source, amount)
>     if Config.Payout.Type == "item" then
>         return AddItem(source, Config.Payout.Item, amount) ~= false
>     end
>     return AddMoney(source, Config.Payout.Account, amount, "Contract Payout") ~= false
> end
> ```

> [accordion] HasBlacklistedJob(source)
>
> Returns whether the player has a job from `Config.BlacklistedJobs`. Players with a blacklisted job can't take contracts.

### Hooks

> [accordion] SuccessfulStep(source, step)
>
> Called whenever a player completes a step. `step` is `"Proof"` (photo taken, once per target) or `"Contract"` (contract paid out).
>
> ```lua theme={null}
> function SuccessfulStep(source, step)
>     if step == "Proof" then
>         -- if Config.SkillSystem then exports['projectx-bridge']:AddExperience(source, 'criminal', 5) end
>     elseif step == "Contract" then
>         -- if Config.SkillSystem then exports['projectx-bridge']:AddExperience(source, 'criminal', 20) end
>     end
> end
> ```

> [accordion] FailedStep(source, step)
>
> Called whenever a player fails a step. Use this to remove XP, items, or apply penalties.
>
> ```lua theme={null}
> function FailedStep(source, step)
>     -- Add whatever you want on a failed step, for example removing exp or money
> end
> ```

> [accordion] InitialCheck(src, approach)
>
> Called before a contract is offered. `approach` is `"Handler"`. Return `false` to block it, for example for a group check, a tablet / phone integration, or a required item.
>
> ```lua theme={null}
> function InitialCheck(src, approach)
>     return true
> end
> ```

> [accordion] ContractCompleteHook(source, tier, payout, contract)
>
> Called after a contract is paid out. `tier` is the `Config.Tiers` key, and `contract` contains the weapon request and one entry per target:
>
> ```lua theme={null}
> contract = {
>     Request = "blade", -- Config.WeaponClasses key, or nil
>     Targets = {
>         {Name = "...", Location = "legion", Kill = {Cause = ..., Distance = 42.0, Headshot = true, Silenced = false}},
>     },
> }
> ```
>
> ```lua theme={null}
> function ContractCompleteHook(source, tier, payout, contract)
>     -- TriggerEvent('my-leaderboard:addKill', source, tier, payout)
> end
> ```

> [accordion] ContractFailedHook(source, tier, reason)
>
> Called when a contract fails. `source` can be `nil` if the owner is offline. `reason` is a locale key: `"target_escaped"`, `"someone_else"`, `"contract_expired"`, `"return_expired"`, `"too_many_innocents"`, `"target_vanished"`, `"spawn_failed"`, or `"contract_cancelled"`.
>
> ```lua theme={null}
> function ContractFailedHook(source, tier, reason)
>     -- Custom penalty or logging
> end
> ```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.