Bonjour, j’ai un problème, je débute dans le script et j’ai créée une location de véhicules pour mon serveur Tout fonctionne sauf que quand le joueur choisi un véhicule le véhicule spawn même s’il n’a pas l’argent sur lui mais la notification ‹ Vous n’avez pas assez d’argent › s’affiche quand même quand le véhicule spawn (voir photos). J’aimerai que quand le joueur a l’argent sur lui le véhicule spawn mais quand il n’a pas l’argent il ne spawn pas. je vous met des photos et mes scripts server et client. Merci de me venir en aide je galère depuis 4 jours.
fichier client.lua :
ESX = nil
Citizen.CreateThread(function()
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(100)
end
end)
RegisterCommand("co", function(source, args, rawcommand)
local pos = GetEntityCoords(PlayerPedId())
print(pos.x..", "..pos.y..", "..pos.z)
end, false)
RMenu.Add("Hijack", "menu", RageUI.CreateMenu("Location","Choisissez un véhicule à louer"))
RMenu:Get("Hijack", "menu").Closed = function()
end
---Point de la location
Citizen.CreateThread(function()
while true do
local interval = 1
local pos = GetEntityCoords(PlayerPedId())
local dest = vector3(-830.05,-1255.35, 5.5)
local distance = GetDistanceBetweenCoords(pos, dest, true)
DrawMarker(1, dest.x,dest.y, dest.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.1, 1.1, 1.1, 0, 128, 128, 170, 0, 1, 2, 0, nil, nil, 0)
if distance > 2 then
RageUI.CloseAll()
else
interval = 1
if distance < 2 then
AddTextEntry("HELP", "~b~Appuyez sur ~INPUT_CONTEXT~ ~b~pour voir les véhicules disponibles")
DisplayHelpTextThisFrame("HELP", false)
if IsControlJustPressed(1, 51) then
RageUI.Visible(RMenu:Get("Hijack","menu"), true)
end
end
end
Citizen.Wait(interval)
end
end)
-----Menu de location
Citizen.CreateThread(function()
while true do
RageUI.IsVisible(RMenu:Get("Hijack","menu"),true,true,true,function()
RageUI.ButtonWithStyle("~o~Panto ~p~===========-~m~LOCATION~m~-~p~===========>", "~w~Voiture commerciale", {RightLabel = "~r~500$"}, true,function(h,a,s)
if s then
TriggerServerEvent('location1', 500)
spawnCar("panto")
RageUI.CloseAll()
end
end)
RageUI.ButtonWithStyle("~o~Faggio ~p~===========-~m~LOCATION~m~-~p~===========>", "~w~Scooter", {RightLabel = "~r~300$"}, true,function(h,a,s)
if s then
TriggerServerEvent('location2', 300)
spawnCar("faggio")
RageUI.CloseAll()
end
end)
RageUI.ButtonWithStyle("~o~BMX ~p~===========-~m~LOCATION~m~-~p~===========>", "~w~Vélo tout-terrain", {RightLabel = "~r~75$"}, true,function(h,a,s)
if s then
TriggerServerEvent('location3', 75)
spawnCar("bmx")
RageUI.CloseAll()
end
end)
end, function()end, 1)
Citizen.Wait(0)
end
end)
--- function
function spawnCar(car)
local model = GetHashKey(car)
RequestModel(model)
while not HasModelLoaded(model) do Citizen.Wait(10) end
local vehicle = CreateVehicle(model, -836.50, -1273.13, 5.0, 90.0, true, false)
local plaque = "HIJACK-V"
SetVehicleNumberPlateText(vehicle, plaque)
TaskWarpPedIntoVehicle(PlayerPedId(), vehicle, -1)
end
--Ped et blips
DecorRegister("Yay", 4)
pedHash = "cs_barry"
zone = vector3( -825.25,-1259.53, 5.6)
zone2 = vector3(-830.05,-1255.35, 5.5)
Heading = 145.64
Ped = nil
HeadingSpawn = 145.64
--Ped et blips
Citizen.CreateThread(function()
LoadModel(pedHash)
Ped = CreatePed(2, GetHashKey(pedHash), zone, Heading, 0, 0)
DecorSetInt(Ped, "Yay", 5431)
FreezeEntityPosition(Ped, 1)
TaskStartScenarioInPlace(Ped, "WORLD_HUMAN_SMOKING", 0, false)
SetEntityInvincible(Ped, true)
SetBlockingOfNonTemporaryEvents(Ped, 1)
local blip = AddBlipForCoord(zone2)
SetBlipSprite(blip, 607)
SetBlipScale(blip, 0.7)
SetBlipShrink(blip, true)
SetBlipColour(blip, 46)
SetBlipAsShortRange(blip, true)
SetBlipSecondaryColour(blip, 24)
BeginTextCommandSetBlipName('STRING')
AddTextComponentString("Location de véhicules")
EndTextCommandSetBlipName(blip)
end)
fichier server.lua
ESX = nil
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
---- location
RegisterNetEvent('location1')
AddEventHandler('location1', function(prix)
local xPlayer = ESX.GetPlayerFromId(source)
local playerMoney = xPlayer.getMoney()
local _source = source
if xPlayer.getMoney() >= prix then
xPlayer.removeMoney(prix)
TriggerClientEvent('esx:showNotification', _source, "Vous avez loué une ~o~Panto~o~ ~w~pour~w~ ~g~500$")
else
TriggerClientEvent('esx:showNotification', _source, "~r~Vous n'avez pas assez d'argent")
end
end)
RegisterNetEvent('location2')
AddEventHandler('location2', function(prix)
local xPlayer = ESX.GetPlayerFromId(source)
local playerMoney = xPlayer.getMoney()
if xPlayer.getMoney() >= prix then
xPlayer.removeMoney(prix)
TriggerClientEvent('esx:showNotification', source, "~r~Vous avez loué une ~o~Faggio~o~ ~w~pour~w~ ~g~300$")
else
TriggerClientEvent('esx:showNotification', source, "Vous n'avez pas assez d'argent")
end
end)
RegisterNetEvent('location3')
AddEventHandler('location3', function(prix)
local xPlayer = ESX.GetPlayerFromId(source)
local playerMoney = xPlayer.getMoney()
local _source = source
if xPlayer.getMoney() >= prix then
xPlayer.removeMoney(prix)
TriggerClientEvent('esx:showNotification', _source, "Vous avez loué un ~o~BMX~o~ ~w~pour~w~ ~g~75$")
else
TriggerClientEvent('esx:showNotification', _source, "~r~Vous n'avez pas asse d'argent")
end
end)