Multicharacter
Examples
Ready code snippets for the editable hook files.
On this page10 sections
Items on every login
function SC.Editable.GiveStartingItems(src, citizenid) exports.ox_inventory:AddItem(src, 'phone', 1) exports.ox_inventory:AddItem(src, 'water', 2)endOne-time starter kit
GiveStartingItems runs on every login. To grant a kit once, track it in your own table:
CREATE TABLE IF NOT EXISTS `my_starter_kits` ( `citizenid` VARCHAR(60) NOT NULL PRIMARY KEY);function SC.Editable.GiveStartingItems(src, citizenid) local given = MySQL.scalar.await('SELECT 1 FROM my_starter_kits WHERE citizenid = ?', { citizenid }) if given then return end exports.ox_inventory:AddItem(src, 'phone', 1) exports.ox_inventory:AddItem(src, 'id_card', 1) MySQL.insert.await('INSERT INTO my_starter_kits (citizenid) VALUES (?)', { citizenid })endfunction SC.Editable.OnCharacterDeleted(src, citizenid) MySQL.query('DELETE FROM my_starter_kits WHERE citizenid = ?', { citizenid })endStarter vehicle to the garage
Vehicles from Config.StartingItems with kind = 'vehicle' arrive in OnStartingItemsGranted.
local function randomPlate() local chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' local plate repeat plate = '' for _ = 1, 8 do local i = math.random(1, #chars) plate = plate .. chars:sub(i, i) end until not MySQL.scalar.await('SELECT 1 FROM owned_vehicles WHERE plate = ?', { plate }) return plateendfunction SC.Editable.OnStartingItemsGranted(src, citizenid, lines, total) for _, line in ipairs(lines) do if line.kind == 'vehicle' then local plate = randomPlate() MySQL.insert.await('INSERT INTO owned_vehicles (owner, plate, vehicle, stored) VALUES (?, ?, ?, ?)', { citizenid, plate, json.encode({ model = joaat(line.item), plate = plate }), 1, }) end endendlocal function randomPlate() local chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' local plate repeat plate = '' for _ = 1, 8 do local i = math.random(1, #chars) plate = plate .. chars:sub(i, i) end until not MySQL.scalar.await('SELECT 1 FROM player_vehicles WHERE plate = ?', { plate }) return plateendfunction SC.Editable.OnStartingItemsGranted(src, citizenid, lines, total) local license = exports.sc_multicharacter:GetCharacter(src).license for _, line in ipairs(lines) do if line.kind == 'vehicle' then MySQL.insert.await('INSERT INTO player_vehicles (license, citizenid, vehicle, hash, mods, plate, garage, state) VALUES (?, ?, ?, ?, ?, ?, ?, ?)', { license, citizenid, line.item, joaat(line.item), '{}', randomPlate(), 'pillboxgarage', 1, }) end endendfunction SC.Editable.OnStartingItemsGranted(src, citizenid, lines, total) for _, line in ipairs(lines) do if line.kind == 'vehicle' then exports['my-garage']:AddVehicle(citizenid, line.item, 'pillboxgarage') end endendJail or hospital spawn
function SC.Editable.ResolveSpawn(src, character, spawnKey) if exports['my-jail']:isJailed(character.citizenid) then return vector4(1690.9, 2565.3, 45.5, 190.0) end if character.is_dead then return vector4(298.6, -584.7, 43.3, 70.0) end return nilendCustom bucket for apartments and instances
function SC.Editable.ResolveBucket(src, character) if exports['my-apartments']:isInside(character.citizenid) then return exports['my-apartments']:bucketFor(character.citizenid) end return nilendBlock character selection
function SC.Editable.CanSelectCharacter(src, character) if exports['my-whitelist']:isBlocked(character.citizenid) then return false, 'This character is suspended.' end return trueendPhone number for a new character
function SC.Editable.OnCharacterCreated(src, character, isFirst) MySQL.insert('INSERT INTO phone_phones (citizenid, number) VALUES (?, ?)', { character.citizenid, ('555%04d'):format(math.random(0, 9999)), })endfunction SC.Editable.OnCharacterDeleted(src, citizenid) MySQL.query('DELETE FROM phone_phones WHERE citizenid = ?', { citizenid })endAnticheat
function SC.Editable.OnStateChanged(state) exports['my-anticheat']:setEnabled(not state.busy)endHUD
function SC.Editable.OnSelectOpened() exports['my-hud']:hide()endfunction SC.Editable.OnPlayerSpawned(character) exports['my-hud']:show()endSend the job to the HUD
function SC.Editable.OnCharacterLoaded(src, character) TriggerClientEvent('my-hud:setJob', src, character.job)end