2022-07-16 04:46:27 +02:00
|
|
|
-- For support join my discord: https://discord.gg/Z9Mxu72zZ6
|
|
|
|
|
|
|
|
|
|
NDCore = exports["ND_Core"]:GetCoreObject()
|
2022-08-05 00:18:10 +02:00
|
|
|
local changeAppearence = false
|
2022-08-09 00:53:35 +02:00
|
|
|
local started = false
|
2022-08-05 00:18:10 +02:00
|
|
|
|
|
|
|
|
function startChangeAppearence()
|
|
|
|
|
local config = {
|
|
|
|
|
ped = true,
|
|
|
|
|
headBlend = true,
|
|
|
|
|
faceFeatures = true,
|
|
|
|
|
headOverlays = true,
|
|
|
|
|
components = true,
|
|
|
|
|
props = true,
|
|
|
|
|
tattoos = false
|
|
|
|
|
}
|
2022-08-04 23:03:44 -04:00
|
|
|
|
2022-08-05 00:18:10 +02:00
|
|
|
exports["fivem-appearance"]:startPlayerCustomization(function(appearance)
|
2022-08-09 00:53:35 +02:00
|
|
|
if appearance then
|
2022-08-05 00:18:10 +02:00
|
|
|
local ped = PlayerPedId()
|
|
|
|
|
local clothing = {
|
2022-08-09 00:53:35 +02:00
|
|
|
model = GetEntityModel(ped),
|
2022-08-05 00:18:10 +02:00
|
|
|
tattoos = exports["fivem-appearance"]:getPedTattoos(ped),
|
|
|
|
|
appearance = exports["fivem-appearance"]:getPedAppearance(ped)
|
|
|
|
|
}
|
|
|
|
|
Wait(4000)
|
|
|
|
|
TriggerServerEvent("ND:updateClothes", clothing)
|
|
|
|
|
else
|
2022-08-09 00:53:35 +02:00
|
|
|
start(true)
|
2022-08-05 00:18:10 +02:00
|
|
|
end
|
2022-08-09 00:53:35 +02:00
|
|
|
changeAppearence = false
|
2022-08-05 00:18:10 +02:00
|
|
|
end, config)
|
|
|
|
|
end
|
2022-07-16 04:46:27 +02:00
|
|
|
|
2022-08-11 19:49:08 +02:00
|
|
|
-- Set the player to creating the ped if they haven't already.
|
|
|
|
|
function setCharacterClothes(character)
|
|
|
|
|
if config.enableAppearance then
|
|
|
|
|
if not character.clothing or next(character.clothing) == nil then
|
|
|
|
|
changeAppearence = true
|
|
|
|
|
else
|
|
|
|
|
changeAppearence = false
|
|
|
|
|
exports["fivem-appearance"]:setPlayerModel(character.clothing.model)
|
|
|
|
|
local ped = PlayerPedId()
|
|
|
|
|
exports["fivem-appearance"]:setPedTattoos(ped, character.clothing.tattoos)
|
|
|
|
|
exports["fivem-appearance"]:setPedAppearance(ped, character.clothing.appearance)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2022-07-16 04:46:27 +02:00
|
|
|
function tablelength(table)
|
|
|
|
|
local count = 0
|
|
|
|
|
for _ in pairs(table) do
|
|
|
|
|
count = count + 1
|
|
|
|
|
end
|
|
|
|
|
return count
|
|
|
|
|
end
|
|
|
|
|
|
2022-07-21 22:53:12 +02:00
|
|
|
function SetDisplay(bool, typeName, bg, characters)
|
|
|
|
|
local characterAmount = characters
|
|
|
|
|
if not characterAmount then
|
|
|
|
|
characterAmount = NDCore.Functions.GetCharacters()
|
|
|
|
|
end
|
2022-07-16 04:46:27 +02:00
|
|
|
if not bg then
|
|
|
|
|
background = config.backgrounds[math.random(1, #config.backgrounds)]
|
|
|
|
|
end
|
|
|
|
|
SetNuiFocus(bool, bool)
|
|
|
|
|
SendNUIMessage({
|
|
|
|
|
type = typeName,
|
|
|
|
|
background = background,
|
|
|
|
|
status = bool,
|
2022-07-16 00:12:02 -04:00
|
|
|
serverName = NDCore.Config.serverName,
|
2022-07-21 22:53:12 +02:00
|
|
|
characterAmount = tablelength(characterAmount) .. "/" .. NDCore.Config.characterLimit
|
2022-07-16 04:46:27 +02:00
|
|
|
})
|
2022-07-21 22:53:12 +02:00
|
|
|
Wait(500)
|
2022-07-16 04:46:27 +02:00
|
|
|
if config.characterSelectionAopDisplay then
|
|
|
|
|
SendNUIMessage({
|
|
|
|
|
type = "aop",
|
2022-08-22 22:20:40 +02:00
|
|
|
aop = config.aopExport()
|
2022-07-16 04:46:27 +02:00
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
function start(switch)
|
2022-07-16 00:12:02 -04:00
|
|
|
TriggerServerEvent("ND:GetCharacters")
|
2022-08-08 20:58:23 +02:00
|
|
|
if not started then
|
|
|
|
|
TriggerServerEvent("ND_CharacterSelection:checkPerms")
|
|
|
|
|
started = true
|
|
|
|
|
end
|
2022-07-16 04:46:27 +02:00
|
|
|
if switch then
|
|
|
|
|
local ped = PlayerPedId()
|
|
|
|
|
SwitchOutPlayer(ped, 0, 1)
|
|
|
|
|
FreezeEntityPosition(ped, true)
|
|
|
|
|
SetEntityVisible(ped, false, 0)
|
|
|
|
|
end
|
|
|
|
|
if config.characterSelectionAopDisplay then
|
|
|
|
|
SendNUIMessage({
|
|
|
|
|
type = "aop",
|
2022-08-29 21:25:32 +02:00
|
|
|
aop = config.aopExport()
|
2022-07-16 04:46:27 +02:00
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
AddEventHandler("onResourceStart", function(resourceName)
|
|
|
|
|
if (GetCurrentResourceName() ~= resourceName) then
|
|
|
|
|
return
|
|
|
|
|
end
|
2022-08-11 19:49:08 +02:00
|
|
|
Wait(2000)
|
2022-07-16 04:46:27 +02:00
|
|
|
start(false)
|
2022-08-09 00:53:35 +02:00
|
|
|
end)
|
2022-07-16 04:46:27 +02:00
|
|
|
|
|
|
|
|
AddEventHandler("playerSpawned", function()
|
|
|
|
|
start(true)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
-- This is used to add department drop down on the ui.
|
2022-09-01 04:11:48 -04:00
|
|
|
RegisterNetEvent("ND_CharacterSelection:permsChecked", function(allowedRoles)
|
2022-07-17 20:15:03 +02:00
|
|
|
SendNUIMessage({
|
|
|
|
|
type = "givePerms",
|
|
|
|
|
deptRoles = json.encode(allowedRoles)
|
|
|
|
|
})
|
2022-07-16 04:46:27 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
-- Gets all the characters and displays them on the ui.
|
2022-09-01 04:11:48 -04:00
|
|
|
RegisterNetEvent("ND:returnCharacters", function(characters)
|
2022-07-23 00:06:20 -04:00
|
|
|
local playerCharacters = {}
|
|
|
|
|
for id, characterInfo in pairs(characters) do
|
|
|
|
|
playerCharacters[tostring(id)] = characterInfo
|
|
|
|
|
end
|
2022-07-16 04:46:27 +02:00
|
|
|
SendNUIMessage({
|
2022-07-21 22:53:12 +02:00
|
|
|
type = "refresh",
|
2022-07-23 00:06:20 -04:00
|
|
|
characters = json.encode(playerCharacters)
|
2022-07-16 04:46:27 +02:00
|
|
|
})
|
2022-07-21 22:53:12 +02:00
|
|
|
SetDisplay(true, "ui", background, characters)
|
2022-07-16 04:46:27 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
-- Selecting a player from the iu.
|
|
|
|
|
RegisterNUICallback("setMainCharacter", function(data)
|
2022-07-17 07:22:52 +02:00
|
|
|
local characters = NDCore.Functions.GetCharacters()
|
|
|
|
|
for _, spawn in pairs(config.spawns[characters[data.id].job]) do
|
2022-07-16 04:46:27 +02:00
|
|
|
SendNUIMessage({
|
|
|
|
|
type = "setSpawns",
|
|
|
|
|
x = spawn.x,
|
|
|
|
|
y = spawn.y,
|
|
|
|
|
z = spawn.z,
|
2022-08-09 00:53:35 +02:00
|
|
|
name = spawn.name,
|
|
|
|
|
id = characters[data.id].id
|
2022-07-16 04:46:27 +02:00
|
|
|
})
|
|
|
|
|
end
|
2022-08-05 00:18:10 +02:00
|
|
|
Wait(1000)
|
2022-07-17 07:22:52 +02:00
|
|
|
TriggerServerEvent("ND:setCharacterOnline", data.id)
|
2022-07-16 04:46:27 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
-- Creating a character from the ui.
|
|
|
|
|
RegisterNUICallback("newCharacter", function(data)
|
2022-07-17 19:37:13 +02:00
|
|
|
if tablelength(NDCore.Characters) < NDCore.Config.characterLimit then
|
2022-07-16 04:46:27 +02:00
|
|
|
TriggerServerEvent("ND_CharacterSelection:newCharacter", {
|
|
|
|
|
firstName = data.firstName,
|
|
|
|
|
lastName = data.lastName,
|
|
|
|
|
dob = data.dateOfBirth,
|
|
|
|
|
gender = data.gender,
|
|
|
|
|
twt = data.twtName,
|
|
|
|
|
job = data.department,
|
|
|
|
|
cash = data.startingCash,
|
|
|
|
|
bank = data.startingBank
|
|
|
|
|
})
|
|
|
|
|
end
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
-- editing a character from the ui.
|
|
|
|
|
RegisterNUICallback("editCharacter", function(data)
|
|
|
|
|
TriggerServerEvent("ND_CharacterSelection:editCharacter", {
|
|
|
|
|
id = data.id,
|
|
|
|
|
firstName = data.firstName,
|
|
|
|
|
lastName = data.lastName,
|
|
|
|
|
dob = data.dateOfBirth,
|
|
|
|
|
gender = data.gender,
|
|
|
|
|
twt = data.twtName,
|
|
|
|
|
job = data.department
|
|
|
|
|
})
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
-- deleting a character from the ui.
|
|
|
|
|
RegisterNUICallback("delCharacter", function(data)
|
|
|
|
|
TriggerServerEvent("ND:deleteCharacter", data.character)
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
-- Quit button from ui.
|
|
|
|
|
RegisterNUICallback("exitGame", function()
|
|
|
|
|
TriggerServerEvent("ND:exitGame")
|
|
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
-- Teleporting using ui.
|
|
|
|
|
RegisterNUICallback("tpToLocation", function(data)
|
|
|
|
|
local ped = PlayerPedId()
|
|
|
|
|
SetEntityCoords(ped, tonumber(data.x), tonumber(data.y), tonumber(data.z), false, false, false, false)
|
|
|
|
|
FreezeEntityPosition(ped, true)
|
|
|
|
|
SwitchInPlayer(ped)
|
2022-08-11 19:49:08 +02:00
|
|
|
Wait(500)
|
2022-07-16 04:46:27 +02:00
|
|
|
SetDisplay(false, "ui")
|
2022-08-11 19:49:08 +02:00
|
|
|
Wait(500)
|
2022-07-16 04:46:27 +02:00
|
|
|
FreezeEntityPosition(ped, false)
|
|
|
|
|
SetEntityVisible(ped, true, 0)
|
2022-08-11 19:49:08 +02:00
|
|
|
setCharacterClothes(NDCore.Functions.GetSelectedCharacter())
|
2022-08-09 00:53:35 +02:00
|
|
|
if config.enableAppearance and changeAppearence then
|
2022-08-05 00:18:10 +02:00
|
|
|
startChangeAppearence()
|
|
|
|
|
end
|
2022-07-16 04:46:27 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
-- Choosing the do not tp button.
|
2022-08-09 00:53:35 +02:00
|
|
|
RegisterNUICallback("tpDoNot", function(data)
|
2022-07-16 04:46:27 +02:00
|
|
|
local ped = PlayerPedId()
|
2022-08-09 00:53:35 +02:00
|
|
|
local character = NDCore.Functions.GetCharacters()[data.id]
|
2022-08-11 19:49:08 +02:00
|
|
|
if character.lastLocation and next(character.lastLocation) ~= nil then
|
2022-08-09 00:53:35 +02:00
|
|
|
SetEntityCoords(ped, character.lastLocation.x, character.lastLocation.y, character.lastLocation.z, false, false, false, false)
|
2022-08-11 19:49:08 +02:00
|
|
|
FreezeEntityPosition(ped, true)
|
2022-08-09 00:53:35 +02:00
|
|
|
end
|
2022-07-16 04:46:27 +02:00
|
|
|
SwitchInPlayer(ped)
|
2022-08-11 19:49:08 +02:00
|
|
|
Wait(500)
|
2022-07-16 04:46:27 +02:00
|
|
|
SetDisplay(false, "ui")
|
2022-08-11 19:49:08 +02:00
|
|
|
Wait(500)
|
2022-08-09 00:53:35 +02:00
|
|
|
SetEntityVisible(ped, true, 0)
|
2022-08-11 19:49:08 +02:00
|
|
|
FreezeEntityPosition(ped, false)
|
|
|
|
|
Wait(100)
|
|
|
|
|
setCharacterClothes(NDCore.Functions.GetSelectedCharacter())
|
2022-08-09 00:53:35 +02:00
|
|
|
if config.enableAppearance and changeAppearence then
|
2022-08-05 00:18:10 +02:00
|
|
|
startChangeAppearence()
|
|
|
|
|
end
|
2022-07-16 04:46:27 +02:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
|
-- Change character command
|
|
|
|
|
RegisterCommand(config.changeCharacterCommand, function()
|
2022-09-05 07:59:50 -04:00
|
|
|
local ped = PlayerPedId()
|
|
|
|
|
SwitchOutPlayer(ped, 0, 1)
|
2022-08-11 19:49:08 +02:00
|
|
|
Wait(2000)
|
2022-07-16 04:46:27 +02:00
|
|
|
FreezeEntityPosition(ped, true)
|
|
|
|
|
SetEntityVisible(ped, false, 0)
|
|
|
|
|
SetDisplay(true, "ui")
|
|
|
|
|
end, false)
|
|
|
|
|
|
|
|
|
|
-- chat suggestions
|
2022-08-11 19:04:57 -06:00
|
|
|
TriggerEvent("chat:addSuggestion", "/" .. config.changeCharacterCommand, "Switch your framework character.")
|