Files
ND_Core/ND_Banks/source/client.lua

185 lines
5.1 KiB
Lua
Raw Normal View History

2022-07-08 23:19:28 +02:00
-- For support join my discord: https://discord.gg/Z9Mxu72zZ6
NDCore = exports["ND_Core"]:GetCoreObject()
2022-07-08 23:19:28 +02:00
local display = false
local nearModel = false
local banks = {
2022-08-15 03:10:52 +02:00
{
["coords"] = vector3(1175.77, 2706.89, 38.09), -- harmony fleeca bank
["name"] = "Fleeca Bank"
},
2022-08-15 03:10:52 +02:00
{
["coords"] = vector3(149.23, -1040.57, 29.36), -- legion square fleeca bank
["name"] = "Fleeca Bank"
},
2022-08-15 03:10:52 +02:00
{
["coords"] = vector3(-2962.53, 482.25, 15.69),
["name"] = "Fleeca Bank"
},
2022-08-15 03:10:52 +02:00
{
["coords"] = vector3(-112.02, 6469.13, 31.62), -- paleto bay bank
["name"] = "Blaine County Savings Bank"
},
2022-08-15 03:10:52 +02:00
{
["coords"] = vector3(-351.56, -49.70, 49.02),
["name"] = "Fleeca Bank"
},
2022-08-15 03:10:52 +02:00
{
["coords"] = vector3(313.66, -278.90, 54.16),
["name"] = "Fleeca Bank"
2022-08-15 03:10:52 +02:00
}
2022-07-08 23:19:28 +02:00
}
local days = {
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
}
-- Get the time
function getTime()
local hours = GetClockHours()
local minutes = GetClockMinutes()
if hours <= 9 then
hours = "0" .. hours
end
if minutes <= 9 then
minutes = "0" .. minutes
end
return hours .. ":" .. minutes
end
-- Hide/Show ui
function SetDisplay(bool)
2022-07-16 00:12:02 -04:00
local selectedCharacter = NDCore.Functions.GetSelectedCharacter()
2022-07-08 23:19:28 +02:00
display = bool
SetNuiFocus(bool, bool)
SendNUIMessage({
status = bool,
2022-08-15 03:10:52 +02:00
playerName = selectedCharacter.firstName .. " " .. selectedCharacter.lastName,
balance = "Account Balance: $" .. selectedCharacter.bank .. ".00",
2022-07-08 23:19:28 +02:00
date = days[GetClockDayOfWeek() + 1],
time = getTime()
})
end
function drawText3D(coords, text)
local onScreen, _x, _y = GetScreenCoordFromWorldCoord(coords.x, coords.y, coords.z + 0.3)
2022-07-08 23:19:28 +02:00
local pX, pY, pZ = table.unpack(GetGameplayCamCoords())
SetTextScale(0.4, 0.4)
SetTextFont(4)
SetTextProportional(1)
SetTextEntry("STRING")
SetTextCentre(true)
SetTextColour(255, 255, 255, 255)
SetTextOutline()
AddTextComponentString(text)
DrawText(_x, _y)
end
-- check if ped is close to a bank coordinate.
function inRange(ped)
playerCoords = GetEntityCoords(ped)
for _, bank in pairs(banks) do
if (#(playerCoords - bank.coords)) < 1.5 then
return bank.coords
2022-07-08 23:19:28 +02:00
end
end
return false
end
Citizen.CreateThread(function()
while true do
Citizen.Wait(500)
ped = PlayerPedId()
nearModel = inRange(ped)
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if not display and nearModel then
drawText3D(nearModel, "~w~Press ~g~E ~w~to use the bank")
if IsControlJustPressed(0, 51) then
SetDisplay(true)
TriggerScreenblurFadeIn(1000)
end
end
end
end)
CreateThread(function()
2022-08-15 03:10:52 +02:00
for _, blips in ipairs(banks) do
local blip = AddBlipForCoord(blips.coords)
SetBlipSprite(blip, 431)
SetBlipColour(blip, 2)
SetBlipScale(blip, 1.0)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(blips.name)
EndTextCommandSetBlipName(blip)
end
end)
2022-07-08 23:19:28 +02:00
-- close the ui.
RegisterNUICallback("close", function(data)
PlaySoundFrontend(-1, "PIN_BUTTON", "ATM_SOUNDS", 1)
SetDisplay(false)
TriggerScreenblurFadeOut(1000)
end)
-- makes a button sount for when the ui is clicked.
RegisterNUICallback("sound", function(data)
PlaySoundFrontend(-1, "PIN_BUTTON", "ATM_SOUNDS", 1)
end)
-- deposit/withdraw
RegisterNUICallback("useATM", function(data)
local action = string.gsub(data.action, " ", "")
if action == "WITHDRAW" then
if data.amount == "" then
Citizen.Wait(1000)
SendNUIMessage({
success = false
})
return
end
TriggerServerEvent("ND_Banks:withdraw", data.amount)
elseif action == "DEPOSIT" then
if data.amount == "" then
Citizen.Wait(1000)
SendNUIMessage({
success = false
})
return
end
TriggerServerEvent("ND_Banks:deposit", data.amount)
elseif action == "TRANSFER" then
if data.transferAmount == "" or data.transferTarget == "" then
Citizen.Wait(1000)
SendNUIMessage({
success = false
})
return
end
TriggerServerEvent("ND_Banks:transfer", data.transferAmount, data.transferTarget)
end
end)
-- update the balance on the ui and confirm if the deposit/withdraw was successful.
RegisterNetEvent("ND_Banks:update")
AddEventHandler("ND_Banks:update", function(status)
Citizen.Wait(1000)
2022-07-16 00:12:02 -04:00
local selectedCharacter = NDCore.Functions.GetSelectedCharacter()
2022-07-08 23:19:28 +02:00
SendNUIMessage({
balance = "Account Balance: $" .. selectedCharacter.bank .. ".00",
2022-07-08 23:19:28 +02:00
success = status
})
2022-08-15 03:10:52 +02:00
end)