Skip to content

Commit

Permalink
rework code
Browse files Browse the repository at this point in the history
  • Loading branch information
RCServers committed Sep 28, 2022
1 parent c90df52 commit 31b819d
Show file tree
Hide file tree
Showing 7 changed files with 519 additions and 168 deletions.
216 changes: 145 additions & 71 deletions client/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,78 +4,167 @@
-- ██╔══╝ ╚██╗ ██╔╝██╔══╝ ██║╚██╗██║ ██║ ╚════██║
-- ███████╗ ╚████╔╝ ███████╗██║ ╚████║ ██║ ███████║
-- ╚══════╝ ╚═══╝ ╚══════╝╚═╝ ╚═══╝ ╚═╝ ╚══════╝


local QBCore = exports["qb-core"]:GetCoreObject()
local PlayerData = QBCore.Functions.GetPlayerData()
local QBCore = nil
local ESX = nil
local PlayerData = nil
local ped, pid, Player, playerId, player
local OpenMenu = false

-- Start Frameworks

RegisterNetEvent("QBCore:Client:OnPlayerUnload", function()
PlayerData = {}
end)

RegisterNetEvent("QBCore:Client:OnPlayerLoaded")
AddEventHandler("QBCore:Client:OnPlayerLoaded", function ()
PlayerData = {}
end)
if Config.Framework == "QBCORE" then
QBCore = exports["qb-core"]:GetCoreObject()
PlayerData = QBCore.Functions.GetPlayerData()
SendNUIMessage({
action = 'updatedata',
pid = 0,
phone = 'Loading',
job = 'Loading',
name = 'Loading',
bank = 'Loading',
logo = Config.Logo,
playerss = 'Loading',
maxPlayers = Config.MaxPlayers,
})
elseif Config.Framework == "ESX" then
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
SendNUIMessage({
action = 'updatedata',
pid = 0,
phone = 'Loading',
job = 'Loading',
name = 'Loading',
bank = 'Loading',
logo = Config.Logo,
playerss = 'Loading',
maxPlayers = Config.MaxPlayers,
})
else
-- Your own framework
end

GroupDigits = function(value)
local left,num,right = string.match(value,'^([^%d]*%d)(%d*)(.-)$')
return left..(num:reverse():gsub('(%d%d%d)','%1' .. ','):reverse())..right
--Data Extra Start
if Config.Framework == "QBCORE" then
--Extra DATA QBCORE PLAYER CHANGE CHARACTER
RegisterNetEvent("QBCore:Client:OnPlayerUnload", function()
PlayerData = {}
end)
RegisterNetEvent("QBCore:Client:OnPlayerLoaded")
AddEventHandler("QBCore:Client:OnPlayerLoaded", function ()
PlayerData = {}
end)

elseif Config.Framework == "ESX" then
--Extra ESX
else
--Other framework your own code
end
--Data Extra End

---Keyboard
RegisterKeyMapping(Config.OpenScore, Config.KeyName, 'keyboard', Config.KeyOpen)
TriggerEvent('chat:addSuggestion', Config.OpenScore, Config.ChatCommandSuggest)

