Merge pull request #700 from Rav3n95/main

Fix of the fix in TextUi, Banking ped refactor
This commit is contained in:
Benzo
2022-11-24 23:02:21 +01:00
committed by GitHub
7 changed files with 75 additions and 103 deletions
+4 -4
View File
@@ -1,12 +1,12 @@
Debug = ESX.GetConfig().EnableDebug Debug = ESX.GetConfig().EnableDebug
---@param message any ---@param message string
---@param type string ---@param typ string
local function TextUI(message, type) local function TextUI(message, typ)
SendNUIMessage({ SendNUIMessage({
action = 'show', action = 'show',
message = message and message or 'ESX-TextUI', message = message and message or 'ESX-TextUI',
type = type ~= 0 and type or 'info' type = type(typ) == "string" and typ or 'info'
}) })
end end
+1 -1
View File
@@ -1,5 +1,5 @@
Locales['en'] = { Locales['en'] = {
['allowlist_check'] = 'Checking you are Allowlisted.', ['allowlist_check'] = 'Checking if you are Allowlisted.',
['not_allowlisted'] = 'You Must be Allowlisted to join this server!', ['not_allowlisted'] = 'You Must be Allowlisted to join this server!',
['allowlist_empty'] = 'There Are no allowlists saved for this server.', ['allowlist_empty'] = 'There Are no allowlists saved for this server.',
['license_missing'] = 'Error: Your Identifier is missing!', ['license_missing'] = 'Error: Your Identifier is missing!',
+5 -5
View File
@@ -1,8 +1,8 @@
Locales['hu'] = { Locales['hu'] = {
['allowlist_check'] = 'Ellenőrzi, hogy fent vagy-e az engedélyezett listára.', ['allowlist_check'] = 'Ellenőrizzük fent vagy-e a menők listáján.',
['not_allowlisted'] = 'Engedélyezettnek kell lenned ahhoz, hogy csatlakozz ehhez a szerverhez!', ['not_allowlisted'] = 'Engedélyezettnek kell lenned ahhoz, hogy csatlakozz ehhez a szerverhez!',
['allowlist_empty'] = 'Ehhez a szerverhez nincsenek mentett engedélyezési listák.', ['allowlist_empty'] = 'Ehhez a szerverhez nincsenek mentett engedélyezési lista.',
['license_missing'] = 'Hiba: Te Identifier-ed hiányzik!', ['license_missing'] = 'Hiba: Te azonosítód hiányzik!',
['help_allowlist_add'] = 'jétékos felvéltele a allowlist-re', ['help_allowlist_add'] = 'játékos felvétele az engedélyezettek listájára',
['help_allowlist_load'] = 'allowlist újratöltése', ['help_allowlist_load'] = 'engedélyezési lista újratöltése',
} }
+24 -76
View File
@@ -1,9 +1,10 @@
local PlayerData, ActivateBlips, Peds = {}, {}, {} local ActivateBlips = {}
local PlayerLoaded = true local PlayerLoaded = true
local isInMarker, isInAtmMarker, isInMenu, isMarkerShowed = false, false, false, false local isInMarker, isInAtmMarker, isInMenu, isMarkerShowed = false, false, false, false
local _GetEntityCoords, _PlayerPedId local _GetEntityCoords, _PlayerPedId
-- Functions -- Functions
-- Listen for keypress while player inside the marker -- Listen for keypress while player inside the marker
local function Listen4Key() local function Listen4Key()
CreateThread(function() CreateThread(function()
@@ -46,57 +47,6 @@ local function RemoveBlips()
ActivateBlips = {} ActivateBlips = {}
end end
-- Ped Handler
local function PedHandler(ids)
local tmpPeds = {}
for _, id in pairs(ids) do
if not Peds[id] then
if not HasModelLoaded(Config.Peds[id].Model) then
RequestModel(Config.Peds[id].Model)
Wait(100)
while not HasModelLoaded(Config.Peds[id].Model) do
Wait(10)
end
end
local npc = CreatePed(6, Config.Peds[id].Model, Config.Peds[id].Position + vector4(0, 0, -1, 0), false,
false)
TaskStartScenarioInPlace(npc, Config.Peds[id].Scenario, 0, true)
SetEntityInvincible(npc, true)
SetEntityProofs(npc, true, true, true, true, true, true, 1, true)
SetBlockingOfNonTemporaryEvents(npc, true)
FreezeEntityPosition(npc, true)
SetPedDiesWhenInjured(npc, false)
SetEntityCanBeDamaged(npc, false)
SetPedCanRagdollFromPlayerImpact(npc, false)
SetPedCanRagdoll(npc, false)
SetEntityAsMissionEntity(npc, true, true)
SetEntityDynamic(npc, false)
Peds[id] = npc
end
end
for id, handle in pairs(Peds) do
local del = true
for i = 1, #ids do
if ids[i] == id then
del = false
tmpPeds[id] = handle
end
end
if del then
DeletePed(handle)
end
end
Peds = tmpPeds
end
function OpenUi(atm) function OpenUi(atm)
atm = atm or false atm = atm or false
isInMenu = true isInMenu = true
@@ -129,7 +79,7 @@ function OpenUi(atm)
end end
local function CloseUi() local function CloseUi()
SetNuiFocus(false) SetNuiFocus(false, false)
isInMenu = false isInMenu = false
SendNUIMessage({ SendNUIMessage({
showMenu = false showMenu = false
@@ -144,8 +94,7 @@ end
local function ShowMarker(coord) local function ShowMarker(coord)
CreateThread(function() CreateThread(function()
while isMarkerShowed do while isMarkerShowed do
DrawMarker(20, coord.x, coord.y, coord.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3, 0.2, 0.2, 187, 255, 0, 255, DrawMarker(20, coord.x, coord.y, coord.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3, 0.2, 0.2, 187, 255, 0, 255, false, true, 2, false, nil, nil, false)
false, true, 2, nil, nil, false)
Wait(0) Wait(0)
end end
end) end)
@@ -159,19 +108,6 @@ local function StartThread()
_PlayerPedId = PlayerPedId() _PlayerPedId = PlayerPedId()
_GetEntityCoords = GetEntityCoords(_PlayerPedId) _GetEntityCoords = GetEntityCoords(_PlayerPedId)
if Config.EnablePeds then
local closestPed = {}
for i = 1, #Config.Peds do
local distance = #(_GetEntityCoords - Config.Peds[i].Position.xyz)
if distance <= Config.DrawMarker then
closestPed[#closestPed + 1] = i
end
end
PedHandler(closestPed)
end
if IsPedOnFoot(PlayerPedId()) then if IsPedOnFoot(PlayerPedId()) then
local closestBank = {} local closestBank = {}
@@ -261,6 +197,21 @@ RegisterNetEvent('esx_banking:closebanking', function()
CloseUi() CloseUi()
end) end)
RegisterNetEvent('esx_banking:PedHandler', function(netIdTable)
local npc
for i = 1, #netIdTable do
npc = NetworkGetEntityFromNetworkId(netIdTable[i])
TaskStartScenarioInPlace(npc, Config.Peds[i].Scenario, 0, true)
SetEntityProofs(npc, true, true, true, true, true, true, true, true)
SetBlockingOfNonTemporaryEvents(npc, true)
FreezeEntityPosition(npc, true)
SetPedCanRagdollFromPlayerImpact(npc, false)
SetPedCanRagdoll(npc, false)
SetEntityAsMissionEntity(npc, true, true)
SetEntityDynamic(npc, false)
end
end)
RegisterNetEvent('esx_banking:updateMoneyInUI') RegisterNetEvent('esx_banking:updateMoneyInUI')
AddEventHandler('esx_banking:updateMoneyInUI', function(doingType, bankMoney, money) AddEventHandler('esx_banking:updateMoneyInUI', function(doingType, bankMoney, money)
SendNUIMessage({ SendNUIMessage({
@@ -275,23 +226,20 @@ end)
-- Resource starting -- Resource starting
AddEventHandler('onResourceStart', function(resource) AddEventHandler('onResourceStart', function(resource)
if resource ~= GetCurrentResourceName() then if resource ~= GetCurrentResourceName() then return end
return
end
StartThread() StartThread()
end) end)
-- Enables it on player loaded -- Enables it on player loaded
RegisterNetEvent('esx:playerLoaded', function() RegisterNetEvent('esx:playerLoaded', function()
StartThread() StartThread()
end) end)
-- Resource stopping -- Resource stopping
AddEventHandler('onResourceStop', function(resource) AddEventHandler('onResourceStop', function(resource)
if resource ~= GetCurrentResourceName() then if resource ~= GetCurrentResourceName() then return end
return
end
RemoveBlips() RemoveBlips()
if isInMenu then if isInMenu then
CloseUi() CloseUi()
end end
end) end)
+1 -1
View File
@@ -2,7 +2,7 @@ Config = {
Debug = false, Debug = false,
DrawMarker = 10, DrawMarker = 10,
Locale = GetConvar('esx:locale', 'en'), Locale = GetConvar('esx:locale', 'en'),
EnablePeds = true, EnablePeds = true,
AtmModels = {`prop_fleeca_atm`, `prop_atm_01`, `prop_atm_02`, `prop_atm_03`}, AtmModels = {`prop_fleeca_atm`, `prop_atm_01`, `prop_atm_02`, `prop_atm_03`},
Banks = { Banks = {
{ {
+1 -1
View File
@@ -4,7 +4,7 @@ game 'gta5'
description 'ESX banking' description 'ESX banking'
lua54 'yes' lua54 'yes'
version '1.8.5' version '1.8.6'
shared_scripts { shared_scripts {
'@es_extended/imports.lua', '@es_extended/imports.lua',
+39 -15
View File
@@ -1,3 +1,5 @@
local spawnedPeds, netIdTable = {}, {}
-- get keys utils -- get keys utils
local function get_key(t) local function get_key(t)
local key local key
@@ -9,28 +11,34 @@ end
-- Resource starting -- Resource starting
AddEventHandler('onResourceStart', function(resourceName) AddEventHandler('onResourceStart', function(resourceName)
if (GetCurrentResourceName() ~= resourceName) then if (GetCurrentResourceName() ~= resourceName) then return end
return if Config.EnablePeds then BANK.CreatePeds() end
end
local twoMonthMs = (os.time() - 5259487) * 1000 local twoMonthMs = (os.time() - 5259487) * 1000
MySQL.Sync.fetchScalar('DELETE FROM banking WHERE time < ? ', {twoMonthMs}) MySQL.Sync.fetchScalar('DELETE FROM banking WHERE time < ? ', {twoMonthMs})
end) end)
AddEventHandler('onResourceStop', function(resourceName)
if (GetCurrentResourceName() ~= resourceName) then return end
if Config.EnablePeds then BANK.DeletePeds() end
end)
AddEventHandler('esx:playerLoaded', function(playerId, xPlayer)
if not Config.EnablePeds then return end
TriggerClientEvent('esx_banking:PedHandler', playerId, netIdTable)
end)
-- event -- event
RegisterServerEvent('esx_banking:doingType') RegisterServerEvent('esx_banking:doingType')
AddEventHandler('esx_banking:doingType', function(typeData) AddEventHandler('esx_banking:doingType', function(typeData)
if source == nil then if source == nil then return end
return if (typeData == nil) then return end
end
if (typeData == nil) then
return
end
local source = source local source = source
local xPlayer = ESX.GetPlayerFromId(source) local xPlayer = ESX.GetPlayerFromId(source)
local identifier = xPlayer.getIdentifier() local identifier = xPlayer.getIdentifier()
local money = xPlayer.getAccount('money').money local money = xPlayer.getAccount('money').money
local bankMoney = xPlayer.getAccount('bank').money local bankMoney = xPlayer.getAccount('bank').money
local amount
local key = get_key(typeData) local key = get_key(typeData)
if typeData.deposit then if typeData.deposit then
@@ -43,9 +51,7 @@ AddEventHandler('esx_banking:doingType', function(typeData)
amount = tonumber(typeData.pincode) amount = tonumber(typeData.pincode)
end end
if not tonumber(amount) then if not tonumber(amount) then return end
return
end
amount = ESX.Math.Round(amount) amount = ESX.Math.Round(amount)
if amount == nil or (not typeData.pincode and amount <= 0) then if amount == nil or (not typeData.pincode and amount <= 0) then
@@ -116,6 +122,24 @@ end)
-- bank functions -- bank functions
BANK = { BANK = {
CreatePeds = function()
for i = 1, #Config.Peds do
local model = Config.Peds[i].Model
local coords = Config.Peds[i].Position
spawnedPeds[i] = CreatePed(0, model, coords.x, coords.y, coords.z, coords.w, true, true)
netIdTable[i] = NetworkGetNetworkIdFromEntity(spawnedPeds[i])
while not DoesEntityExist(spawnedPeds[i]) do Wait(50) end
end
Wait(100)
TriggerClientEvent('esx_banking:PedHandler', -1, netIdTable)
end,
DeletePeds = function()
for i = 1, #spawnedPeds do
DeleteEntity(spawnedPeds[i])
spawnedPeds[i] = nil
end
end,
Withdraw = function(amount, xPlayer) Withdraw = function(amount, xPlayer)
xPlayer.addAccountMoney('money', amount) xPlayer.addAccountMoney('money', amount)
xPlayer.removeAccountMoney('bank', amount) xPlayer.removeAccountMoney('bank', amount)
@@ -132,7 +156,7 @@ BANK = {
xPlayer.removeAccountMoney('bank', amount) xPlayer.removeAccountMoney('bank', amount)
xTarget.addAccountMoney('bank', amount) xTarget.addAccountMoney('bank', amount)
bankMoney = xTarget.getAccount('bank').money local bankMoney = xTarget.getAccount('bank').money
BANK.LogTransaction(xTarget.source, "TRANSFER_RECEIVE", amount, bankMoney) BANK.LogTransaction(xTarget.source, "TRANSFER_RECEIVE", amount, bankMoney)
TriggerClientEvent("esx:showNotification", xTarget.source, TranslateCap('receive_transfer', amount, xPlayer.source), TriggerClientEvent("esx:showNotification", xTarget.source, TranslateCap('receive_transfer', amount, xPlayer.source),
"success") "success")
@@ -151,5 +175,5 @@ BANK = {
MySQL.insert('INSERT INTO banking (identifier, type, amount, time, balance) VALUES (?, ?, ?, ?, ?)', MySQL.insert('INSERT INTO banking (identifier, type, amount, time, balance) VALUES (?, ?, ?, ?, ?)',
{identifier, logType, amount, os.time() * 1000, bankMoney}) {identifier, logType, amount, os.time() * 1000, bankMoney})
end end
} }