I create a personal menu and i want help… When the player click on “Spawn personal vehicle” the command is automaticly executed and the vehicule spawn…
This code doesnt work:
véhicle.lua (client)
local spawn
RegisterNUICallback("vehicles", function(data, cb)
local action = data.action
if action == "spawn" then
TriggerServerEvent("menupersonal:vehicleSpawn")
drawNotification("~g~Votre véhicule a spawn")
end
cb("ok")
end)
And Server.lua
require "resources/essentialmode/lib/MySQL"
MySQL:open("127.0.0.1", "gta5_gamemode_essential", "root", "1234")
RegisterServerEvent('menupersonal:vehicleSpawn')
AddEventHandler('menupersonal:vehicleSpawn', function()
print("Player ID " ..source)
local player = user.identifier
local executed_query = MySQL:executeQuery("SELECT * FROM users WHERE identifier = '@username'",{['@username'] = player})
local car = MySQL:getResults(executed_query, {'personalvehicle'})
local playerPed = GetPlayerPed(-1)
local playerCoords = GetEntityCoords(playerPed)
pv.veh = CreateVehicle(car, playerCoords, 0.0, true, false)
SetVehRadioStation(pv.veh, "OFF")
SetPedIntoVehicle(playerPed, pv.veh, -1)
SetVehicleEngineOn(pv.veh, true, false, false)
end)
One thing I would suggest as well is…however annoying it might be that people don’t reply just be patient.
Someone will eventually reply, by ‘upping’ your post you can negatively impact the replies.
Search google for LUA tutorials, start out with the basics and also look at scripts that are already released on the forums and try and understand how they work.
Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if IsControlJustPressed(1,Keys["H"]) then
NameOfMenu() -- Menu to draw
Menu.hidden = not Menu.hidden -- Hide/Show the menu
end
Menu.renderGUI() -- Draw menu on each tick if Menu.hidden = false
end
end)
That is used to trigger your Menu, so you would press H key to active it.
To add a Menu add this function to your client side script :
function NameOfMenu()
MenuTitle = "Title of the menu"
ClearMenu()
Menu.addButton("First Button","FunctionName1","arg")
Menu.addButton("Second Button","FunctionName2",nil) -- No arg
-- ...
end
This is the code you need to look at, I’m limited with the assistance I can give you at the moment as I’m at work.
The menu is fonctional but its the command when i click on the menu for spawn the vehicle the vehicle doesnt spawn… I search the command for execute the command when a player click on the menu…
<div id="vehiclesmenu" data-parent="mainmenu">
<p class="traineroption" data-action="vehicles spawn">Spawn my personal vehicle[WIP]</p>
</div>
and my script lua is “vehicle.lua”
local spawn
RegisterNUICallback("vehicles", function(data, cb)
local action = data.action
if action == "spawn" then
TriggerClientEvent("chatMessage", -1, "", {255, 255, 255}, "/pv")
drawNotification("~g~Your vehicle has spawned")
end
cb("ok")
end)