CLIENT side:
local vehicles =
{
"Patriot"
}
function openGUI ( )
window = guiCreateWindow (0.3,0.2,0.3,0.6,"SACR Car spawn",true)
gridlist = guiCreateGridList (0.1,0.1,0.8,0.7,true,window)
column = guiGridListAddColumn( gridlist, "Vehicles:", 0.85 )
for index, vehicle in ipairs ( vehicles ) do
local row = guiGridListAddRow ( gridlist )
guiGridListSetItemText ( gridlist, row, column, tostring ( vehicle ), false, false )
end
button = guiCreateButton (0.6,0.85,0.4,0.1,"Spawn",true,window)
close = guiCreateButton(0,0.85,0.4,0.1,"Close",true,window)
showCursor ( true )
end
addEvent ( "openGUI", true )
addEventHandler ( "openGUI", root, openGUI )
function destroyGUI()
destroyElement(window)
showCursor (false)
window = nil
end
function buttonClick ( )
if ( source == button ) then -- "row" is not a GUI element.
local row, col = guiGridListGetSelectedItem ( gridlist ) -- Get the selected item from the grid list.
if ( row and col and row ~= -1 and col ~= -1 ) then -- If he has a selected item.
local vehicleName = guiGridListGetItemText ( gridlist, row, col ) -- Get the text of it.
triggerServerEvent ( "vehicle", localPlayer, getVehicleModelFromName ( vehicleName ) ) -- Trigger the "vehicle" event with a vehicle model argument.
destroyGUI ()
end
elseif ( source == close ) then
destroyGUI ()
end
end
addEventHandler ( "onClientGUIClick", getRootElement(), buttonClick )