Skip to content

Commit

Permalink
convert: esx_banking > bpt_banking
Browse files Browse the repository at this point in the history
  • Loading branch information
bitpredator committed Jun 9, 2024
1 parent 05c57eb commit 5592d66
Show file tree
Hide file tree
Showing 36 changed files with 2,520 additions and 3,646 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GNU GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

Expand Down Expand Up @@ -631,8 +631,8 @@ to attach them to the start of each source file to most effectively
state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.

esx_banking
Copyright (C) 2015-2023 Jérémie N'gadi
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) 2024 bitpredator

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -645,14 +645,14 @@ the "copyright" line and a pointer to where the full notice is found.
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <https://www.gnu.org/licenses/>.

Also add information on how to contact you by electronic and paper mail.

If the program does terminal interaction, make it output a short
notice like this when it starts in an interactive mode:

esx_banking Copyright (C) 2015-2023 Jérémie N'gadi
<program> Copyright (C) 2024 bitpredator
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
Expand All @@ -664,11 +664,11 @@ might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
For more information on this, and how to apply and follow the GNU GPL, see
<http://www.gnu.org/licenses/>.
<https://www.gnu.org/licenses/>.

The GNU General Public License does not permit incorporating your program
into proprietary programs. If your program is a subroutine library, you
may consider it more useful to permit linking proprietary applications with
the library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License. But first, please read
<http://www.gnu.org/philosophy/why-not-lgpl.html>.
<https://www.gnu.org/licenses/why-not-lgpl.html>.
19 changes: 19 additions & 0 deletions server-data/resources/[bpt_addons]/bpt_banking/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<h1 align='center'>bpt_banking</a></h1>
<p align='center'><a href='https://discord.gg/ksGfNvDEfq'>Discord</a>

Copyright (C) 2024 bitpredator

This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version.

This program Is distributed In the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty Of MERCHANTABILITY Or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License For more details.

ATTENTION:
You are not authorized to change the name of the resource and the resources within it.

If you want to contribute you can open a pull request.

