HTNFW Script Conversion Guide

Share

HTNFW Script Conversion Guide

This guide is for converting scripts from ESX/QBCore to HTNFW.

Rules You Must Follow

  1. Save ownership with cid (characters.id), not source.
  2. Use framework exports for money updates. Do not manually change cash/bank vars.
  3. Always nil-check player data before using it.

Convert One Script In This Order

  1. Replace server player fetch.
    • Use: exports['htn-framework']:CharacterInformation(source, 'all')
  2. Replace client player fetch.
    • Use: exports['htn-framework']:getCharacterInfo('all')
  3. Replace money logic.
    • Use: exports['htn-framework']:CurrencyUpdate(...)
  4. Replace job checks.
    • Use: character.job.name, character.job.rank, character.job.lable, character.job.header
  5. Replace DB owner id fields.
    • Old: source
    • New: cid / stateId
  6. Test reconnect and ownership.
    • Data should still belong to correct character after relog.

Quick API Calls

Server

  • Full player data:
    • exports['htn-framework']:CharacterInformation(source, 'all')
  • Player cid only:
    • exports['htn-framework']:CharacterInformation(source, 'id')
  • Add/remove money:
    • exports['htn-framework']:CurrencyUpdate(stateId, 'cash' or 'bank', {_source=source, update=amount, status=true or false})
    • status=true adds money
    • status=false removes money
  • Get online player by cid:
    • exports['htn-framework']:GetPlayerFromCid(cid)
  • Permission check:
    • exports['htn-framework']:perm({comp='hasPermission', data={sourceId=src, event='permission_name'}})

Client

  • Full local player data:
    • exports['htn-framework']:getCharacterInfo('all')
  • Job only:
    • exports['htn-framework']:getCharacterInfo('job')
  • Cash/bank only:
    • exports['htn-framework']:getCharacterInfo('currency')

Copy/Paste Examples

Server: Get Player + CID

local char = exports['htn-framework']:CharacterInformation(source, 'all')
if not char then return end

local cid = char.id
local fullName = (char.first_name or '') .. ' ' .. (char.last_name or '')

Server: Add/Remove Money

local char = exports['htn-framework']:CharacterInformation(source, 'all')
if not char then return end

-- Add 500 bank
exports['htn-framework']:CurrencyUpdate(char.id, 'bank', {
    _source = source,
    update = 500,
    status = true
})

-- Remove 200 cash
exports['htn-framework']:CurrencyUpdate(char.id, 'cash', {
    _source = source,
    update = 200,
    status = false
})

Client: Job/Currency

local p = exports['htn-framework']:getCharacterInfo('all')
if not p then return end

local jobName = p.job and p.job.name or 'unemployed'
local cash = p.currency and p.currency.cash or 0
local bank = p.currency and p.currency.bank or 0

Server: Set Job

TriggerEvent('htn-framework:UpdatePlayerJob', targetStateId, {
    job = 'police',
    rank = 2
})