Skip to content

Commit

Permalink
new file: client/client.lua
Browse files Browse the repository at this point in the history
new file:   config.lua
new file:   fxmanifest.lua
new file:   locales/en.lua
new file:   locales/fr.lua
new file:   server/server.lua
  • Loading branch information
YOMAN1792 committed May 20, 2024
0 parents commit 7839e11
Show file tree
Hide file tree
Showing 6 changed files with 367 additions and 0 deletions.
154 changes: 154 additions & 0 deletions client/client.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
-- Function to create a menu option
local function createMenuOption(label, price, model)
local args = { price = price, label = label, model = model }
return {
title = label,
description = string.format(Language[Config.lang].Menu["locationDescriptionFormat"], label, price),
args = args,
-- Define what happens when this menu option is selected
onSelect = function(selected, secondary)
-- If debug mode is on, print some important information to the console
if Config.Debug == true then
print("onSelect called")
print("selected: ", selected)
print("args: ", args)
if args then
print("args.price: ", args.price)
print("args.label: ", args.label)
print("args.model: ", args.model)
end
end
-- Trigger a server event to handle the selection
TriggerServerEvent('{-YOMAN1792#2784-}::Location', args.price, args.label, args.model)
-- Hide the context menu
lib.hideContext()
end
}
end

-- Function to populate the context menu options
local function updateMenuOptions()
local options = {}

-- Add scooter options
table.insert(options, { title = Language[Config.lang].TwoWheels["title"], disabled = true })
for k, v in pairs(Config.TwoWheels.vehicles) do
table.insert(options, createMenuOption(v.label, v.price, v.model))
end

-- Add car options
table.insert(options, { title = Language[Config.lang].Cars["title"], disabled = true })
for k, v in pairs(Config.Cars.vehicles) do
table.insert(options, createMenuOption(v.label, v.price, v.model))
end


-- Update the context menu options
lib.registerContext({ id = 'Location', title = Language[Config.lang].Menu["Title"], options = options })
end

-- Call the function once to initialize the menu
updateMenuOptions()

-- Create a thread to show the context menu when the player is near the location
Citizen.CreateThread(function()
local waitTime = 500 -- Default wait time
local notificationShown = false -- Track if the notification has been shown
while true do
Citizen.Wait(waitTime)
local plyCoords = GetEntityCoords(GetPlayerPed(-1), false)
local nearMenu = false
for k in pairs(Config.PositionArea) do
local dist = Vdist(plyCoords.x, plyCoords.y, plyCoords.z, Config.PositionArea[k].x, Config.PositionArea[k].y, Config.PositionArea[k].z)
if dist <= 1.0 then
nearMenu = true
if not notificationShown then
ESX.ShowNotification(Language[Config.lang].Menu["Notification"])
notificationShown = true
end
if IsControlJustPressed(1, 51) then
lib.showContext('Location')
end
break -- Exit the loop as soon as we find a nearby menu
end
end
-- Adjust the wait time based on whether the player is near a menu
waitTime = nearMenu and 0 or 500
if not nearMenu then
notificationShown = false -- Reset the notification tracking when the player is not near a menu
end
end
end)

-- Register a network event that spawns a car when triggered
RegisterNetEvent('{-YOMAN1792#2784-}::Location:spawnCar')
AddEventHandler('{-YOMAN1792#2784-}::Location:spawnCar', function(car)
local status, error = pcall(function()
local model = GetHashKey(car)

-- Check if the model is loaded
if not HasModelLoaded(model) then
RequestModel(model)
while not HasModelLoaded(model) do
Citizen.Wait(0)
end
end

local retval = PlayerPedId()

-- Show a notification when the car is spawned
ESX.ShowAdvancedNotification(Language[Config.lang].NotifVehicleSpawn["sender"], Language[Config.lang].NotifVehicleSpawn["subject"], Language[Config.lang].NotifVehicleSpawn["msg"], Config.textureDict, 1)
RequestModel(car)
while not HasModelLoaded(car) do
RequestModel(car)
Citizen.Wait(0)
end

local x, y, z = table.unpack(GetEntityCoords(GetPlayerPed(-1), false))
Citizen.Wait(500)
local vehicle = CreateVehicle(car, Config.VehiclePosition.x, Config.VehiclePosition.y, Config.VehiclePosition.z,
Config.VehiclePosition.heading, true, false)
SetEntityAsMissionEntity(vehicle, true, true)
local plaque = Config.PlateName
SetVehicleNumberPlateText(vehicle, plaque)
TaskWarpPedIntoVehicle(PlayerPedId(), vehicle, -1)
end)
if not status then
print('^1An error occurred: ' .. error)
end
end)