You are not authorized to sell this software (this is free project).

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ CREATE TABLE IF NOT EXISTS `banking` (
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;

ALTER TABLE `users` ADD COLUMN `pincode` INT NULL;
ALTER TABLE `users` ADD COLUMN `pincode` INT NULL;
262 changes: 262 additions & 0 deletions server-data/resources/[bpt_addons]/bpt_banking/client/main.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
local BANK = {
Data = {}
}

local activeBlips, bankPoints, atmPoints, markerPoints = {}, {}, {}, {}
local playerLoaded, uiActive, inMenu = false, false, false

--Functions
-- General data collecting thread
function BANK:Thread()
self:CreateBlips()
local data = self.Data
data.ped = PlayerPedId()
data.coord = GetEntityCoords(data.Ped)
playerLoaded = true

CreateThread(function()
while playerLoaded do
data.coord = GetEntityCoords(data.ped)
data.ped = PlayerPedId()
bankPoints, atmPoints, markerPoints = {}, {}, {}

if (IsPedOnFoot(data.ped) and not ESX.PlayerData.dead) and not inMenu then
for i = 1, #Config.AtmModels do
local atm = GetClosestObjectOfType(data.coord.x, data.coord.y, data.coord.z, 0.7, Config.AtmModels
[i], false, false, false)
if atm ~= 0 then
atmPoints[#atmPoints + 1] = GetEntityCoords(atm)
end
end

for i = 1, #Config.Banks do
local bankDistance = #(data.coord - Config.Banks[i].Position.xyz)
if bankDistance <= 0.7 then
bankPoints[#bankPoints + 1] = Config.Banks[i].Position.xyz
end
if Config.ShowMarker and bankDistance <= (Config.DrawMarker or 10) then
markerPoints[#markerPoints + 1] = Config.Banks[i].Position.xyz
end
end
end

if next(bankPoints) and not uiActive then
self:TextUi(true)
end

if next(atmPoints) and not uiActive then
self:TextUi(true, true)
end

if not next(bankPoints) and not next(atmPoints) and uiActive then
self:TextUi(false)
end

Wait(1000)
end
end)

if not Config.ShowMarker then return end

CreateThread(function()
local wait = 1000
while playerLoaded do
if next(markerPoints) then
for i = 1, #markerPoints do
DrawMarker(20, markerPoints[i].x, markerPoints[i].y, markerPoints[i].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)
end
wait = 0
end
Wait(wait)
end
end)
end

-- Handle text ui / Keypress
function BANK:TextUi(state, atm)
uiActive = state
if not state then
return ESX.HideUI()
end
ESX.TextUI(TranslateCap('press_e_banking'))
CreateThread(function()
while uiActive do
if IsControlJustReleased(0, 38) then
self:HandleUi(true, atm)
self:TextUi(false)
end
Wait(0)
end
end)
end

-- Create Blips
function BANK:CreateBlips()
local tmpActiveBlips = {}
for i = 1, #Config.Banks do
if type(Config.Banks[i].Blip) == 'table' and Config.Banks[i].Blip.Enabled then
local position = Config.Banks[i].Position
local bInfo = Config.Banks[i].Blip
local blip = AddBlipForCoord(position.x, position.y, position.z)
SetBlipSprite(blip, bInfo.Sprite)
SetBlipScale(blip, bInfo.Scale)
SetBlipColour(blip, bInfo.Color)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName('STRING')
AddTextComponentSubstringPlayerName(bInfo.Label)
EndTextCommandSetBlipName(blip)
tmpActiveBlips[#tmpActiveBlips + 1] = blip
end
end

activeBlips = tmpActiveBlips
end

-- Remove blips
function BANK:RemoveBlips()
for i = 1, #activeBlips do
if DoesBlipExist(activeBlips[i]) then
RemoveBlip(activeBlips[i])
end
end
activeBlips = {}
end

-- Open / Close ui
function BANK:HandleUi(state, atm)
atm = atm or false
SetNuiFocus(state, state)
inMenu = state
ClearPedTasks(PlayerPedId())
if not state then
SendNUIMessage({
showMenu = false
})
return
end
ESX.TriggerServerCallback('bpt_banking:getPlayerData', function(data)
SendNUIMessage({
showMenu = true,
openATM = atm,
datas = {
your_money_panel = {
accountsData = { {
name = "cash",
amount = data.money
}, {
name = "bank",
amount = data.bankMoney
} }
},
bankCardData = {
bankName = TranslateCap('bank_name'),
cardNumber = "2232 2222 2222 2222",
createdDate = "08/08",
name = data.playerName
},
transactionsData = data.transactionHistory
}
})
end)
end

function BANK:LoadNpc(index, netID)
CreateThread(function()
while not NetworkDoesEntityExistWithNetworkId(netID) do
Wait(200)
end
local npc = NetworkGetEntityFromNetworkId(netID)
TaskStartScenarioInPlace(npc, Config.Peds[index].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

-- Events
RegisterNetEvent('bpt_banking:closebanking', function()
BANK:HandleUi(false)
end)

RegisterNetEvent('bpt_banking:pedHandler', function(netIdTable)
for i = 1, #netIdTable do
BANK:LoadNpc(i, netIdTable[i])
end
end)

RegisterNetEvent('bpt_banking:updateMoneyInUI', function(doingType, bankMoney, money)
SendNUIMessage({
updateData = true,
data = {
type = doingType,
bankMoney = bankMoney,
money = money
}
})
end)

-- Handlers
-- Resource starting
AddEventHandler('onResourceStart', function(resource)
if resource ~= GetCurrentResourceName() then return end
BANK:Thread()
end)

-- Enable the script on player loaded
RegisterNetEvent('esx:playerLoaded', function()
BANK:Thread()
end)

-- Disable the script on player logout
RegisterNetEvent('esx:onPlayerLogout', function()
playerLoaded = false
end)

-- Resource stopping
AddEventHandler('onResourceStop', function(resource)
if resource ~= GetCurrentResourceName() then return end
BANK:RemoveBlips()
if uiActive then BANK:TextUi(false) end
end)

RegisterNetEvent('esx:onPlayerDeath', function() BANK:TextUi(false) end)

-- Nui Callbacks
RegisterNUICallback('close', function(data, cb)
BANK:HandleUi(false)
cb('ok')
end)

RegisterNUICallback('clickButton', function(data, cb)
if not data or not inMenu then
return cb('ok')
end

TriggerServerEvent("bpt_banking:doingType", data)
cb('ok')
end)

RegisterNUICallback('checkPincode', function(data, cb)
if not data or not inMenu then
return cb('ok')
end

ESX.TriggerServerCallback("bpt_banking:checkPincode", function(pincode)
if pincode then
cb({
success = true
})
ESX.ShowNotification(TranslateCap('pincode_found'), "success")
else
cb({
error = true
})
ESX.ShowNotification(TranslateCap('pincode_not_found'), "error")
end
end, data)
end)
Loading

0 comments on commit 5592d66

Please sign in to comment.