Jump to content

GUI Gridlist car spawner


Alen141

Recommended Posts

Hey guys,I want to make car spawner gui, like some servers have but I have problems creating vehicle!

My Clientside:

  
  
vehWnd = guiCreateWindow(324, 200, 468, 387, "Police Vehicle Spawner", false) 
guiWindowSetSizable(vehWnd, false) 
guiSetVisible(vehWnd, false) 
  
carsG = guiCreateGridList(59, 137, 131, 220, false, vehWnd) 
guiGridListAddColumn(carsG, "Vehicle", 0.9) 
  
    vehicles = 
            { 
            {"Police Car", 596}, 
            {"Police Ranger", 599},           
            } 
  
    for i,vehicles in ipairs(vehicles) do 
    row = guiGridListAddRow(carsG) 
    guiGridListSetItemText(carsG, row, 1, tostring(vehicles[1]), false, false) 
    guiGridListSetItemData(carsG, row, 1, tostring(vehicles[2])) 
end 
guiGridListAddRow(carsG) 
guiGridListSetItemText(carsG, 0, 1, "Car Name", false, false) 
spawnbtn = guiCreateButton(205, 314, 125, 43, "Spawn", false, vehWnd) 
desc = guiCreateMemo(43, 33, 384, 94, "Here you can spawn yourself a vehicle!\n", false, vehWnd) 
guiMemoSetReadOnly(desc, true) 
  
local vehmarker = createMarker ( 1555.4000244141, -1610.9000244141,12.300000190735, "cylinder", 2.5, 100, 149, 237, 170 ) 
  
function spawnStart(hitElement) 
             if getElementType(hitElement) == "player" and (hitElement == localPlayer) then 
                  if not guiGetVisible(vehWnd) then 
                       guiSetVisible(vehWnd, true) 
                       showCursor(true) 
                  end 
             end 
        end 
addEventHandler("onClientMarkerHit", vehmarker, spawnStart) 
  
function spawnVeh() 
    if ( source == spawnbtn ) then             
        triggerServerEvent("spawn", getLocalPlayer()) 
        guiSetVisible(jobWnd,false) 
        showCursor(false) 
    end 
end 
addEventHandler("onClientGUIClick",root,spawnVeh) 

My Server Side:

function spawnVeh(id) 
local playerTeam = getPlayerTeam ( source )  
local teamName = ( playerTeam and getTeamName ( playerTeam ) or "" ) 
if ( teamName == "Police" ) then 
        local x,y,z = getElementPosition(source) 
        createVehicle(id,x+5,y,z) 
    end 
end 
addEvent("spawn", true) 
addEventHandler("spawn",root,spawnVeh) 

Link to comment
Get the selected item from your gridlist using:
guiGridListGetSelectedItem 

then get the item data, which is the model:

guiGridListGetItemData 

then just send the result of that to the server side at triggerServerEvent.

  
  
vehWnd = guiCreateWindow(324, 200, 468, 387, "Police Vehicle Spawner", false) 
guiWindowSetSizable(vehWnd, false) 
guiSetVisible(vehWnd, false) 
  
carsG = guiCreateGridList(59, 137, 131, 220, false, vehWnd) 
guiGridListAddColumn(carsG, "Vehicle", 0.9) 
  
    vehicles = 
            { 
            {"Police Car", 596}, 
            {"Police Ranger", 599},           
            } 
  
    for i,vehicles in ipairs(vehicles) do 
    row = guiGridListAddRow(carsG) 
    guiGridListSetItemText(carsG, row, 1, tostring(vehicles[1]), false, false) 
    guiGridListSetItemData(carsG, row, 1, tostring(vehicles[2])) 
end 
guiGridListAddRow(carsG) 
spawnbtn = guiCreateButton(205, 314, 125, 43, "Spawn", false, vehWnd) 
desc = guiCreateMemo(43, 33, 384, 94, "Here you can spawn yourself a vehicle!\n", false, vehWnd) 
guiMemoSetReadOnly(desc, true) 
  
local vehmarker = createMarker ( 1555.4000244141, -1610.9000244141,12.300000190735, "cylinder", 2.5, 100, 149, 237, 170 ) 
  
function spawnStart(hitElement) 
             if getElementType(hitElement) == "player" and (hitElement == localPlayer) then 
                  if not guiGetVisible(vehWnd) then 
                       guiSetVisible(vehWnd, true) 
                       showCursor(true) 
                  end 
             end 
        end 
addEventHandler("onClientMarkerHit", vehmarker, spawnStart) 
  
