From 1461983069898f1a14262841444c1427b3bb512b Mon Sep 17 00:00:00 2001 From: Mohab Date: Mon, 28 Jul 2025 15:22:58 +0300 Subject: [PATCH 1/3] feat: GUI vehicle test spawning --- [examples]/test_vehicles/c_test_gui.lua | 69 +++++++++++++++++++++++++ [examples]/test_vehicles/meta.xml | 1 + [examples]/test_vehicles/s_test_cmd.lua | 21 ++++++++ 3 files changed, 91 insertions(+) create mode 100644 [examples]/test_vehicles/c_test_gui.lua diff --git a/[examples]/test_vehicles/c_test_gui.lua b/[examples]/test_vehicles/c_test_gui.lua new file mode 100644 index 0000000..874e674 --- /dev/null +++ b/[examples]/test_vehicles/c_test_gui.lua @@ -0,0 +1,69 @@ +local screenW, screenH = guiGetScreenSize() + +local windowW, windowH = 300, 200 +local windowX, windowY = (screenW - windowW) / 2, (screenH - windowH) / 2 +local window = guiCreateWindow(windowX, windowY, windowW, windowH, "Vehicle Spawner", false) + +local label = guiCreateLabel(20, 40, 260, 30, "Enter Vehicle ID:", false, window) +guiLabelSetHorizontalAlign(label, "center") + +local input = guiCreateEdit(50, 70, 200, 30, "", false, window) + +local spawnButton = guiCreateButton(50, 120, 200, 40, "Spawn Vehicle", false, window) + +guiSetVisible(window, false) + +function requestVehicleSpawn() + local vehicleIDText = guiGetText(input) + local vehicleID = tonumber(vehicleIDText) + + if not vehicleID then + outputChatBox("Error: Please enter a valid number!", 255, 0, 0) + return + end + + local x, y, z = getElementPosition(localPlayer) + local rot = getPedRotation(localPlayer) + + local offsetDistance = 5 + local spawnX = x + offsetDistance * math.sin(math.rad(-rot)) + local spawnY = y + offsetDistance * math.cos(math.rad(-rot)) + + guiSetVisible(window, false) + showCursor(false) + + guiSetText(input, "") + triggerServerEvent("spawnVehicleServer", resourceRoot, localPlayer, vehicleID, spawnX, spawnY, z, rot) +end + +addEventHandler("onClientGUIClick", spawnButton, requestVehicleSpawn, false) + +addEvent("vehicleSpawnResult", true) +addEventHandler("vehicleSpawnResult", localPlayer, function(success, message) + if success then + outputChatBox(message, 0, 255, 0) + else + outputChatBox(message, 255, 0, 0) + end +end) + +function onInputEnter() + if source == input then + requestVehicleSpawn() + end +end + +addEventHandler("onClientGUIAccepted", input, onInputEnter) + +function toggleGUI() + local visible = guiGetVisible(window) + guiSetVisible(window, not visible) + showCursor(not visible) + + if not visible then + guiBringToFront(input) + guiFocus(input) + end +end + +bindKey("F4", "down", toggleGUI) diff --git a/[examples]/test_vehicles/meta.xml b/[examples]/test_vehicles/meta.xml index 3815a66..8bbf630 100644 --- a/[examples]/test_vehicles/meta.xml +++ b/[examples]/test_vehicles/meta.xml @@ -3,6 +3,7 @@