Gtagasje Posted February 22, 2012 Posted February 22, 2012 Hi, I have made a vehicle gui already, and I know how to make it, but I always made it with buttons. Now, I need a lot of vehicles in a gui, so buttons is not an option anymore. So I made this gui with a gridlist, a column, and some rows, that shows up when you hit a marker. But now, I want it to spawn a vehicle, when you press the button spawn, and have a row selected. Ex: I have selected the row "Police Rancher" and click on spawn, and now I get a police rancher. But if I have not selected any row, it says in the chatbox "Please select a row first!". I dont have the code yet, cus I dont know a shit about gridlists. I hope any off you can help me with it. This is my whole code(client side): local VehMarker1 = createMarker( 1026.4000244141, -1451.4000244141, 13, 'cylinder', 1.0, 0, 0, 255, 255 ) local teams = {["SWAT"] = true, ["Staff"] = true} function createVehGui () MainGui = guiCreateWindow(308,125,400,485,"LWC SWAT Vehicle Panel",false) VehGrid = guiCreateGridList(70,55,261,287,false,MainGui) guiGridListSetSelectionMode(VehGrid,2) VehCol = guiGridListAddColumn(VehGrid,"SWAT Vehicles",0.2) Spawn = guiCreateButton(39,393,145,67,"Spawn",false,MainGui) guiSetFont(Spawn,"clear-normal") Cancel = guiCreateButton(219,393,145,67,"Cancel",false,MainGui) guiSetFont(Cancel,"clear-normal") PolLS = guiGridListAddRow (VehGrid) guiGridListSetItemText ( VehGrid, PolLS, VehCol, "Police LS", false, false ) PolLV = guiGridListAddRow (VehGrid) guiGridListSetItemText ( VehGrid, PolLV, VehCol, "Police LV", false, false ) PolSF = guiGridListAddRow (VehGrid) guiGridListSetItemText ( VehGrid, PolSF, VehCol, "Police SF", false, false ) PolRan = guiGridListAddRow (VehGrid) guiGridListSetItemText ( VehGrid, PolRan, VehCol, "Police Rancher", false, false ) PolEnf = guiGridListAddRow (VehGrid) guiGridListSetItemText ( VehGrid, PolEnf, VehCol, "Police Enforcer", false, false ) SWATTruck = guiGridListAddRow (VehGrid) guiGridListSetItemText ( VehGrid, SWATTruck, VehCol, "SWAT Truck", false, false ) end addEventHandler("onClientMarkerHit", vehMarker, function ( hitElement ) if hitElement == localPlayer and getPlayerTeam ( hitElement ) and teams[getTeamName(getPlayerTeam ( hitElement ))] then createVehGui ( hitElement ) if (MainGui ~= nil) then guiSetVisible(MainGui, true) showCursor(true) guiSetInputEnabled(true) else outputChatBox ("Error: Please Re-enter the marker to get your vehicle keys.", getRootElement(), 255, 0, 0) end end end ) Thanks in advance. Gtagasje. Yes, this is infact a signature.
Castillo Posted February 22, 2012 Posted February 22, 2012 -- client side: local VehMarker1 = createMarker( 1026.4000244141, -1451.4000244141, 13, 'cylinder', 1.0, 0, 0, 255, 255 ) local teams = {["SWAT"] = true, ["Staff"] = true} local vehicles = {"Police LS", "Police LV", "Police SF", "Police Rancher", "Police Enforcer", "SWAT Truck"} function createVehGui () MainGui = guiCreateWindow(308,125,400,485,"LWC SWAT Vehicle Panel",false) VehGrid = guiCreateGridList(70,55,261,287,false,MainGui) guiGridListSetSelectionMode(VehGrid,2) VehCol = guiGridListAddColumn(VehGrid,"SWAT Vehicles",0.2) Spawn = guiCreateButton(39,393,145,67,"Spawn",false,MainGui) guiSetFont(Spawn,"clear-normal") Cancel = guiCreateButton(219,393,145,67,"Cancel",false,MainGui) guiSetFont(Cancel,"clear-normal") for index, vehicle in ipairs(vehicles) do local row = guiGridListAddRow (VehGrid) guiGridListSetItemText ( VehGrid, row, VehCol, tostring(vehicle), false, false ) end end addEventHandler("onClientMarkerHit", vehMarker, function ( hitElement ) if (hitElement == localPlayer and getPlayerTeam ( hitElement ) and teams[getTeamName(getPlayerTeam ( hitElement ))]) then createVehGui ( hitElement ) if (MainGui ~= nil) then guiSetVisible(MainGui, true) showCursor(true) guiSetInputEnabled(true) else outputChatBox ("Error: Please Re-enter the marker to get your vehicle keys.", 255, 0, 0) end end end ) addEventHandler("onClientGUIClick", root, function () if (source == Spawn) then local row,col = guiGridListGetSelectedItem(VehGrid) if (row and col and row ~= -1 and col ~= -1) then local vehicleName = guiGridListGetItemText(VehGrid, row, 1) triggerServerEvent("spawnVehicle",localPlayer,vehicleName) else outputChatBox("Error: Please select a vehicle from the list.",255,0,0) end elseif (source == Cancel) then guiSetVisible(MainGui, false) showCursor(false) guiSetInputEnabled(false) end end ) -- server side: local vehicles = {} addEvent("spawnVehicle",true) addEventHandler("spawnVehicle",root, function (vehicleName) local model = getVehicleModelFromName(vehicleName) local x, y, z = getElementPosition(source) if isElement(vehicles[source]) then destroyElement(vehicles[source]) end vehicles[source] = createVehicle(model, x+2, y, z) end ) San Andreas Utopia RPG (SAUR) Owner & Developer. Education is the most powerful weapon which you can use to change the world.
Kenix Posted February 22, 2012 Posted February 22, 2012 Server addEvent( "spawnVehicle",true ) local vehicles = { } addEventHandler( "spawnVehicle",root, function ( vehicleName ) local model = getVehicleModelFromName( vehicleName ) if model then local x, y, z = getElementPosition( source ) if isElement( vehicles[ source ] ) then destroyElement( vehicles[ source ] ) end vehicles[ source ] = createVehicle( model, x+2, y, z ) end end ) addEventHandler( "onPlayerQuit",root, function ( ) if vehicles[ source ] and #vehicles[ source ] > 0 then for _,v in pairs( vehicles[ source ] ) do if isElement( v ) then destroyElement( v ) end end vehicles[ source ] = nil end end ) Client local VehMarker1 = createMarker( 1026.4000244141, -1451.4000244141, 13, 'cylinder', 1.0, 0, 0, 255, 255 ) local teams = {["SWAT"] = true, ["Staff"] = true} local vehicles = {"Police LS", "Police LV", "Police SF", "Police Rancher", "Police Enforcer", "SWAT Truck"} function createVehGui () MainGui = guiCreateWindow(308,125,400,485,"LWC SWAT Vehicle Panel",false) VehGrid = guiCreateGridList(70,55,261,287,false,MainGui) guiGridListSetSelectionMode(VehGrid,2) VehCol = guiGridListAddColumn(VehGrid,"SWAT Vehicles",0.2) Spawn = guiCreateButton(39,393,145,67,"Spawn",false,MainGui) guiSetFont(Spawn,"clear-normal") Cancel = guiCreateButton(219,393,145,67,"Cancel",false,MainGui) guiSetFont(Cancel,"clear-normal") for index, vehicle in ipairs(vehicles) do local row = guiGridListAddRow (VehGrid) guiGridListSetItemText ( VehGrid, row, VehCol, tostring(vehicle), false, false ) end end addEventHandler("onClientMarkerHit", vehMarker, function ( hitElement ) if (hitElement == localPlayer and getPlayerTeam ( hitElement ) and teams[getTeamName(getPlayerTeam ( hitElement ))]) then createVehGui ( hitElement ) if (MainGui ~= nil) then guiSetVisible(MainGui, true) showCursor(true) guiSetInputEnabled(true) else outputChatBox ("Error: Please Re-enter the marker to get your vehicle keys.", 255, 0, 0) end end end ) addEventHandler("onClientGUIClick", root, function () if (source == Spawn) then local row,col = guiGridListGetSelectedItem(VehGrid) if (row and col and row ~= -1 and col ~= -1) then local vehicleName = guiGridListGetItemText(VehGrid, row, 1) if vehicleName then triggerServerEvent("spawnVehicle",localPlayer,vehicleName) end else outputChatBox("Error: Please select a vehicle from the list.",255,0,0) end elseif (source == Cancel) then guiSetVisible(MainGui, false) showCursor(false) guiSetInputEnabled(false) end end ) http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
Gtagasje Posted February 23, 2012 Author Posted February 23, 2012 Thanks both off you for helping me! Yes, this is infact a signature.
Kenix Posted February 23, 2012 Posted February 23, 2012 No problem. http://vk.com/the_kenix Вопросы задавайте на форуме, не пишите мне в личку. Please don't pm me.
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