Hassam Posted July 15, 2013 Share Posted July 15, 2013 Hello scripters, I'm creating this topic due, I had a some difficult about this: SwatCars = {416, 427, 490, 528, 523, 470, 598, 596, 597, 599, 601, 428, 541, 579, 560, 451, 495, 426, 551} function swatcars() for v = 400, 611 do if ( getVehicleNameFromModel ( v ) ~= "" ) then table.insert( SwatCars, { model = v, name = getVehicleNameFromModel ( v ) } ) end end table.sort( SwatCars, function(a, b) return a.name < b.name end ) end I can't put the names of cars from model, someone can help me? Thanks Edit: for index, swatcar in ipairs(SwatCars) do local row = guiGridListAddRow (CarGridswat) guiGridListSetItemText ( carGridswat, row, nameColswat, tostring(swatcar), false, false ) end Link to comment
DNL291 Posted July 15, 2013 Share Posted July 15, 2013 Try this: for index, swatcar in ipairs(SwatCars) do local row = guiGridListAddRow (CarGridswat) guiGridListSetItemText ( carGridswat, row, nameColswat, swatcar.name, false, false ) end Link to comment
Hassam Posted July 15, 2013 Author Share Posted July 15, 2013 Didn't worked attempt to index local 'swatcar' Edited, now worked something, but now I can't see the cars SwatCars = {416, 427, 490, 528, 523, 470, 598, 596, 597, 599, 601, 428, 541, 579, 560, 451, 495, 426, 551} function swatcars1() for v = 400, 611 do if ( getVehicleNameFromModel ( v ) ~= "" ) then table.insert( SwatCars, { model = v, name = getVehicleNameFromModel ( v ) } ) end end table.sort( SwatCars, function(a, b) return a.name < b.name end ) end another correction for index, swatcar in ipairs(SwatCars) do local row1 = guiGridListAddRow (carGridswat) guiGridListSetItemText ( carGridswat, row1, nameColswat, tostring(swatcar), false, false ) end Link to comment
DNL291 Posted July 15, 2013 Share Posted July 15, 2013 I tested this code and it worked for me (on the chatbox). --SwatCars = {416, 427, 490, 528, 523, 470, 598, 596, 597, 599, 601, 428, 541, 579, 560, 451, 495, 426, 551} local SwatCars = {} function swatcars() for v = 400, 611 do if ( getVehicleNameFromModel ( v ) ~= "" ) then table.insert( SwatCars, { model = v, name = getVehicleNameFromModel ( v ) } ) end end table.sort( SwatCars, function(a, b) return a.name < b.name end ) for index, swatcar in ipairs(SwatCars) do local row = guiGridListAddRow (CarGridswat) guiGridListSetItemText ( carGridswat, row, nameColswat, swatcar.name, false, false ) end end addEventHandler("onClientResourceStart", resourceRoot, swatcars) Link to comment
Hassam Posted July 15, 2013 Author Share Posted July 15, 2013 didn't worked, look at this gui: SwatCars = {416, 427, 490, 528, 523, 470, 598, 596, 597, 599, 601, 428, 541, 579, 560, 451, 495, 426, 551} function swatcars1() for v = 400, 611 do if ( getVehicleNameFromModel ( v ) ~= "" ) then table.insert( SwatCars, { model = v, name = getVehicleNameFromModel ( v ) } ) end end table.sort( SwatCars, function(a, b) return a.name < b.name end ) for index, swatcar in ipairs(SwatCars) do local row = guiGridListAddRow (carGridswat) guiGridListSetItemText ( carGridswat, row, nameColswat, swatcar.name, false, false ) end end addEventHandler("onClientResourceStart", resourceRoot, swatcars1) Gui carWinSwat = guiCreateWindow(rx / 2 - 150, ry / 2 - 167, 300, 337, "Select a vehicle to use", false) guiSetAlpha(carWinSwat, 0.95) guiSetVisible(carWinSwat, false) carGridswat = guiCreateGridList(11, 31, 285, 237, false, carWinSwat) guiGridListSetSelectionMode(carGridswat, 1) nameColswatcar = guiGridListAddColumn(carGridswat, "Vehicle Name", 0.-- s8) --> useBut_swat = guiCreateButton(20, 282, 108, 38, "Use Vehicle", false, carWinSwat) closeBut_swat = guiCreateButton(170, 282, 108, 38, "Cancel", false, carWinSwat) Link to comment
DNL291 Posted July 16, 2013 Share Posted July 16, 2013 I did not understand why you added some vehicle IDs in SwatCars table and you used for-loop to add all vehicle IDs in SwatCars table. Link to comment
Castillo Posted July 16, 2013 Share Posted July 16, 2013 Is because he copied it from admin panel resource, that's where he got how to sort the vehicles by name, but he didn't quite understand how it worked, so he thought he had to do the loop aswell. SwatCars = { 416, 427, 490, 528, 523, 470, 598, 596, 597, 599, 601, 428, 541, 579, 560, 451, 495, 426, 551 } function swatcars1 ( ) table.sort ( SwatCars, function ( a, b ) return ( getVehicleNameFromModel ( a ) < < getVehicleNameFromModel ( b ) ) end ) for _, swatcar in ipairs ( SwatCars ) do local row = guiGridListAddRow ( carGridswat ) guiGridListSetItemText ( carGridswat, row, nameColswat, getVehicleNameFromModel ( swatcar ), false, false ) end end addEventHandler ( "onClientResourceStart", resourceRoot, swatcars1 ) Try that. 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