Update main.lua

Bug fixes and a little code improvements
This commit is contained in:
Andyyy7666
2022-02-26 01:40:26 +01:00
committed by GitHub
parent 41d4a8126a
commit 5cab2ebe2e

View File

@@ -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,15 +15,16 @@ 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
admin = true
else
SendNUIMessage({ SendNUIMessage({
type = "givePerms", type = "givePerms",
deptRole = role deptRole = role
}) })
end end
end end)
RegisterNetEvent("refreshCharacters")
AddEventHandler("refreshCharacters", function()
TriggerServerEvent("getCharacters")
end) end)
Citizen.CreateThread(function() Citizen.CreateThread(function()
@@ -33,10 +33,9 @@ Citizen.CreateThread(function()
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,25 +133,22 @@ 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]
if mainDepartment == validDept then
for i = 1, #config.spawns[validDept] do
SendNUIMessage({ SendNUIMessage({
type = "setSpawns", type = "setSpawns",
x = config.spawns[validDept][i].x, x = spawn.x,
y = config.spawns[validDept][i].y, y = spawn.y,
z = config.spawns[validDept][i].z, z = spawn.z,
name = config.spawns[validDept][i].name name = spawn.name
}) })
end end
end
end
TriggerServerEvent("characterOnline", mainCharaterId) TriggerServerEvent("characterOnline", mainCharaterId)
TriggerServerEvent("getPriority")
registered = true registered = true
end) end)
if config.enableMoneySystem then
-- This will display the money that the player has. -- This will display the money that the player has.
RegisterNetEvent("returnMoney") RegisterNetEvent("returnMoney")
AddEventHandler("returnMoney", function(newCash, newBank) AddEventHandler("returnMoney", function(newCash, newBank)
@@ -164,10 +161,10 @@ AddEventHandler("returnMoney", function(newCash, newBank)
if registered then if registered then
while true do while true do
Citizen.Wait(0) Citizen.Wait(0)
text("💵", 0.885, 0.028, 0.35) text("💵", 0.885, 0.028, 0.35, 7)
text("💳", 0.885, 0.068, 0.35) text("💳", 0.885, 0.068, 0.35, 7)
text("~g~$~w~".. cash, 0.91, 0.03, 0.55) text("~g~$~w~".. cash, 0.91, 0.03, 0.55, 7)
text("~b~$~w~".. bank, 0.91, 0.07, 0.55) text("~b~$~w~".. bank, 0.91, 0.07, 0.55, 7)
end end
end end
else else
@@ -179,6 +176,40 @@ AddEventHandler("returnMoney", function(newCash, newBank)
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)
end
-- Teleporting -- Teleporting
RegisterNUICallback("tpToLocation", function(data) RegisterNUICallback("tpToLocation", function(data)
local ped = PlayerPedId() local ped = PlayerPedId()
@@ -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)