Citizen.CreateThread(function ()
while true do
Wait(500)
if LocalPlayer.state.isLoggedIn then

QBCore.Functions.GetPlayerData(function(PlayerData)
QBCore.Functions.TriggerCallback('Ultra-Scoreboard:CurrentPlayers', function(player)
ped = PlayerPedId()
pid = GetPlayerServerId(PlayerId())
Player = QBCore.Functions.GetPlayerData()
playerId = PlayerId()
--Function OnKey
RegisterCommand(Config.OpenScore,function ()
OpenMenu = not OpenMenu
if OpenMenu then
SetNuiFocus(true, true)
SendNUIMessage({ action = 'show'})
SendNUIMessage({ action = 'bottom'})
if Config.UseRobberys == true then
SendNUIMessage({ action = 'showrobbery'})
end
else
SetNuiFocus(false, false)
SendNUIMessage({action = 'hide'})
end

if Config.Framework == "QBCORE" then
QBCore.Functions.TriggerCallback('Ultra-Scoreboard:CurrentPlayers', function(oPlayers)
ped = PlayerPedId()
pid = GetPlayerServerId(PlayerId())
PlayerData = QBCore.Functions.GetPlayerData()
playerId = PlayerId()
SendNUIMessage({
action = 'updatedata',
pid = pid,
phone = PlayerData.charinfo.phone,
job = PlayerData.job.label or Config.NoJob,
name = PlayerData.charinfo.firstname.. " " ..PlayerData.charinfo.lastname,
bank = Config.TypeIconMoney ..GroupDigits(PlayerData.money['bank']),
logo = Config.Logo,
playerss = oPlayers,
maxPlayers = Config.MaxPlayers,
})
end)
QBCore.Functions.TriggerCallback('Ultra-Scoreboard:CurrentJobs', function(police, ambulance, mechanic, realestate, taxi, abogado)
ped = PlayerPedId()
pid = GetPlayerServerId(PlayerId())
PlayerData = QBCore.Functions.GetPlayerData()
playerId = PlayerId()

SendNUIMessage({
action = 'updatedatajob',
mechanic = mechanic,
police = police,
ambulance = ambulance,
realestate = realestate,
taxi = taxi,
abogado = abogado,
robos = Config.RobList,
})

-- ✓ ✘
end)


elseif Config.Framework == "ESX" then
ESX.PlayerData = ESX.GetPlayerData()
local player = PlayerId()
local pid = GetPlayerServerId(player)
local playersList = 0
for i = 1, #ESX.PlayerData.accounts, 1 do
if ESX.PlayerData.accounts[i].name == "bank" then
bank = ESX.PlayerData.accounts[i].money
end
end
ESX.TriggerServerCallback('Ultra-Scoreboard:CurrentJobs', function(police, ambulance, mechanic, realestate, taxi, abogado, oPlayers, rpName ,rPhone)
SendNUIMessage({
action = 'updatedatajob',
mechanic = mechanic,
police = police,
ambulance = ambulance,
realestate = realestate,
taxi = taxi,
abogado = abogado,
robos = Config.RobList,
})
SendNUIMessage({
action = 'updatedata',
pid = pid,
phone = Player.charinfo.phone,
job = Player.job.label or Config.NoJob,
name = Player.charinfo.firstname.. " " ..PlayerData.charinfo.lastname,
bank = Config.TypeIconMoney ..GroupDigits(Player.money['bank']),
phone = rPhone,
job = ESX.PlayerData.job.label or Config.NoJob,
name = rpName,
bank = Config.TypeIconMoney ..ESX.Math.GroupDigits(bank),
logo = Config.Logo,
playerss = player,
playerss = oPlayers,
maxPlayers = Config.MaxPlayers,
})
end)
end)
else
SendNUIMessage({action = 'hide'})
end
Wait(500)


end
end)

Citizen.CreateThread(function ()
while true do
Wait(500)
QBCore.Functions.TriggerCallback('Ultra-Scoreboard:CurrentPlayers2', function(police, ambulance, mechanic, realestate, taxi, abogado)
SendNUIMessage({
action = 'updatedatajob',
mechanic = mechanic,
police = police,
ambulance = ambulance,
realestate = realestate,
taxi = taxi,
abogado = abogado,
})
end)
Wait(500)
end
RegisterNUICallback("exit" , function(data, cb)
OpenMenu = false
SetNuiFocus(false, false)
SendNUIMessage({action = 'hide'})
end)

--Other functions

local function GetPlayers()
local players = {}
for _, player in ipairs(GetActivePlayers()) do
Expand All @@ -87,22 +176,7 @@ local function GetPlayers()
return players
end

RegisterKeyMapping(Config.OpenScore, Config.KeyName, 'keyboard', Config.KeyOpen)

TriggerEvent('chat:addSuggestion', Config.OpenScore, Config.ChatCommandSuggest)

RegisterCommand(Config.OpenScore,function ()
SetNuiFocus(true, true)
SendNUIMessage({
action = 'show'
})
end)

RegisterNUICallback("exit" , function(data, cb)
SetNuiFocus(false, false)
SendNUIMessage({
action = 'hide'
})
end)


GroupDigits = function(value)
local left,num,right = string.match(value,'^([^%d]*%d)(%d*)(.-)$')
return left..(num:reverse():gsub('(%d%d%d)','%1' .. ','):reverse())..right
end
26 changes: 23 additions & 3 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,36 @@
-- ╚██████╗╚██████╔╝██║ ╚████║██║ ██║╚██████╔╝
-- ╚═════╝ ╚═════╝ ╚═╝ ╚═══╝╚═╝ ╚═╝ ╚═════╝

Config = Config or {}
Config = {}

Config.Framework = "QBCORE" -- QBCORE o ESX
Config.Debug = false -- Debug mode
Config.Logo = "https://i.imgur.com/yduIdh7.png"

Config.OpenScore = "scoreb"
Config.OpenScore = "scoreboard"
Config.ChatCommandSuggest = "Open Scoreboard"
Config.KeyOpen = "F10"
Config.KeyName = "Open Scorebaord"

Config.MaxPlayers = GetConvarInt('sv_maxclients', 70)
Config.TypeIconMoney = " $"

Config.NoJob = "unemployed"
Config.NoJob = "unemployed"

Config.UseRobberys = true

--!!WARNING!!
-- The Label is not working yet, I only put it to make an order guide!
-- if you want to change the rob you have to change it in the html

Config.RobList = {
{order = 1 , label = 'FLEECA', requieredCops = 3},
{order = 2 , label = 'PACIFIC BANK', requieredCops = 2},
{order = 3 , label = 'VANGELICO', requieredCops = 6},
{order = 4 , label = 'STORE', requieredCops = 3},
{order = 5 , label = 'HUMANE LABS', requieredCops = 4},
{order = 6 , label = 'BOBCAT', requieredCops = 5},
{order = 7 , label = 'UNION', requieredCops = 3},
{order = 8 , label = 'YACHT', requieredCops = 2},
{order = 9 , label = 'VANT', requieredCops = 1},
}
16 changes: 10 additions & 6 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@
fx_version 'cerulean'
game 'gta5'

author 'Clau#1981'

author 'Clau#1981, Robeer#9999'
version '1.1'
description 'Ultra Scoreboard'

shared_scripts {
-- '@es_extended/imports.lua', --On ESX ENABLE
-- '@es_extended/locale.lua', -- On ESX ENABLE
'config.lua',
}

client_scripts {
'client/*.lua',
}

server_scripts {
'@oxmysql/lib/MySQL.lua',
--'@mysql-async/lib/MySQL.lua', -- FOR OLD VERSION OF MYSQL
'server/*.lua',
}

shared_scripts {
'config.lua'
}

ui_page {
'html/index.html',
}
Expand Down
Loading

0 comments on commit 31b819d

Please sign in to comment.