Alen141 Posted July 22, 2013 Share Posted July 22, 2013 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
Castillo Posted July 22, 2013 Share Posted July 22, 2013 Well, the problem is that you aren't sending any "id", so on the server side, "id" is nil. Link to comment
Alen141 Posted July 22, 2013 Author Share Posted July 22, 2013 Well, the problem is that you aren't sending any "id", so on the server side, "id" is nil. how to tell client to send "id" to server side EDIT : how to tell client that "id" is second value Link to comment
Castillo Posted July 22, 2013 Share Posted July 22, 2013 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. Link to comment
Alen141 Posted July 22, 2013 Author Share Posted July 22, 2013 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
Castillo Posted July 22, 2013 Share Posted July 22, 2013 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
Alen141 Posted July 22, 2013 Author Share Posted July 22, 2013 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 Link to comment
Vision Posted July 22, 2013 Share Posted July 22, 2013 Change this guiSetVisible(jobWnd,false) to this guiSetVisible(vehWnd,false) Link to comment
Alen141 Posted July 22, 2013 Author Share Posted July 22, 2013 Change this guiSetVisible(jobWnd,false) to this guiSetVisible(vehWnd,false) hahaha thx, when I used function from my job script Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now