mirror of
https://github.com/ND-Framework/ND_Core.git
synced 2026-08-18 14:26:03 +01:00
Update main.lua
Bug fixes and a little code improvements
This commit is contained in:
@@ -8,7 +8,6 @@
|
|||||||
local background = config.backgrounds[math.random(1, #config.backgrounds)]
|
local background = config.backgrounds[math.random(1, #config.backgrounds)]
|
||||||
local started = true
|
local started = true
|
||||||
registered = false
|
registered = false
|
||||||
admin = false
|
|
||||||
cash = nil
|
cash = nil
|
||||||
bank = nil
|
bank = nil
|
||||||
|
|
||||||
@@ -16,27 +15,27 @@ bank = nil
|
|||||||
RegisterNetEvent("permsChecked")
|
RegisterNetEvent("permsChecked")
|
||||||
AddEventHandler("permsChecked", function(role, rolePermission)
|
AddEventHandler("permsChecked", function(role, rolePermission)
|
||||||
if rolePermission then
|
if rolePermission then
|
||||||
if role == "ADMIN" then
|
SendNUIMessage({
|
||||||
admin = true
|
type = "givePerms",
|
||||||
else
|
deptRole = role
|
||||||
SendNUIMessage({
|
})
|
||||||
type = "givePerms",
|
|
||||||
deptRole = role
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
RegisterNetEvent("refreshCharacters")
|
||||||
|
AddEventHandler("refreshCharacters", function()
|
||||||
|
TriggerServerEvent("getCharacters")
|
||||||
|
end)
|
||||||
|
|
||||||
Citizen.CreateThread(function()
|
Citizen.CreateThread(function()
|
||||||
while started do
|
while started do
|
||||||
Citizen.Wait(200)
|
Citizen.Wait(200)
|
||||||
local ped = PlayerPedId()
|
local ped = PlayerPedId()
|
||||||
if IsPedOnFoot(ped) or IsPedInVehicle(ped, GetVehiclePedIsIn(ped, false), false) then
|
if IsPedOnFoot(ped) or IsPedInVehicle(ped, GetVehiclePedIsIn(ped, false), false) then
|
||||||
print("^0This framework is created by ^5Andyyy#7666 ^0for support you can join the ^5discord: ^0https://discord.gg/Z9Mxu72zZ6")
|
print("^0This framework is created by ^5Andyyy#7666 ^0for support you can join the ^5discord: ^0https://discord.gg/Z9Mxu72zZ6")
|
||||||
for i = 1, #config.departments do -- if you have an error that says attempt to index a nil value (global 'config') it's beacuse you have edited the config wrong.
|
for departmentName in pairs(config.departments) do -- if you have an error that says attempt to index a nil value (global 'config') it's beacuse you have edited the config wrong.
|
||||||
TriggerServerEvent("checkPerms", config.departments[i]) -- check permissions for each department with the department names.
|
TriggerServerEvent("checkPerms", config.departments[departmentName]) -- check permissions for each department with the department names.
|
||||||
end
|
end
|
||||||
TriggerServerEvent("checkPerms", "ADMIN") -- check if the player has the admin role.
|
|
||||||
TriggerServerEvent("getCharacters")
|
TriggerServerEvent("getCharacters")
|
||||||
Citizen.Wait(100)
|
Citizen.Wait(100)
|
||||||
TriggerServerEvent("getAop")
|
TriggerServerEvent("getAop")
|
||||||
@@ -46,6 +45,7 @@ Citizen.CreateThread(function()
|
|||||||
started = false
|
started = false
|
||||||
SendNUIMessage({
|
SendNUIMessage({
|
||||||
type = "onStart",
|
type = "onStart",
|
||||||
|
enableMoneySystem = config.enableMoneySystem,
|
||||||
maxStartingBank = config.maxStartingBank,
|
maxStartingBank = config.maxStartingBank,
|
||||||
maxStartingCash = config.maxStartingCash
|
maxStartingCash = config.maxStartingCash
|
||||||
})
|
})
|
||||||
@@ -59,25 +59,25 @@ end)
|
|||||||
|
|
||||||
RegisterNetEvent("returnCharacters")
|
RegisterNetEvent("returnCharacters")
|
||||||
AddEventHandler("returnCharacters", function(characters)
|
AddEventHandler("returnCharacters", function(characters)
|
||||||
|
characterAmount = 0
|
||||||
SendNUIMessage({
|
SendNUIMessage({
|
||||||
type = "refresh"
|
type = "refresh"
|
||||||
})
|
})
|
||||||
for i = 1, #characters do
|
for _, character in pairs(characters) do
|
||||||
index = characters[i]
|
|
||||||
SendNUIMessage({
|
SendNUIMessage({
|
||||||
type = "character",
|
type = "character",
|
||||||
id = index.id,
|
id = character.id,
|
||||||
firstName = index.firstName,
|
firstName = character.firstName,
|
||||||
lastName = index.lastName,
|
lastName = character.lastName,
|
||||||
dateOfBirth = index.dob,
|
dateOfBirth = character.dob,
|
||||||
gender = index.gender,
|
gender = character.gender,
|
||||||
twtName = index.twt,
|
twtName = character.twt,
|
||||||
department = index.department,
|
department = character.department,
|
||||||
startingCash = index.cash,
|
startingCash = character.cash,
|
||||||
startingBank = index.bank
|
startingBank = character.bank
|
||||||
})
|
})
|
||||||
|
characterAmount = characterAmount + 1
|
||||||
end
|
end
|
||||||
characterAmount = #characters
|
|
||||||
SetDisplay(true, "ui", background)
|
SetDisplay(true, "ui", background)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
@@ -133,51 +133,82 @@ RegisterNUICallback("setMainCharacter", function(data)
|
|||||||
mainStartingBank = data.startingBank
|
mainStartingBank = data.startingBank
|
||||||
mainCharaterId = data.character
|
mainCharaterId = data.character
|
||||||
|
|
||||||
for i = 1, #config.departments do
|
for _, spawn in pairs(config.spawns[mainDepartment]) do
|
||||||
validDept = config.departments[i]
|
SendNUIMessage({
|
||||||
if mainDepartment == validDept then
|
type = "setSpawns",
|
||||||
for i = 1, #config.spawns[validDept] do
|
x = spawn.x,
|
||||||
SendNUIMessage({
|
y = spawn.y,
|
||||||
type = "setSpawns",
|
z = spawn.z,
|
||||||
x = config.spawns[validDept][i].x,
|
name = spawn.name
|
||||||
y = config.spawns[validDept][i].y,
|
})
|
||||||
z = config.spawns[validDept][i].z,
|
|
||||||
name = config.spawns[validDept][i].name
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
TriggerServerEvent("characterOnline", mainCharaterId)
|
TriggerServerEvent("characterOnline", mainCharaterId)
|
||||||
|
TriggerServerEvent("getPriority")
|
||||||
registered = true
|
registered = true
|
||||||
end)
|
end)
|
||||||
|
|
||||||
-- This will display the money that the player has.
|
if config.enableMoneySystem then
|
||||||
RegisterNetEvent("returnMoney")
|
-- This will display the money that the player has.
|
||||||
AddEventHandler("returnMoney", function(newCash, newBank)
|
RegisterNetEvent("returnMoney")
|
||||||
while not registered do
|
AddEventHandler("returnMoney", function(newCash, newBank)
|
||||||
Citizen.Wait(10)
|
while not registered do
|
||||||
end
|
Citizen.Wait(10)
|
||||||
cash = newCash
|
|
||||||
bank = newBank
|
|
||||||
if config.legacyMoneyDisplay then
|
|
||||||
if registered then
|
|
||||||
while true do
|
|
||||||
Citizen.Wait(0)
|
|
||||||
text("💵", 0.885, 0.028, 0.35)
|
|
||||||
text("💳", 0.885, 0.068, 0.35)
|
|
||||||
text("~g~$~w~".. cash, 0.91, 0.03, 0.55)
|
|
||||||
text("~b~$~w~".. bank, 0.91, 0.07, 0.55)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
else
|
cash = newCash
|
||||||
SendNUIMessage({
|
bank = newBank
|
||||||
type = "Money",
|
if config.legacyMoneyDisplay then
|
||||||
cash = "Cash: $" .. cash,
|
if registered then
|
||||||
bank = "Bank: $" .. bank
|
while true do
|
||||||
})
|
Citizen.Wait(0)
|
||||||
end
|
text("💵", 0.885, 0.028, 0.35, 7)
|
||||||
end)
|
text("💳", 0.885, 0.068, 0.35, 7)
|
||||||
|
text("~g~$~w~".. cash, 0.91, 0.03, 0.55, 7)
|
||||||
|
text("~b~$~w~".. bank, 0.91, 0.07, 0.55, 7)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
SendNUIMessage({
|
||||||
|
type = "Money",
|
||||||
|
cash = "Cash: $" .. cash,
|
||||||
|
bank = "Bank: $" .. bank
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- This is to update the players money on the ui.
|
||||||
|
RegisterNetEvent("updateMoney")
|
||||||
|
AddEventHandler("updateMoney", function()
|
||||||
|
TriggerServerEvent("getMoney", mainCharaterId)
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Notification when you recieve money.
|
||||||
|
RegisterNetEvent("receiveBank")
|
||||||
|
AddEventHandler("receiveBank", function(amount, playerSending, playerId)
|
||||||
|
BeginTextCommandThefeedPost("STRING")
|
||||||
|
AddTextComponentSubstringPlayerName("Received $" .. amount .. " from " .. playerSending .. " [".. playerId .."]")
|
||||||
|
EndTextCommandThefeedPostMessagetext("CHAR_BANK_FLEECA", "CHAR_BANK_FLEECA", true, 9,"FleecaBank", "")
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Notification when you receive cash.
|
||||||
|
RegisterNetEvent("receiveCash")
|
||||||
|
AddEventHandler("receiveCash", function(amount, playerSending, playerId)
|
||||||
|
BeginTextCommandThefeedPost("STRING")
|
||||||
|
AddTextComponentSubstringPlayerName(playerSending .. " gave you $" .. amount .. ".")
|
||||||
|
EndTextCommandThefeedPostMessagetext("CHAR_DEFAULT", "CHAR_DEFAULT", true, 9, playerSending .. " [".. playerId .."]", "")
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Notification when receiving salary.
|
||||||
|
RegisterNetEvent("receiveSalary")
|
||||||
|
AddEventHandler("receiveSalary", function(amount)
|
||||||
|
if registered then
|
||||||
|
BeginTextCommandThefeedPost("STRING")
|
||||||
|
AddTextComponentSubstringPlayerName("Daily Salary + $" .. config.salaryAmount)
|
||||||
|
EndTextCommandThefeedPostMessagetext("CHAR_BANK_FLEECA", "CHAR_BANK_FLEECA", true, 9,"FleecaBank", "")
|
||||||
|
TriggerServerEvent("getMoney", mainCharaterId)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
-- Teleporting
|
-- Teleporting
|
||||||
RegisterNUICallback("tpToLocation", function(data)
|
RegisterNUICallback("tpToLocation", function(data)
|
||||||
@@ -238,8 +269,24 @@ if config.enableRichPrecence then
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- hide gta default cash, ammo and reticle hud.
|
if config.enablePriorityCooldown then
|
||||||
if config.hideAmmoAndMoney or config.hideReticle then
|
TriggerEvent("chat:addSuggestion", "/" .. config.startPriorityCommand, "Start a priority.")
|
||||||
|
TriggerEvent("chat:addSuggestion", "/" .. config.stopPriorityCommand, "Stop an active priority.")
|
||||||
|
TriggerEvent("chat:addSuggestion", "/" .. config.cooldownPriorityCommand, "Start a cooldown on priorities.", {
|
||||||
|
{name="Time", help="Time in minutes to start a cooldown"}
|
||||||
|
})
|
||||||
|
|
||||||
|
RegisterNetEvent("returnPriority")
|
||||||
|
AddEventHandler("returnPriority", function(priority)
|
||||||
|
if config.canSeePriority[mainDepartment] then
|
||||||
|
priorityText = priority
|
||||||
|
else
|
||||||
|
priorityText = nil
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
if config.hideAmmoAndMoney or config.hideReticle or config.customPauseMenu or config.enablePriorityCooldown then
|
||||||
Citizen.CreateThread(function()
|
Citizen.CreateThread(function()
|
||||||
while true do
|
while true do
|
||||||
Citizen.Wait(0)
|
Citizen.Wait(0)
|
||||||
@@ -257,48 +304,20 @@ if config.hideAmmoAndMoney or config.hideReticle then
|
|||||||
BeginScaleformMovieMethodOnFrontendHeader("SET_HEADING_DETAILS")
|
BeginScaleformMovieMethodOnFrontendHeader("SET_HEADING_DETAILS")
|
||||||
AddTextEntry("FE_THDR_GTAO", config.serverName)
|
AddTextEntry("FE_THDR_GTAO", config.serverName)
|
||||||
ScaleformMovieMethodAddParamPlayerNameString(mainFirstName .. " " .. mainLastName)
|
ScaleformMovieMethodAddParamPlayerNameString(mainFirstName .. " " .. mainLastName)
|
||||||
--PushScaleformMovieFunctionParameterString("Cash: $" .. cash)
|
if registered and config.enableMoneySystem then
|
||||||
--PushScaleformMovieFunctionParameterString("Bank: $" .. bank)
|
PushScaleformMovieFunctionParameterString("Cash: $" .. cash)
|
||||||
|
PushScaleformMovieFunctionParameterString("Bank: $" .. bank)
|
||||||
|
end
|
||||||
EndScaleformMovieMethod()
|
EndScaleformMovieMethod()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
if config.enablePriorityCooldown and priorityText then
|
||||||
|
text(priorityText, 0.182, 0.891, 0.4, 4)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- This is to update the players money on the ui.
|
|
||||||
RegisterNetEvent("updateMoney")
|
|
||||||
AddEventHandler("updateMoney", function()
|
|
||||||
TriggerServerEvent("getMoney", mainCharaterId)
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Notification when you recieve money.
|
|
||||||
RegisterNetEvent("receiveBank")
|
|
||||||
AddEventHandler("receiveBank", function(amount, playerSending, playerId)
|
|
||||||
BeginTextCommandThefeedPost("STRING")
|
|
||||||
AddTextComponentSubstringPlayerName("Received $" .. amount .. " from " .. playerSending .. " [".. playerId .."]")
|
|
||||||
EndTextCommandThefeedPostMessagetext("CHAR_BANK_FLEECA", "CHAR_BANK_FLEECA", true, 9,"FleecaBank", "")
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Notification when you receive cash.
|
|
||||||
RegisterNetEvent("receiveCash")
|
|
||||||
AddEventHandler("receiveCash", function(amount, playerSending, playerId)
|
|
||||||
BeginTextCommandThefeedPost("STRING")
|
|
||||||
AddTextComponentSubstringPlayerName(playerSending .. " gave you $" .. amount .. ".")
|
|
||||||
EndTextCommandThefeedPostMessagetext("CHAR_DEFAULT", "CHAR_DEFAULT", true, 9, playerSending .. " [".. playerId .."]", "")
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Notification when receiving salary.
|
|
||||||
RegisterNetEvent("receiveSalary")
|
|
||||||
AddEventHandler("receiveSalary", function(amount)
|
|
||||||
if registered then
|
|
||||||
BeginTextCommandThefeedPost("STRING")
|
|
||||||
AddTextComponentSubstringPlayerName("Daily Salary + $" .. config.salaryAmount)
|
|
||||||
EndTextCommandThefeedPostMessagetext("CHAR_BANK_FLEECA", "CHAR_BANK_FLEECA", true, 9,"FleecaBank", "")
|
|
||||||
TriggerServerEvent("getMoney", mainCharaterId)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
-- Notification above the map.
|
-- Notification above the map.
|
||||||
function notify(message)
|
function notify(message)
|
||||||
BeginTextCommandThefeedPost("STRING")
|
BeginTextCommandThefeedPost("STRING")
|
||||||
@@ -325,8 +344,8 @@ function getCharacterInfo(infoType)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function text(text, x, y, scale)
|
function text(text, x, y, scale, font)
|
||||||
SetTextFont(7)
|
SetTextFont(font)
|
||||||
SetTextProportional(0)
|
SetTextProportional(0)
|
||||||
SetTextScale(scale, scale)
|
SetTextScale(scale, scale)
|
||||||
SetTextEdge(1, 0, 0, 0, 255)
|
SetTextEdge(1, 0, 0, 0, 255)
|
||||||
|
|||||||
Reference in New Issue
Block a user