Code Snippets
This purpose of this page is to automate as much as possible so customers can solve problems their self without needing to open discord support tickets.

Translate

Note: Not all of these code snippets are guaranteed to work for your server. They are code snippets provided by the Codesign Development Team that were requested by the community for their specific use case or provided to us by the community for their specific use case. We post them here in the event that you may find them useful.

Snippets

ESX v1.1 to v1.final (accounts)

If you currently use esx version 1.1 and you are wanting to switch to esx version 1.final, you can use this chat command to migrate your players bank/cash from the money and bank column to the accounts column (assuming you have already added the accounts column inside the users database table).
1
RegisterCommand('esx_1final', function(source)
2
if source == 0 then
3
local database_result = DatabaseQuery('SELECT identifier, money, bank FROM users')
4
for cd = 1, #database_result do
5
SQL('UPDATE users SET [email protected] WHERE [email protected]', {['@accounts'] = json.encode({black_money = 0, money = database_result[cd].money or 0, bank = database_result[cd].bank or 0}), ['@identifier'] = database_result[cd].identifier})
6
print(string.format('^1%s^0/^1%s^0 ^3Identifier:^0 %s ^3Money:^0 %s ^3Bank:^0 %s^0', cd, #database_result, database_result[cd].identifier, database_result[cd].money or 0, database_result[cd].bank or 0))
7
end
8
end
9
end)
Copied!

Dispatch & Gcphone

If you want your players to be able to send police and ambulance dispatch notifications from their phone, replace the existing server event with the one provided below.
Note: This will only work on OneSync.
1
RegisterServerEvent('gcPhone:sendMessage')
2
AddEventHandler('gcPhone:sendMessage', function(phoneNumber, message, gpsData)
3
local _source = source
4
local ped_coords = GetEntityCoords(GetPlayerPed(_source))
5
local identifier = ESX.GetPlayerFromId(_source).identifier
6
addMessage(_source, identifier, phoneNumber, message, gpsData)
7
8
if phoneNumber == 'police' then
9
TriggerClientEvent('cd_dispatch:AddNotification', -1, {
10
job = 'police',
11
coords = ped_coords,
12
title = 'Police Assistance',
13
message = message,
14
flash = 0,
15
unique_id = tostring(math.random(0000000,9999999)),
16
blip = {
17
sprite = 137,
18
scale = 1.0,
19
colour = 38,
20
flashes = false,
21
text = 'Civilian Call',
22
time = (5*60*1000),
23
sound = 1,
24
}
25
})
26
elseif phoneNumber == 'ambulance' then
27
TriggerClientEvent('cd_dispatch:AddNotification', -1, {
28
job = 'ambulance',
29
coords = ped_coords,
30
title = 'Medical Assistance',
31
message = message,
32
flash = 0,
33
unique_id = tostring(math.random(0000000,9999999)),
34
blip = {
35
sprite = 61,
36
scale = 1.0,
37
colour = 1,
38
flashes = false,
39
text = 'Civilian Call',
40
time = (5*60*1000),
41
sound = 1,
42
}
43
})
44
end
45
end)
Copied!

mf-multi to cd_multicharacter

This command will convert your whole database's player identifier structure from the one mf-multi requires to the one cd_multicharacter requires. But make sure you do this after you have fully installed the cd_multicharacter.
This has been posted due to numerous requests.
1
RegisterCommand('cd_multicharacter_conversion', function(source)
2
if source == 0 then
3
print('^1CODESIGN MULTICHARACTER IDENTIFIER CONVERSION STARTED ...^0')
4
local max_characters = 5 --Enter the maximm amount of characters a player can possibly have in your server.
5
local mf_multichar_id = {}
6
for cd = 1, max_characters do
7
table.insert(mf_multichar_id, tostring(cd)..':')
8
end
9
for cd_1 = 1, #Config.DatabaseTables do
10
local DatabaseTables = Config.DatabaseTables[cd_1]
11
local result = DatabaseQuery('SELECT '..DatabaseTables.column_name..' FROM '..DatabaseTables.table_name)
12
for cd_2 = 1, #result do
13
local old_identifier = result[cd_2][DatabaseTables.column_name]
14
if old_identifier ~= nil then
15
for cd_3 = 1, #mf_multichar_id do
16
if string.sub(old_identifier, 1, 2) == mf_multichar_id[cd_3] then
17
local multichar_id = string.sub(old_identifier, 1, 1)
18
local empty_identifier = old_identifier:sub(3)
19
local new_identifier = string.format('Char%s:%s', multichar_id, empty_identifier)
20
DatabaseQuery('UPDATE '..DatabaseTables.table_name..' SET '..DatabaseTables.column_name..'="'..new_identifier..'" WHERE '..DatabaseTables.column_name..'="'..old_identifier..'"')
21
print(string.format('^1%s^0/^1%s^0 - ^3Database Table:^0 %s ^3Database Column:^0 %s ^3Old Identifier:^0 %s: ^3New Identifier:^0 %s', cd_2, #result, DatabaseTables.table_name, DatabaseTables.column_name, old_identifier, new_identifier))
22
end
23
end
24
end
25
end
26
end
27
print('^2CODESIGN MULTICHARACTER IDENTIFIER CONVERSION FINISHED!^0')
28
end
29
end)
Copied!

Housing Scripts & CD Garage

We have permission from each resource developer to post these code snippets below.

Allhousing v2

Allhousing compatibility with the Codesign Garage.
Inside the menus_esx.lua replace the existing 2 functions with the ones provided below.
ESXGarageOwnerMenu
ESXGarageOwnedMenu
1
ESXGarageOwnerMenu = function(d)
2
local ped = GetPlayerPed(-1)
3
if IsPedInAnyVehicle(ped,false) then
4
local veh = GetVehiclePedIsUsing(ped)
5
local props = GetVehicleProperties(veh)
6
local ownerInfo = Callback("Allhousing:GetVehicleOwner",props.plate)
7
local canStore = false
8
local identifier = GetPlayerIdentifier()
9
10
if d.Owner == identifier then
11
canStore = true
12
else
13
for k,v in pairs(d.HouseKeys) do
14
if v.identifier == identifier then
15
canStore = true
16
break
17
end
18
end
19
end
20
21
if canStore then
22
local doStore = false
23
if ownerInfo.owned and ownerInfo.owner then
24
doStore = true
25
elseif ownerInfo.owned and Config.StoreStolenPlayerVehicles then
26
doStore = true
27
end
28
29
if doStore then
30
TriggerEvent('cd_garage:StoreVehicle_Main', 1, false)
31
TriggerServerEvent("Allhousing:VehicleStored",d.Id,props.plate,props)
32
ShowNotification(Labels["VehicleStored"])
33
else
34
ShowNotification(Labels["CantStoreVehicle"])
35
end
36
else
37
ShowNotification(Labels["CantStoreVehicle"])
38
end
39
FreezeEntityPosition(GetPlayerPed(-1),false)
40
else
41
ESX.UI.Menu.Open( 'default', GetCurrentResourceName(), 'choosegarage', -- Replace the menu name
42
{
43
title = ('Garage'),
44
align = 'center', -- Menu position--top-left
45
elements = { -- Contains menu elements
46
{label = ('Inside Garage'), value = 'ingarage'},
47
{label = ('Outside Garage'), value = 'outgarage'}
48
}
49
},
50
function(data, menu) -- This part contains the code that executes when you press enter
51
if data.current.value == 'ingarage' then
52
TriggerEvent('cd_garage:PropertyGarage', 'inside')
53
menu.close()
54
FreezeEntityPosition(GetPlayerPed(-1),false)
55
elseif data.current.value == 'outgarage' then
56
TriggerEvent('cd_garage:PropertyGarage', 'quick')
57
menu.close()
58
FreezeEntityPosition(GetPlayerPed(-1),false)
59
end
60
end,
61
function(data, menu) -- This part contains the code that executes when the return key is pressed.
62
menu.close() -- Close the menu
63
FreezeEntityPosition(GetPlayerPed(-1),false)
64
end
65
)
66
end
67
end
Copied!
1
ESXGarageOwnedMenu = function(d)
2
local plyPed = GetPlayerPed(-1)
3
if IsPedInAnyVehicle(plyPed,false) then
4
local veh = GetVehiclePedIsUsing(plyPed)
5
local props = GetVehicleProperties(veh)
6
local ownerInfo = Callback("Allhousing:GetVehicleOwner",props.plate)
7
local canStore = false
8
local identifier = GetPlayerIdentifier()
9
10
if d.Owner == identifier then
11
canStore = true
12
else
13
for k,v in pairs(d.HouseKeys) do
14
if v.identifier == identifier then
15
canStore = true
16
break
17
end
18
end
19
end
20
21
if canStore then
22
local doStore = false
23
if ownerInfo.owned and ownerInfo.owner then
24
doStore = true
25
elseif ownerInfo.owned and Config.StoreStolenPlayerVehicles then
26
doStore = true
27
end
28
29
if doStore then
30
TriggerEvent('cd_garage:StoreVehicle_Main', 1, false)
31
TriggerServerEvent("Allhousing:VehicleStored",d.Id,props.plate,props)
32
ShowNotification(Labels["VehicleStored"])
33
else
34
ShowNotification(Labels["CantStoreVehicle"])
35
end
36
else
37
ShowNotification(Labels["CantStoreVehicle"])
38
end
39
FreezeEntityPosition(GetPlayerPed(-1),false)
40
else
41
local myId = GetPlayerIdentifier()
42
for k,v in pairs(d.HouseKeys) do
43
if v.identifier == myId then
44
DoOpenESXGarage(d)
45
return
46
end
47
end
48
49
if not Config.GarageTheft then
50
FreezeEntityPosition(GetPlayerPed(-1),false)
51
return
52
end
53
54
if Config.LockpickRequired then
55
local hasItem = CheckForLockpick()
56
if not hasItem then
57
ShowNotification(Labels['NoLockpick'])
58
FreezeEntityPosition(GetPlayerPed(-1),false)
59
return
60
end
61
end
62
63
while not HasAnimDictLoaded("[email protected]_cracking") do RequestAnimDict("[email protected]_cracking"); Citizen.Wait(0); end
64
TaskPlayAnim(plyPed, "[email protected]_cracking", "idle_base", 1.0, 1.0, -1, 1, 0, 0, 0, 0 )
65
Wait(2000)
66
67
if Config.UsingLockpickV1 then
68
TriggerEvent("lockpicking:StartMinigame",4,function(didWin)
69
if didWin then
70
ClearPedTasksImmediately(plyPed)
71
DoOpenESXGarage(d)
72
else
73
ClearPedTasksImmediately(plyPed)
74
TriggerServerEvent("Allhousing:BreakLockpick")
75
end
76
FreezeEntityPosition(GetPlayerPed(-1),false)
77
end)
78
elseif Config.UsingLockpickV2 then
79
exports["lockpick"]:Lockpick(function(didWin)
80
if didWin then
81
ClearPedTasksImmediately(plyPed)
82
DoOpenESXGarage(d)
83
ShowNotification(Labels["LockpickSuccess"])
84
else
85
ClearPedTasksImmediately(plyPed)
86
TriggerServerEvent("Allhousing:BreakLockpick")
87
ShowNotification(Labels["LockpickFailed"])
88
end
89
FreezeEntityPosition(GetPlayerPed(-1),false)
90
end)
91
else
92
if Config.UsingProgressBars then
93
exports["progressBars"]:startUI(Config.LockpickTime * 1000,Labels["ProgressLockpicking"])
94
end
95
Wait(Config.LockpickTime * 1000)
96
if math.random(100) < Config.LockpickFailChance then
97
local plyPos = GetEntityCoords(GetPlayerPed(-1))
98
local zoneName = GetNameOfZone(plyPos.x,plyPos.y,plyPos.z)
99
if Config.LockpickBreakOnFail then
100
TriggerServerEvent("Allhousing:BreakLockpick")
101
end
102
ShowNotification(Labels["LockpickFailed"])
103
for k,v in pairs(Config.PoliceJobs) do
104
TriggerServerEvent("Allhousing:NotifyJobs",k,"Someone is attempting to break into a garage at "..zoneName)
105
end
106
ClearPedTasksImmediately(plyPed)
107
else
108
ShowNotification(Labels["LockpickSuccess"])
109
ClearPedTasksImmediately(plyPed)
110
DoOpenESXGarage(d)
111
end
112
FreezeEntityPosition(GetPlayerPed(-1),false)
113
end
114
end
115
end
Copied!

SSComplete Housing

SSComplete Housing compatibility with the Codesign Garage.
Inside the config.lua replace the existing Config.Parking table with the one provided below.
1
Config.Parking = {
2
ScriptParking = true, -- SET TRUE TO USE SCRIPT PARKING FOR EACH HOME(SELECT PARKING TYPE PER HOUSE IN GAME), SET FALSE TO USE A PRIVATE PARKING SYSTEM(FUNCTION CHOSEN IN CONFIG.CREATION TABLE)
3
AllowAll = true, -- SET TRUE TO ALLOW ANYONE TO PARK IN ANY OWNED PARKING SPOT, FALSE TO ALLOW ONLY THE OWNER OR KEY HOLDER
4
AllowNil = true, -- SET TRUE TO ALLOW PLAYERS TO USE NON-OWNED HOME PARKING SPOTS
5
GarageStoreEvent = function(ped, veh)
6
TriggerEvent('cd_garage:StoreVehicle_Main', 1, false)
7
end,
8
GarageOpenEvent = function(location)
9
TriggerEvent('cd_garage:PropertyGarage', 'quick')
10
end
11
}
Copied!

Loaf Housing

Loaf Housing compatibility with the Codesign Garage.
Inside the client/main.lua replace the existing thread with the one provided below.
1
CreateThread(function()
2
while true do
3
if Cache.NearbyHouses and #Cache.NearbyHouses > 0 then
4
Wait(0)
5
for k, v in pairs(Cache.NearbyHouses) do
6
if not Cache.owned_houses[v.houseid] and not Cache.bought_houses[v.houseid] then
7
if (not Config.REA or Config.AllowCircle) and Marker(v.data.Entrance.xyz, string.format(Strings["buy_house"], v.data.Label, v.houseid, FormatNumber(v.data.Price))) then
8
OpenPurchaseMenu(v.houseid)
9
while #(GetEntityCoords(PlayerPedId()) - v.data.Entrance.xyz) <= 1.1 and ESX.UI.Menu.IsOpen("default", GetCurrentResourceName(), "purchase_house") do
10
Wait(50)
11
end
12
ESX.UI.Menu.CloseAll()
13
elseif Config.REA and not Config.AllowCircle then
14
if Marker(v.data.Entrance.xyz, Strings["contact_rea"]:format(v.data.Label, v.houseid)) then
15
PreviewHouse(v.data)
16
end
17
end
18
else
19
if Config.EnableGarage and (Cache.owned_houses[v.houseid] or exports["loaf_keysystem"]:HasKey("house_" .. v.houseid) and Config.Options.Key.Garage) and v.data.Garage then
20
local vehicle = GetVehiclePedIsUsing(PlayerPedId())
21
22
if DoesEntityExist(vehicle) then
23
if Marker(v.data.Garage.Exit.xyz + vec3(0.0, 0.0, 0.5), Strings["store_garage"]) then
24
--cd_garage
25
TriggerEvent('cd_garage:StoreVehicle_Main', 1, false)
26
--cd_garage
27
end
28
else
29
if Marker(v.data.Garage.Entrance, Strings["enter_garage"]) then
30
local viewing = true
31
32
--cd_garage
33
ESX.UI.Menu.Open( 'default', GetCurrentResourceName(), 'choosegarage', -- Replace the menu name
34
{
35
title = ('Garage'),
36
align = 'center', -- Menu position--top-left
37
elements = { -- Contains menu elements
38
{label = ('Go inside'), value = 'ingarage'},
39
{label = ('Open Menu'), value = 'outgarage'}
40
}
41
},
42
function(data, menu) -- This part contains the code that executes when you press enter
43
if data.current.value == 'ingarage' then
44
TriggerEvent('cd_garage:PropertyGarage', 'inside')
45
menu.close()
46
FreezeEntityPosition(GetPlayerPed(-1),false)
47
elseif data.current.value == 'outgarage' then
48
TriggerEvent('cd_garage:PropertyGarage', 'quick')
49
menu.close()
50
FreezeEntityPosition(GetPlayerPed(-1),false)
51
end
52
end,
53
function(data, menu) -- This part contains the code that executes when the return key is pressed.
54
menu.close() -- Close the menu
55
FreezeEntityPosition(GetPlayerPed(-1),false)
56
end
57
)
58
--cd_garage
59
viewing = false
60
61
while viewing do
62
Wait(250)
63
end
64
end
65
end
66
end
67
68
Marker(v.data.Entrance.xyz)
69
if #(v.data.Entrance.xyz - GetEntityCoords(PlayerPedId())) <= 2.0 then
70
local suffix = ""
71
if Cache.owned_houses[v.houseid] then
72
suffix = Strings["press_manage"]
73
if IsControlJustReleased(0, ((Config.Options and Config.Options.SecondaryAction) or (47))) then
74
ManageHouse(v.houseid)
75
end
76
elseif Cache.IsPolice then
77
suffix = Strings["breach_door"]
78
elseif Config.LockPicking and Config.LockPicking.Enabled then
79
suffix = Strings["lockpick_door"]
80
end
81
82
if Cache.unlocked_doors[v.houseid] then
83
DrawTxt3D(v.data.Entrance.xyz, Strings["unlocked"] .. " (" .. v.houseid .. ")", true, true)
84
if #(v.data.Entrance.xyz - GetEntityCoords(PlayerPedId())) <= 1.0 then
85
if suffix == Strings["press_manage"] then
86
HelpText(Strings["enter"] .. suffix, true)
87
else
88
HelpText(Strings["enter"], true)
89
end
90
if IsControlJustReleased(0, ((Config.Options and Config.Options.MainAction) or (51))) then
91
Cache.inshell = true
92
EnterHouse(k, v)
93
while Cache.inshell do
94
Wait(500)
95
end
96
end
97
end
98
else
99
DrawTxt3D(v.data.Entrance.xyz, Strings["locked"] .. " (" .. v.houseid .. ")" .. suffix, true, true)
100
101
if Cache.IsPolice and suffix == Strings["breach_door"] and IsControlJustReleased(0, ((Config.Options and Config.Options.SecondaryAction) or (47))) then
102
TriggerServerEvent("loaf_housing:breachDoor", v.houseid)
103
elseif IsControlJustReleased(0, ((Config.Options and Config.Options.SecondaryAction) or (47))) and suffix == Strings["lockpick_door"] then
104
local success = LockPick(tonumber(v.houseid))
105
106
ClearPedTasks(PlayerPedId())
107
if success then
108
TriggerServerEvent("loaf_housing:successfulLockpick", v.houseid)
109
end
110
end
111
end
112
end
113
end
114
end
115
else
116
while #(GetEntityCoords(PlayerPedId()) - Config.IKEA.EnterIKEA.xyz) <= 25.0 do
117
Wait(0)
118
119
if Marker(Config.IKEA.EnterIKEA.xyz, Strings["enter_ikea"]) then
120
EnterIKEA()
121
elseif #(GetEntityCoords(PlayerPedId()) - Config.IKEA.EnterIKEA.xyz) <= 1.0 and IsControlJustReleased(0, ((Config.Options and Config.Options.SecondaryAction) or (47))) then
122
OpenSellMenuIKEA()
123
end
124
end
125
Wait(500)
126
end
127
end
128
end)
Copied!