-- PED
-- Create a thread to spawn a non-player character (NPC) at specified locations
Citizen.CreateThread(function()
local hash = GetHashKey("cs_lazlow")
while not HasModelLoaded(hash) do
RequestModel(hash)
Wait(20)
end
for k, v in pairs(Config.PosPed) do
ped = CreatePed("PED_TYPE_CIVMALE", "cs_lazlow", v.x, v.y, v.z, v.a, false, true)
SetBlockingOfNonTemporaryEvents(ped, true)
FreezeEntityPosition(ped, true)
SetEntityInvincible(ped, true)
end
end)


-- -- BLIPS
-- Create a thread to add blips (markers) on the game map at specified locations
Citizen.CreateThread(function()
for k, v in pairs(Config.BlipMap) do
local blip = AddBlipForCoord(v.x, v.y, v.z)

SetBlipSprite(blip, 225)
SetBlipScale(blip, 0.9)
SetBlipColour(blip, 43)
SetBlipAsShortRange(blip, true)

BeginTextCommandSetBlipName('STRING')
AddTextComponentSubstringPlayerName(Language[Config.lang].Menu["BlipName"])
EndTextCommandSetBlipName(blip)
end
end)

51 changes: 51 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Config = {
lang = "FR",

Debug = true,

PlateName = "Location",

-- The Logo of the Notifications
textureDict = "CHAR_BANK_MAZE",

BlipMap = {
{ x = -1032.6223, y = -2729.5947, z = 20.1314 }
},

-- sets near the ped so when the player enter in the 1 M radius they can open the menu
PositionArea = {
{ x = -1034.8305, y = -2733.0974, z = 20.1692 }
},

PosPed = {
{ x = -1034.5335, y = -2732.4450, z = 19.1692, a = 151.5 }
},

Cars = {
vehicles = {
-- Model you enter the spawn name abd label you enter the name that will be shown on the menu.
-- You can add as many as you wish.
{ model = "blista", label = "Blista", price = 500 },
}
},

TwoWheels = {
vehicles = {
-- Model you enter the spawn name abd label you enter the name that will be shown on the menu.
-- You can add as many as you wish.
{ model = "faggio", label = "Faggio", price = 200 },
}
},

--Vehicle Spawn Position
VehiclePosition = {
x = -1032.6223,
y = -2729.5947,
z = 20.1314,
heading = 240.00
},
}

Language = {}

-- Script Created by YOMAN1792
31 changes: 31 additions & 0 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
fx_version 'cerulean'
game 'gta5'
lua54 'yes'

author 'YOMAN1792'
description 'Location system done with OX_LIB for Esx'
version '1.0'


client_script "client/client.lua"
server_scripts {
'@oxmysql/lib/MySQL.lua',
'server/server.lua'
}


shared_scripts {
'@es_extended/imports.lua',
'@ox_lib/init.lua',
'config.lua',
'locales/*.lua',
}


dependencie 'es_extended'


