sloved- closed
hamood192244 opened this issue · comments
hello
i want help for esx_vehicleshop
how to lock and unlock vehicles with ranks
for example
if i have [rank 20] i can unlock models for buy it and there some cars i have to get [rank 30] to unlock
it's possible if its possible how ?
I wish you a happy and fulfilling day <3
Hamood
Check the FAQ
For esx_vehicleshop
you could do something like this:
- Add reward vehicles to
config.lua
inesx_vehicleshop
:
Config.RewardVehicles = {
20 = {
models = { "voltic", "tyrus" },
locked = true
},
30 = {
models = { "voltic2", "turismor" },
locked = true
}
}
-
Perform a check in the
OpenShopMenu()
function inclient/main.lua
ofesx_vehicleshop
to see if the model is locked and either prevent it from being shown or prevent it from being purchased until player is at the correct rank. -
Listen for the
esx_xp:rankUp
event and set the vehicles as unlocked:
AddEventHandler("esx_xp:rankUp", function(newRank, previousRank)
local Rewards = Config.RewardVehicles[newRank]
if Rewards ~= nil and type(Rewards) == "table" then
Rewards.locked = false
end
end)
Thank you so much for your answer and help <3
but there small problem
i do your steps and there error show to me wen i paste the "Config.RewardVehicles"
config.lua in esx_vehicleshop
https://gyazo.com/8f90b57e24a3516bfb7649c6abc34ae4
i hope you know the problem
Thank you so much
Sorry, there were missing commas on the models
lines. I'vwe updated it.
i check there another problem
Config.RewardVehicles = {
20 = {
models = { "voltic", "tyrus" },
locked = true
},
30 = {
models = { "voltic2", "turismor" },
locked = true
}
}
20 and 30 should in this place no number it's wrong
when i replace it with letters the script run with out errors
i don't know in programing
but i'm learning
i think should like that maybe ?
https://gyazo.com/762067fab18f6e92ba8d52412ad59163
i know it's wrong XD
This worked for me. It prevents purchase of the vehicles until the player reaches the correct rank.
- Edit
Config.RewardCars
:
Config.RewardCars = {
{
models = { "vxr", "17toylc" },
rank = 10
},
{
models = { "bison", "landv6" },
rank = 20
}
}
- In
client/main.lua
add the following function above theOpenShopMenu()
function:
function IsVehicleLocked(tab, model)
for k, v in pairs(tab) do
for k2, vmodel in pairs(v.models) do
if vmodel == model then
return tonumber(v.rank)
end
end
end
return false
end
- In
client/main.lua
find theOpenShopMenu()
function and find the following line:
table.insert(options, ('%s <span style="color:green;">%s</span>'):format(vehicle.name, _U('generic_shopitem', ESX.Math.GroupDigits(vehicle.price))))
Replace that line with the following code:
local rankLocked = IsVehicleLocked(Config.RewardCars, vehicle.model)
-- Hide price and show locked text if player rank is less than required rank
if rankLocked ~= false and ESX.GetPlayerData().rank < rankLocked then
table.insert(options, ('%s <span style="color:green;">%s</span>'):format(vehicle.name, _U('generic_shopitem', "Locked (" .. rankLocked .. ")")))
else
table.insert(options, ('%s <span style="color:green;">%s</span>'):format(vehicle.name, _U('generic_shopitem', ESX.Math.GroupDigits(vehicle.price))))
end
- In
client/main.lua
find theOpenShopMenu()
function and find the following line:
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'shop_confirm', {
Add this code above that line:
-- Prevent purchase if player rank is less than required rank
local rankLocked = IsVehicleLocked(Config.RewardCars, vehicleData.model)
if rankLocked ~= false and ESX.GetPlayerData().rank < rankLocked then
ESX.ShowNotification("~r~ERROR: ~w~You can't purchase this car until you reach Rank " .. rankLocked)
return false
end
thank youu so much
it's work but there small small problem
`local rankLocked = IsVehicleLocked(Config.RewardCars, vehicle.model)
-- Hide price and show locked text if player rank is less than required rank
if rankLocked ~= false and ESX.GetPlayerData().rank < rankLocked then
table.insert(options, ('%s %s'):format(vehicle.name, _U('generic_shopitem', "Locked (" .. rankLocked .. ")")))
else
table.insert(options, ('%s %s'):format(vehicle.name, _U('generic_shopitem', ESX.Math.GroupDigits(vehicle.price))))
end`
https://gyazo.com/1930875913330df0be34efcd5c4e1678
there problem here
when i start the script with out this it's start and the rank system work
but don't show the You can't purchase this car until you reach Rank
just showing the price and i can't buy it becuse it's work
but when insert the if rankLocked ~= false and ESX.GetPlayerData().rank < rankLocked then
doesn't work
showing in F8 problem
do you have discord ?
I know I'm bothering you but I'm sorry
We are close to finish this
Can you help a little
And I really appreciate what you do here
all hearts in the world to you <3 <3 <3 <3
t
function IsVehicleLocked(tab, model)
for k, v in pairs(tab) do
for k2, vmodel in pairs(v.models) do
if vmodel == model then
return tonumber(v.rank)
end
end
end
return false
end
function OpenShopMenu()
if #Vehicles == 0 then
print('[esx_vehicleshop] [^3ERROR^7] No vehicles found')
return
end
IsInShopMenu = true
StartShopRestriction()
ESX.UI.Menu.CloseAll()
local playerPed = PlayerPedId()
FreezeEntityPosition(playerPed, true)
SetEntityVisible(playerPed, false)
SetEntityCoords(playerPed, Config.Zones.ShopInside.Pos)
local vehiclesByCategory = {}
local elements = {}
local firstVehicleData = nil
for i=1, #Categories, 1 do
vehiclesByCategory[Categories[i].name] = {}
end
for i=1, #Vehicles, 1 do
if IsModelInCdimage(GetHashKey(Vehicles[i].model)) then
table.insert(vehiclesByCategory[Vehicles[i].category], Vehicles[i])
else
print(('[esx_vehicleshop] [^3ERROR^7] Vehicle "%s" does not exist'):format(Vehicles[i].model))
end
end
for k,v in pairs(vehiclesByCategory) do
table.sort(v, function(a, b)
return a.name < b.name
end)
end
for i=1, #Categories, 1 do
local category = Categories[i]
local categoryVehicles = vehiclesByCategory[category.name]
local options = {}
for j=1, #categoryVehicles, 1 do
local vehicle = categoryVehicles[j]
if i == 1 and j == 1 then
firstVehicleData = vehicle
end
local rankLocked = IsVehicleLocked(Config.RewardCars, vehicle.model)
-- Hide price and show locked text if player rank is less than required rank
if rankLocked ~= false and ESX.GetPlayerData().rank < rankLocked then
table.insert(options, ('%s <span style="color:green;">%s</span>'):format(vehicle.name, _U('generic_shopitem', "Locked (" .. rankLocked .. ")")))
else
table.insert(options, ('%s <span style="color:green;">%s</span>'):format(vehicle.name, _U('generic_shopitem', ESX.Math.GroupDigits(vehicle.price))))
end
end
table.sort(options)
table.insert(elements, {
name = category.name,
label = category.label,
value = 0,
type = 'slider',
max = #Categories[i],
options = options
})
end
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'vehicle_shop', {
title = _U('car_dealer'),
align = 'top-left',
elements = elements
}, function(data, menu)
local vehicleData = vehiclesByCategory[data.current.name][data.current.value + 1]
-- Prevent purchase if player rank is less than required rank
local rankLocked = IsVehicleLocked(Config.RewardCars, vehicleData.model)
if rankLocked ~= false and ESX.GetPlayerData().rank < rankLocked then
ESX.ShowNotification("~r~ERROR: ~w~You can't purchase this car until you reach Rank " .. rankLocked)
return false
end
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'shop_confirm', {
title = _U('buy_vehicle_shop', vehicleData.name, ESX.Math.GroupDigits(vehicleData.price)),
align = 'top-left',
elements = {
{label = _U('no'), value = 'no'},
{label = _U('yes'), value = 'yes'}
}}, function(data2, menu2)
if data2.current.value == 'yes' then
if Config.EnablePlayerManagement then
ESX.TriggerServerCallback('esx_vehicleshop:buyCarDealerVehicle', function(success)
if success then
IsInShopMenu = false
DeleteDisplayVehicleInsideShop()
CurrentAction = 'shop_menu'
CurrentActionMsg = _U('shop_menu')
CurrentActionData = {}
local playerPed = PlayerPedId()
FreezeEntityPosition(playerPed, false)
SetEntityVisible(playerPed, true)
SetEntityCoords(playerPed, Config.Zones.ShopEntering.Pos)
menu2.close()
menu.close()
ESX.ShowNotification(_U('vehicle_purchased'))
else
ESX.ShowNotification(_U('broke_company'))
end
end, vehicleData.model)
else
local generatedPlate = GeneratePlate()
ESX.TriggerServerCallback('esx_vehicleshop:buyVehicle', function(success)
if success then
IsInShopMenu = false
menu2.close()
menu.close()
DeleteDisplayVehicleInsideShop()
ESX.Game.SpawnVehicle(vehicleData.model, Config.Zones.ShopOutside.Pos, Config.Zones.ShopOutside.Heading, function(vehicle)
TaskWarpPedIntoVehicle(playerPed, vehicle, -1)
SetVehicleNumberPlateText(vehicle, generatedPlate)
FreezeEntityPosition(playerPed, false)
SetEntityVisible(playerPed, true)
end)
else
ESX.ShowNotification(_U('not_enough_money'))
end
end, vehicleData.model, generatedPlate)
end
else
menu2.close()
end
end, function(data2, menu2)
menu2.close()
end)
I do like that there some misstake?
Mobius1
can you help please </3
1
hello
Mobius1 can u help please </3
l
hello @Mobius1
is it possible to communicate with you on discord ?
Will provide a guide on a simple esx_vehicleshop
integration, currently working on esx_properties
esx_vehicleshop - buy cars by rank
Same approach as on esx_weaponshop
, using corresponding SQL-tables to store required rank information.
SQL
alter table sesx.vehicles add column rank int default 0;
-- rank cars by price, not sure this is good/balanced
update sesx.vehicles set rank = 5 where price > 50000;
update sesx.vehicles set rank = 10 where price > 100000;
update sesx.vehicles set rank = 15 where price > 250000;
Code
Client
Author: Lars Bergmann
Date: Mon Nov 16 15:53:04 2020 +0100
Vehicleshop rank integration
diff --git a/resources/[esx]/esx_vehicleshop/client/main.lua b/resources/[esx]/esx_vehicleshop/client/main.lua
index a6d2a2b..b1977f9 100644
--- a/resources/[esx]/esx_vehicleshop/client/main.lua
+++ b/resources/[esx]/esx_vehicleshop/client/main.lua
@@ -161,7 +161,7 @@ function OpenShopMenu()
firstVehicleData = vehicle
end
- table.insert(options, ('%s <span style="color:green;">%s</span>'):format(vehicle.name, _U('generic_shopitem', ESX.Math.GroupDigits(vehicle.price))))
+ table.insert(options, ('%s <span style="color:green;">%s</span> (%s)'):format(vehicle.name, _U('generic_shopitem', ESX.Math.GroupDigits(vehicle.price)), vehicle.rank))
end
table.insert(elements, {
@@ -228,8 +228,8 @@ function OpenShopMenu()
if data3.current.value == 'personnal' then
- ESX.TriggerServerCallback('esx_vehicleshop:buyVehicle', function(hasEnoughMoney)
- if hasEnoughMoney then
+ ESX.TriggerServerCallback('esx_vehicleshop:buyVehicle', function(msg)
+ if msg == 'ok' then
IsInShopMenu = false
menu3.close()
@@ -254,8 +254,10 @@ function OpenShopMenu()
FreezeEntityPosition(playerPed, false)
SetEntityVisible(playerPed, true)
- else
+ elseif msg == 'money' then
ESX.ShowNotification(_U('not_enough_money'))
+ else
+ ESX.ShowNotification('Rank too low!')
end
end, vehicleData.model)
@@ -294,8 +296,8 @@ function OpenShopMenu()
menu3.close()
end)
else
- ESX.TriggerServerCallback('esx_vehicleshop:buyVehicle', function(hasEnoughMoney)
- if hasEnoughMoney then
+ ESX.TriggerServerCallback('esx_vehicleshop:buyVehicle', function(msg)
+ if msg == 'ok' then
IsInShopMenu = false
menu2.close()
menu.close()
@@ -318,8 +320,10 @@ function OpenShopMenu()
FreezeEntityPosition(playerPed, false)
SetEntityVisible(playerPed, true)
- else
+ elseif msg == 'money' then
ESX.ShowNotification(_U('not_enough_money'))
+ else
+ ESX.ShowNotification("Rank too low!")
end
end, vehicleData.model)
end
@@ -979,4 +983,4 @@ Citizen.CreateThread(function()
LoadInterior(interiorID)
EnableInteriorProp(interiorID, 'csr_beforeMission') -- Load large window
RefreshInterior(interiorID)
-end)
\ No newline at end of file
+end)
Server
diff --git a/resources/[esx]/esx_vehicleshop/server/main.lua b/resources/[esx]/esx_vehicleshop/server/main.lua
index 0010802..55cf5a4 100644
--- a/resources/[esx]/esx_vehicleshop/server/main.lua
+++ b/resources/[esx]/esx_vehicleshop/server/main.lua
@@ -201,6 +201,7 @@ end)
ESX.RegisterServerCallback('esx_vehicleshop:buyVehicle', function(source, cb, vehicleModel)
local xPlayer = ESX.GetPlayerFromId(source)
+ local playerRank = xPlayer.get("rank")
local vehicleData
for i=1, #Vehicles, 1 do
@@ -210,11 +211,18 @@ ESX.RegisterServerCallback('esx_vehicleshop:buyVehicle', function(source, cb, ve
end
end
+
+ if playerRank < vehicleData.rank then
+ xPlayer.showNotification("Rank too low!")
+ cb("rank")
+ return
+ end
+
if vehicleData and xPlayer.getMoney() >= vehicleData.price then
xPlayer.removeMoney(vehicleData.price)
- cb(true)
+ cb("ok")
else
- cb(false)
+ cb("money")
end
end)