From 8681f824b6576fec584f0aff762ad98a9dab8957 Mon Sep 17 00:00:00 2001
From: Andyyy7666 <86536434+Andyyy7666@users.noreply.github.com>
Date: Tue, 9 Aug 2022 00:53:35 +0200
Subject: [PATCH] Added fivem appearance
---
ND_CharacterSelection/config.lua | 2 +-
ND_CharacterSelection/source/client.lua | 56 ++---
ND_CharacterSelection/source/ui/script.js | 237 +++++++++++++++++++++-
ND_Core/server/events.lua | 6 +-
ND_Core/server/main.lua | 15 +-
5 files changed, 287 insertions(+), 29 deletions(-)
diff --git a/ND_CharacterSelection/config.lua b/ND_CharacterSelection/config.lua
index 87978ca..636f652 100644
--- a/ND_CharacterSelection/config.lua
+++ b/ND_CharacterSelection/config.lua
@@ -2,7 +2,7 @@
config = {
changeCharacterCommand = "changecharacter", -- this is the command to open the ui again and change your character.
-
+ enableAppearance = true, -- you need to install fivem-appearance
characterSelectionAopDisplay = false,
aop = function ()
return "AOP: " .. exports["SimpleHUD"]:getAOP() -- exports["ModernHUD"]:getAOP()
diff --git a/ND_CharacterSelection/source/client.lua b/ND_CharacterSelection/source/client.lua
index 654d848..43051a5 100644
--- a/ND_CharacterSelection/source/client.lua
+++ b/ND_CharacterSelection/source/client.lua
@@ -2,6 +2,7 @@
NDCore = exports["ND_Core"]:GetCoreObject()
local changeAppearence = false
+local started = false
function startChangeAppearence()
local config = {
@@ -15,17 +16,19 @@ function startChangeAppearence()
}
exports["fivem-appearance"]:startPlayerCustomization(function(appearance)
- if (appearance) then
+ if appearance then
local ped = PlayerPedId()
local clothing = {
+ model = GetEntityModel(ped),
tattoos = exports["fivem-appearance"]:getPedTattoos(ped),
appearance = exports["fivem-appearance"]:getPedAppearance(ped)
}
Wait(4000)
TriggerServerEvent("ND:updateClothes", clothing)
else
- print("Canceled")
+ start(true)
end
+ changeAppearence = false
end, config)
end
@@ -62,8 +65,6 @@ function SetDisplay(bool, typeName, bg, characters)
end
end
-started = false
-
function start(switch)
TriggerServerEvent("ND:GetCharacters")
if not started then
@@ -90,7 +91,7 @@ AddEventHandler("onResourceStart", function(resourceName)
end
Citizen.Wait(2000)
start(false)
-end)
+end)
AddEventHandler("playerSpawned", function()
start(true)
@@ -119,19 +120,21 @@ AddEventHandler("ND:returnCharacters", function(characters)
SetDisplay(true, "ui", background, characters)
end)
--- [TODO] to be implemented properly later
-- Set the player to creating the ped if they haven't already.
--- RegisterNetEvent("ND:setCharacter")
--- AddEventHandler("ND:setCharacter", function(character)
--- if next(character.clothing) == nil then
--- changeAppearence = true
--- else
--- changeAppearence = false
--- local ped = PlayerPedId()
--- exports["fivem-appearance"]:setPedTattoos(ped, character.clothing.tattoos)
--- exports["fivem-appearance"]:setPedAppearance(ped, character.clothing.appearance)
--- end
--- end)
+RegisterNetEvent("ND:setCharacter")
+AddEventHandler("ND:setCharacter", function(character)
+ if config.enableAppearance then
+ if 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)
-- Selecting a player from the iu.
RegisterNUICallback("setMainCharacter", function(data)
@@ -142,7 +145,8 @@ RegisterNUICallback("setMainCharacter", function(data)
x = spawn.x,
y = spawn.y,
z = spawn.z,
- name = spawn.name
+ name = spawn.name,
+ id = characters[data.id].id
})
end
Wait(1000)
@@ -200,21 +204,27 @@ RegisterNUICallback("tpToLocation", function(data)
Citizen.Wait(500)
FreezeEntityPosition(ped, false)
SetEntityVisible(ped, true, 0)
- if changeAppearence then
+ if config.enableAppearance and changeAppearence then
startChangeAppearence()
end
end)
-- Choosing the do not tp button.
-RegisterNUICallback("tpDoNot", function()
+RegisterNUICallback("tpDoNot", function(data)
local ped = PlayerPedId()
+ local character = NDCore.Functions.GetCharacters()[data.id]
+ FreezeEntityPosition(ped, false)
+ if next(character.lastLocation) ~= nil then
+ SetEntityCoords(ped, character.lastLocation.x, character.lastLocation.y, character.lastLocation.z, false, false, false, false)
+ end
+ FreezeEntityPosition(ped, true)
SwitchInPlayer(ped)
Citizen.Wait(500)
SetDisplay(false, "ui")
Citizen.Wait(500)
- SetEntityVisible(ped, true, 0)
FreezeEntityPosition(ped, false)
- if changeAppearence then
+ SetEntityVisible(ped, true, 0)
+ if config.enableAppearance and changeAppearence then
startChangeAppearence()
end
end)
@@ -229,4 +239,4 @@ RegisterCommand(config.changeCharacterCommand, function()
end, false)
-- chat suggestions
-TriggerEvent("chat:addSuggestion", "/" .. config.changeCharacterCommand, "Switch your framework character.")
+TriggerEvent("chat:addSuggestion", "/" .. config.changeCharacterCommand, "Switch your framework character.")
\ No newline at end of file
diff --git a/ND_CharacterSelection/source/ui/script.js b/ND_CharacterSelection/source/ui/script.js
index bb78e56..e6d7b80 100644
--- a/ND_CharacterSelection/source/ui/script.js
+++ b/ND_CharacterSelection/source/ui/script.js
@@ -64,6 +64,7 @@ $(function() {
if (item.type === "setSpawns") {
$("#spawnMenuContainer").empty();
setTimeout(function(){
+ $("#tpDoNot").data("id", item.id);
$("#spawnMenuContainer").append(``);
$(".spawnButtons").click(function() {
$.post(`https://${GetParentResourceName()}/tpToLocation`, JSON.stringify({
@@ -77,6 +78,16 @@ $(function() {
}, 550);
return;
});
+ $("#tpDoNot").click(function() {
+ $.post(`https://${GetParentResourceName()}/tpDoNot`, JSON.stringify({
+ id: $("#tpDoNot").data("id")
+ }));
+ spawnMenu(false)
+ setTimeout(function(){
+ $("#spawnMenuContainer").empty();
+ }, 550);
+ return;
+ });
}, 10);
}
@@ -201,8 +212,228 @@ $(function() {
}, 550);
return;
});
- $("#tpDoNot").click(function() {
- $.post(`https://${GetParentResourceName()}/tpDoNot`);
+
+ $("#quitGameButton").click(function() {
+ exitGameMenu(true)
+ return;
+ });
+ $("#exitGameCancel").click(function() {
+ exitGameMenu(false)
+ return;
+ });
+ $("#exitGameConfirm").click(function() {
+ $.post(`https://${GetParentResourceName()}/exitGame`);
+ return;
+ });
+});
+$(function() {
+ function display(bool) {
+ if (bool) {
+ $("body").show();
+ } else {
+ $("body").hide();
+ }
+ }
+ function characterCreatorMenu(bool) {
+ if (bool) {
+ $("#characterCreator").fadeIn("slow");
+ $("#characterEditor, #exitGameMenu, #deleteCharacterMenu, #spawnLocation").hide();
+ return;
+ }
+ $("#characterCreator").fadeOut("slow");
+ }
+ function characterEditorMenu(bool) {
+ if (bool) {
+ $("#characterEditor").fadeIn("slow");
+ $("#characterCreator, #exitGameMenu, #deleteCharacterMenu, #spawnLocation").hide();
+ return;
+ }
+ $("#characterEditor").fadeOut("slow");
+ }
+ function exitGameMenu(bool) {
+ if (bool) {
+ $("#exitGameMenu").fadeIn("slow");
+ $("#characterCreator, #characterEditor, #deleteCharacterMenu, #spawnLocation").hide();
+ return;
+ }
+ $("#exitGameMenu").fadeOut("slow");
+ }
+ function confirmDeleteMenu(bool) {
+ if (bool) {
+ $("#deleteCharacterMenu").fadeIn("slow");
+ $("#characterCreator, #characterEditor, #exitGameMenu, #spawnLocation").hide();
+ return;
+ }
+ $("#deleteCharacterMenu").fadeOut("slow");
+ }
+ function spawnMenu(bool) {
+ if (bool) {
+ $("#spawnLocation").fadeIn("slow");
+ $("#characterCreator, #characterEditor, #exitGameMenu, #deleteCharacterMenu").hide();
+ return;
+ }
+ $("#spawnLocation").fadeOut("slow");
+ }
+
+ window.addEventListener("message", function(event) {
+ const item = event.data;
+ if (item.type === "ui") {
+ if (item.status) {
+ $("#serverName").text(item.serverName);
+ $("body").css("background-image", "url(" + item.background + ")");
+ display(true);
+ } else {
+ display(false);
+ }
+ }
+
+ $("#playerAmount").text(item.characterAmount);
+
+ if (item.type === "setSpawns") {
+ $("#spawnMenuContainer").empty();
+ setTimeout(function(){
+ $("#tpDoNot").data("id", item.id);
+ $("#spawnMenuContainer").append(``);
+ $(".spawnButtons").click(function() {
+ $.post(`https://${GetParentResourceName()}/tpToLocation`, JSON.stringify({
+ x: $(this).data("x"),
+ y: $(this).data("y"),
+ z: $(this).data("z")
+ }));
+ spawnMenu(false);
+ setTimeout(function(){
+ $("#spawnMenuContainer").empty();
+ }, 550);
+ return;
+ });
+ $("#tpDoNot").click(function() {
+ $.post(`https://${GetParentResourceName()}/tpDoNot`, JSON.stringify({
+ id: $("#tpDoNot").data("id")
+ }));
+ spawnMenu(false)
+ setTimeout(function(){
+ $("#spawnMenuContainer").empty();
+ }, 550);
+ return;
+ });
+ }, 10);
+ }
+
+ if (item.type === "givePerms") {
+ JSON.parse(item.deptRoles).forEach((dept) => {
+ $(".departments").append($("