Server
Functions

Server functions

getPlayer

This returns the player and contains player data & player functions.

parameters:

  • source: number

returns:

  • player: table
local player = NDCore.getPlayer(source)

getPlayers

If no key or no value is passed then all active players will be returned. If returnArray is true then players will be returned in an array otherwise an object with their source as the key.

parameters:

  • key: string
  • value: any
  • returnArray: boolean

returns:

  • players: table
    • Contains all players with matching key value data.

NDCore.getPlayers(key, value, returnArray)
Array example
local players = NDCore.getPlayers("job", "windowcleaner", true)
for i=1, #players do
    local ply = players[i]
    print(ply.fullname)
end
Object example
local players = NDCore.getPlayers("job", "windowcleaner", false)
for playerSource, playerData in pairs(players) do
    print(playerData.fullname)
end

getPlayerServerInfo

Returns identifiers & discord information, same as in player data and getDiscordInfo.

parameters:

  • source: number

returns:

  • info: table
    • identifiers: table
    • discord: table
local info = NDCore.getPlayerServerInfo(source)

loadSQL

This will run oxmysql query (opens in a new tab) for the content in an sql file.

parameters:

  • fileLocation: string
  • resource: string

returns:

  • success: boolean
local success = NDCore.loadSQL(fileLocation, resource)

getDiscordInfo

If a user is not found by discordUserId this will return nil otherwise it will return this info:

parameters:

  • discordUserId: string

returns:

  • discordInfo: table
    • nickname: string
    • user: string
    • roles: table
local discordInfo = NDCore.getDiscordInfo(discordUserId)

enableMultiCharacter

ND Core is single character by defualt unless this is used, if you're making a character selection resource you should use this to disable single character. ND Characters utilises this function.

parameters:

  • enable: boolean
NDCore.enableMultiCharacter(enable)

newCharacter

Create a new player character to the database.

parameters

  • source: number
  • info: table
    • firstname: string
    • lastname: string
    • dob: string
    • gender: string
    • cash: number
    • bank: number
    • groups: table
    • metadata: table
    • inventory: table

returns

  • player: table

This returns the player and contains player data & player functions

NDCore.newCharacter(source, info)
example
local player = NDCore.newCharacter(source, {
    firstname = "John",
    lastname = "Doe",
    dob = "29/03/1999",
    gender = "male",
    cash = 2500,
    bank = 8000
})
 
print(player.firstname) -- John

fetchCharacter

Fetch a character from the database, this will use the core:characterIdentifier in ndcore.cfg it's important to pass the source if you want to check if a source owns the character.

parameters

  • identifier: string
  • source: number

returns

  • player: table

This returns the player and contains player data & player functions

local character = NDCore.fetchCharacter(identifier, source)

fetchAllCharacters

Fetch all character a player owns. The returned table consisits of keys that are the character ids and the value is character info without any player functions.

parameters

  • source: number

returns*

  • characters: table
local characters = NDCore.fetchAllCharacters(source)

setActiveCharacter

Set the character as the current playing one for the player.

parameters

  • source: number
  • id: number

The id parameter is the character id from the player data

returns

  • player: table

This returns the player and contains player data & player functions

local player = NDCore.setActiveCharacter(source, id)

Vehicles

getVehicleById

Get vehicle data from a vehicle id.

parameters

  • id: number | string

returns

  • data: table
    • id: number | string
    • owner: number
    • plate: string
    • properties: table
    • stored: boolean
    • impounded: boolean
    • available: boolean

a vehicle can only be available if it's not impounded and it's stored. Stolen doesn't matter it's just used in things like police mdt.

local vehicle = NDCore.getVehicleById(id)
print(json.encode(vehicle, {indent=true}))
--[[
    {
        id = 5,
        owner = 25,
        plate = "1234ABCD",
        properties = json.decode(vehicle.properties) or {},
        stored = true,
        impounded = false,
        stolen = false,
        available = true
    }
]]

getVehicle

Get NDCore vehicle from an entity.

parameters

  • entity: number

returns

  • vehicle: table

view vehicle

local vehicle = NDCore.getVehicle(entity)

getVehicles

Get a table with all the characters owned vehicles.

parameters

  • characterId: number

returns

  • vehicles: table

contains the same info as getVehicleById

NDCore.getVehicles(characterId)
example
local player = NDCore.getPlayer(source)
local vehicles = NDCore.getVehicles(player.id)
for i=1, #vehicles do
    local veh = vehicles[i]
    print(json.encode(veh, {indent=true}))
    --[[
        {
            id = 5,
            owner = 25,
            plate = "1234ABCD",
            properties = json.decode(vehicle.properties) or {},
            stored = true,
            impounded = false,
            stolen = false,
            available = true
        }
    ]]
end

giveVehicleAccess

Give a player keys to a vehicle.

parameters

  • source: number
  • vehicle: entity
  • access: boolean
NDCore.giveVehicleAccess(source, vehicle, access)

createVehicle

Spawns a vehicle.

parameters

  • info: table
    • owner: number
    • vehicleId: number
    • properties: table
    • coords: vec3 | vec4
    • heading: number
    • model: number
    • keys: table
    • source: number

if no vehicleId is passed a temporary one will be created.

returns

  • vehicle: table

view vehicle

local vehicle = NDCore.createVehicle()
example
-- works like this:
NDCore.createVehicle({
    model = `taxi`,
    coords = vec4(x, y, z, w)
})
 
-- also like this:
NDCore.createVehicle({
    model = `taxi`,
    coords = vec3(x, y, z)
    heading = w
})
 
-- also can add owner that will receive keys.
local player = NDCore.getPlayer(source)
NDCore.createVehicle({
    model = `taxi`,
    coords = vec4(x, y, z, w),
    owner = player.id
})
 
-- more key access can be given.
local player = NDCore.getPlayer(source)
NDCore.createVehicle({
    model = `taxi`,
    coords = vec4(x, y, z, w),
    keys = {
        [player.id] = true
    }
})

transferVehicleOwnership

This will change the owner of the vehicle completely and even take and give keys, remove and add map blip and more.

parameters

  • vehicleId: number | string
  • fromSource: number
  • toSource: number

returns

  • success: boolean
NDCore.transferVehicleOwnership(vehicleId, fromSource, toSource)

setVehicleOwned

This function will register the vehicle owned and add it to the database.

parameters

  • playerId: number
  • properties: table
  • stored: boolean

properties should include information about the vehicle ox_lib (opens in a new tab) has a function to get a vehicles properties.

returns

  • vehicleId
local vehicleId = NDCore.setVehicleOwned(playerId, properties, stored)
example
local player = NDCore.getPlayer(source)
local vehicleId = NDCore.setVehicleOwned(player.id, properties, true)

shareVehicleKeys

give a player access to another players vehicle as if they are next to eachother and hand the keys.

  • source: number
  • targetSource: number
  • vehicle: entity

returns

  • success: boolean
local success = NDCore.shareVehicleKeys(source, targetSource, vehicle)

spawnOwnedVehicle

Spawns a vehicle that's owned by the player and checks for availability

parameters

  • source number
  • vehicleId number
  • coords vector4

returns

  • vehicle: table

view vehicle

local vehicle = NDCore.spawnOwnedVehicle(source, vehicleId, coords)