kieran Posted December 8, 2017 Share Posted December 8, 2017 I am trying to make a grid list GUI, the idea is to add the contents of the table to the grid list, and then check the first column against the table data, if the name is equal to the row index on table, then get the xyz and create a marker. Made the GUI, but making the marker is what I'm struggling with... --x, y, z, location, cash Locations = { [1] = {-1351.5205078125, -503.66796875, 14.171875, "SF Airport", 15000}, [2] = {2838.658203125, 999.6708984375, 10.75, "East LV", 12000}, [3] = {2262.89453125, 2792.927734375, 10.8203125, "Near KACC", 12500} } window = {} local Name local marker function showGUI() local screenW, screenH = guiGetScreenSize() window = guiCreateWindow((screenW - 498) / 2, (screenH - 266) / 2, 498, 266, "Shipments", false) guiWindowSetSizable(window, false) gridlist = guiCreateGridList(9, 27, 479, 194, false, window) colLocation = guiGridListAddColumn(gridlist, "Location", 0.33) colDistance = guiGridListAddColumn(gridlist, "Distance", 0.33) colCash = guiGridListAddColumn(gridlist, "Cash", 0.33) for i=1,#Locations do --For loop shows location, distance (rounded to integer) and the cash player will get local x,y,z,text,cash = Locations[i][1],Locations[i][2],Locations[i][3],Locations[i][4],Locations[i][5] local px,py,pz = getElementPosition(localPlayer) --Player position local distance = getDistanceBetweenPoints3D(px,py,pz,x,y,z) --Distance between player and location local row = guiGridListAddRow ( gridlist,text, math.floor(distance), cash ) end btn_acc = guiCreateButton(72, 231, 140, 25, "Accept", false, window) guiSetFont(btn_acc, "sa-header") btn_exit = guiCreateButton(284, 231, 140, 25, "Exit", false, window) guiSetFont(btn_exit, "sa-header") addEventHandler("onClientDoubleClick", root, DoubleClick) --Handler for double click end addEvent("TruckerStart", true) addEventHandler("TruckerStart", getRootElement(), showGUI) function DoubleClick (button) if button == "left" then Name = guiGridListGetItemText(gridlist,guiGridListGetSelectedItem(gridlist),1) --Get the name (Location[4]) outputChatBox(""..Name) --Testing to see if it gets the name --Something to iterate through table and check if the Name is equals to ^"Name"^, then create a marker after it gets the Locations x,y,z from table local marker = createMarker( x,y,z-1,"cylinder", 3, 0, 100, 0, 100 ) end end Any help is appreciated, or even a pointer to a site where it explains how to get 1 row in a table. Link to comment
TRtam Posted December 9, 2017 Share Posted December 9, 2017 This should work: function DoubleClick (button) if button == "left" then Name = guiGridListGetItemText(gridlist,guiGridListGetSelectedItem(gridlist),1) --Get the name (Location[4]) outputChatBox(""..Name) --Testing to see if it gets the name --Something to iterate through table and check if the Name is equals to ^"Name"^, then create a marker after it gets the Locations x,y,z from table local x, y, z for i=1,#Locations do if Name == Locations[i][4] then x, y, z = Locations[i][1], Locations[i][2], Locations[i][3] end end local marker = createMarker( x,y,z-1,"cylinder", 3, 0, 100, 0, 100 ) end end 1 Link to comment
kieran Posted December 9, 2017 Author Share Posted December 9, 2017 @TRtam I thought it was something like this, but first ever grid list script that's working with tables haha, worked perfect thanks! 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