escrow_ignore {
'config.lua',
'locales/*.lua',
}
24 changes: 24 additions & 0 deletions locales/en.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Language["EN"] = {
Menu = {
["locationDescriptionFormat"] = "Rent a %s for %d$",
["BlipName"] = "Car Rental",
["Title"] = "Vehicle Rental",
["Notification"] = "Press [~g~E~c~] to talk to the ~g~Renter",
},
TwoWheels = {
["title"] = "↓ Scooter ↓"
},
Cars = {
["title"] = "↓ Car ↓"
},
NotifVehicleSpawn = {
["sender"] = "Bank",
["subject"] = "~g~Payment accepted",
["msg"] = "Thank you for your trust, don't forget to respect the traffic rules!"
},
NotifNoMoney = {
["sender"] = "Bank",
["subject"] = "~r~Payment refused",
["msg"] = "Insufficient balance, please check it!"
}
}
24 changes: 24 additions & 0 deletions locales/fr.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Language["FR"] = {
Menu = {
["locationDescriptionFormat"] = "Louer un %s pour %d$",
["BlipName"] = "Location Voiture",
["Title"] = "Location Véhicule",
["Notification"] = "Appuyez sur [~g~E~c~] pour parler au ~g~Loueur",
},
TwoWheels = {
["title"] = "↓ Scooter ↓"
},
Cars = {
["title"] = "↓ Voiture ↓"
},
NotifVehicleSpawn = {
["sender"] = "Banque",
["subject"] = "~g~Payement accepté",
["msg"] = "Merci pour votre confiance, n'oubliez pas de respecter le code de la route !"
},
NotifNoMoney = {
["sender"] = "Banque",
["subject"] = "~r~Payement refusé",
["msg"] = "Solde insuffisant, merci de le vérifier !"
}
}
83 changes: 83 additions & 0 deletions server/server.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
RegisterNetEvent('{-YOMAN1792#2784-}::Location')
AddEventHandler('{-YOMAN1792#2784-}::Location', function(price, label, model)
local status, error = pcall(function()
local _source = source
local xPlayer = ESX.GetPlayerFromId(source)
local xMoney = xPlayer.getMoney()
local car = model

if xPlayer == nil then
print('Invalid player')
return
end

-- Validate the price
if type(price) ~= 'number' or price < 0 then
print('Invalid price')
return
end

-- Validate the car model
local modelExists = false
for _, v in pairs(Config.Cars.vehicles) do
if v.model == model then
modelExists = true
break
end
end
for _, v in pairs(Config.TwoWheels.vehicles) do
if v.model == model then
modelExists = true
break
end
end
if not modelExists then
print('Invalid car model')
return
end

if xMoney >= price then
xPlayer.removeMoney(price)
elseif xPlayer.getAccount("bank").money >= price then
xPlayer.removeAccountMoney("bank", price)
else
TriggerClientEvent('esx:showAdvancedNotification', source, Language[Config.lang].NotifNoMoney["sender"], Language[Config.lang].NotifNoMoney["subject"], Language[Config.lang].NotifNoMoney["msg"], Config.textureDict, 1)
return
end
TriggerClientEvent('{-YOMAN1792#2784-}::Location:spawnCar', source, car)
end)

AddEventHandler('onResourceStart', function(resourceName)
if (GetCurrentResourceName() ~= resourceName) then
return
end
print('The resource ' .. resourceName .. ' has been started. ^5:) Have a good day!')
print("^6This script was made by YOMAN1792")
print("For any questions please add me on discord : ^2YOMAN1792")
end)

AddEventHandler('onResourceStop', function(resourceName)
if (GetCurrentResourceName() ~= resourceName) then
return
end
print('The resource ' .. resourceName .. ' was stopped. ^5:) Have a good day!')
print("For any questions please add me : ^2YOMAN1792")
end)


if not status then
print('^1An error occurred: ' .. error)
end
end)




--[[
AddEventHandler('playerConnecting', function(playerName, setKickReason)
identifiers = GetPlayerIdentifiers(source)
for i in ipairs(identifiers) do
print('Player: ' .. playerName .. ', Identifier #' .. i .. ': ' .. identifiers[i])
end
end)
]]

0 comments on commit 7839e11

Please sign in to comment.