function spawnVeh() 
    if ( source == spawnbtn ) then  
        local row, col = guiGridListGetSelectedItem( carsG ) 
        local name = guiGridListGetItemText( carsG, row, col )   
        if name == "Police Car" then 
        local id = 596 
        triggerServerEvent("spawn", getLocalPlayer(), id) 
        guiSetVisible(jobWnd,false) 
        showCursor(false) 
        elseif name == "Police Ranger" then 
        local id = 599 
        triggerServerEvent("spawn", getLocalPlayer(), id) 
        guiSetVisible(jobWnd,false) 
        showCursor(false) 
    end 
end 
end 
addEventHandler("onClientGUIClick",root,spawnVeh) 

i've done it but now window stays open, do you know why?

Link to comment
vehWnd = guiCreateWindow(324, 200, 468, 387, "Police Vehicle Spawner", false) 
guiWindowSetSizable(vehWnd, false) 
guiSetVisible(vehWnd, false) 
  
carsG = guiCreateGridList(59, 137, 131, 220, false, vehWnd) 
guiGridListAddColumn(carsG, "Vehicle", 0.9) 
  
    vehicles = 
            { 
            {"Police Car", 596}, 
            {"Police Ranger", 599},           
            } 
  
    for i,vehicles in ipairs(vehicles) do 
    row = guiGridListAddRow(carsG) 
    guiGridListSetItemText(carsG, row, 1, tostring(vehicles[1]), false, false) 
    guiGridListSetItemData(carsG, row, 1, tostring(vehicles[2])) 
end 
guiGridListAddRow(carsG) 
spawnbtn = guiCreateButton(205, 314, 125, 43, "Spawn", false, vehWnd) 
desc = guiCreateMemo(43, 33, 384, 94, "Here you can spawn yourself a vehicle!\n", false, vehWnd) 
guiMemoSetReadOnly(desc, true) 
  
local vehmarker = createMarker ( 1555.4000244141, -1610.9000244141,12.300000190735, "cylinder", 2.5, 100, 149, 237, 170 ) 
  
function spawnStart(hitElement) 
             if getElementType(hitElement) == "player" and (hitElement == localPlayer) then 
                  if not guiGetVisible(vehWnd) then 
                       guiSetVisible(vehWnd, true) 
                       showCursor(true) 
                  end 
             end 
        end 
addEventHandler("onClientMarkerHit", vehmarker, spawnStart) 
  
function spawnVeh() 
    if ( source == spawnbtn ) then 
        local row, col = guiGridListGetSelectedItem( carsG ) 
        local id = guiGridListGetItemData( carsG, row, col )  
        triggerServerEvent("spawn", getLocalPlayer(), id) 
        guiSetVisible(jobWnd,false) 
        showCursor(false) 
    end 
end 
addEventHandler("onClientGUIClick",root,spawnVeh) 

Link to comment
vehWnd = guiCreateWindow(324, 200, 468, 387, "Police Vehicle Spawner", false) 
guiWindowSetSizable(vehWnd, false) 
guiSetVisible(vehWnd, false) 
  
carsG = guiCreateGridList(59, 137, 131, 220, false, vehWnd) 
guiGridListAddColumn(carsG, "Vehicle", 0.9) 
  
    vehicles = 
            { 
            {"Police Car", 596}, 
            {"Police Ranger", 599},           
            } 
  
    for i,vehicles in ipairs(vehicles) do 
    row = guiGridListAddRow(carsG) 
    guiGridListSetItemText(carsG, row, 1, tostring(vehicles[1]), false, false) 
    guiGridListSetItemData(carsG, row, 1, tostring(vehicles[2])) 
end 
guiGridListAddRow(carsG) 
spawnbtn = guiCreateButton(205, 314, 125, 43, "Spawn", false, vehWnd) 
desc = guiCreateMemo(43, 33, 384, 94, "Here you can spawn yourself a vehicle!\n", false, vehWnd) 
guiMemoSetReadOnly(desc, true) 
  
local vehmarker = createMarker ( 1555.4000244141, -1610.9000244141,12.300000190735, "cylinder", 2.5, 100, 149, 237, 170 ) 
  
function spawnStart(hitElement) 
             if getElementType(hitElement) == "player" and (hitElement == localPlayer) then 
                  if not guiGetVisible(vehWnd) then 
                       guiSetVisible(vehWnd, true) 
                       showCursor(true) 
                  end 
             end 
        end 
addEventHandler("onClientMarkerHit", vehmarker, spawnStart) 
  
function spawnVeh() 
    if ( source == spawnbtn ) then 
        local row, col = guiGridListGetSelectedItem( carsG ) 
        local id = guiGridListGetItemData( carsG, row, col )  
        triggerServerEvent("spawn", getLocalPlayer(), id) 
        guiSetVisible(jobWnd,false) 
        showCursor(false) 
    end 
end 
addEventHandler("onClientGUIClick",root,spawnVeh) 

window is still not closing from some reason but I can move 21ozs6a.jpg

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...