Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions [gameplay]/licenseplate/client.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
local GUI = {
button = {},
window = {},
label = {},
edit = {}
}

local isWindowOpen = false

function createLicenseWindow()
if GUI.window[1] then return end

GUI.window[1] = guiCreateWindow(671, 319, 307, 152, "License plate", false)
guiWindowSetSizable(GUI.window[1], false)

GUI.edit[1] = guiCreateEdit(13, 46, 284, 44, "", false, GUI.window[1])
GUI.label[1] = guiCreateLabel(16, 23, 281, 19, "Specify the number you want to install.", false, GUI.window[1])
guiSetFont(GUI.label[1], "default-bold-small")

GUI.button[1] = guiCreateButton(9, 104, 129, 38, "Set the number", false, GUI.window[1])
GUI.button[2] = guiCreateButton(168, 104, 129, 38, "Cancel", false, GUI.window[1])

guiSetVisible(GUI.window[1], false)
end

function showLicenseWindow()
if isWindowOpen then
hideLicenseWindow()
return
end

if not GUI.window[1] then
createLicenseWindow()
end
guiSetVisible(GUI.window[1], true)
guiSetInputEnabled(true)
guiBringToFront(GUI.window[1])
guiSetText(GUI.edit[1], "")
isWindowOpen = true
end

function hideLicenseWindow()
if GUI.window[1] then
guiSetVisible(GUI.window[1], false)
guiSetInputEnabled(false)
isWindowOpen = false
end
end

addCommandHandler("setplate", showLicenseWindow)
addCommandHandler("license", showLicenseWindow)

function onClientGUIClick(button, state)
if button ~= "left" or state ~= "up" then return end
local clicked = source
if clicked == GUI.button[1] then
local plate = guiGetText(GUI.edit[1])
plate = plate:gsub("^%s*(.-)%s*$", "%1")

if plate == "" then
outputChatBox("Please enter a license plate number.", 255, 0, 0)
return
end

if #plate > 8 then
outputChatBox("License plate cannot exceed 8 characters.", 255, 0, 0)
return
end

-- (Optionally – uncomment if necessary)
-- if not string.match(plate, "^[A-Za-z0-9 ]+$") then
-- outputChatBox("License plate contains invalid characters. Use only letters, numbers and spaces.", 255, 0, 0)
-- return
-- end

local vehicle = getPedOccupiedVehicle(localPlayer)
if not vehicle then
outputChatBox("You are not in a vehicle.", 255, 0, 0)
return
end

triggerServerEvent("LicensePlate:set", localPlayer, vehicle, plate)
hideLicenseWindow()

elseif clicked == GUI.button[2] then
hideLicenseWindow()
end
end
addEventHandler("onClientGUIClick", root, onClientGUIClick)
7 changes: 7 additions & 0 deletions [gameplay]/licenseplate/meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<meta>
<info author="MTA contributors (github.com/multitheftauto/mtasa-resources)" version="1.0" type="script" description="Basic license plate" />

<script src="client.lua" type="client" />

<script src="server.lua" type="server" />
</meta>
26 changes: 26 additions & 0 deletions [gameplay]/licenseplate/server.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
addEvent("LicensePlate:set", true)
addEventHandler("LicensePlate:set", root,
function(vehicle, plate)
local player = source

if not player or not isElement(player) then return end
if not vehicle or not isElement(vehicle) then return end

if getPedOccupiedVehicle(player) ~= vehicle then
outputChatBox("You are not in that vehicle.", player, 255, 0, 0)
return
end

if #plate > 8 then
outputChatBox("License plate too long.", player, 255, 0, 0)
return
end
--[[if not string.match(plate, "^[A-Za-z0-9 ]+$") then
outputChatBox("Invalid characters in license plate.", player, 255, 0, 0)
return
end]]

setVehiclePlateText(vehicle, plate)
outputChatBox("License plate set to: " .. plate, player, 0, 255, 0)
end
)