StefanAlmighty Posted September 25, 2015 Share Posted September 25, 2015 So I'm making a teleport system GUI. I've made the GUI, but now I want to create an array and I want it to loop through my array and fill the gridlist with all the teleporter locations in the array? How would I go about doing this? Link to comment
KariiiM Posted September 25, 2015 Share Posted September 25, 2015 Create a table and loop the data from this table and send it to client side by trigger ,in case you created the table in client just loop it Use ipairs pairs to loop a table Link to comment
StefanAlmighty Posted September 25, 2015 Author Share Posted September 25, 2015 How would I create the table? I want it to store an ID, name and description. Link to comment
KariiiM Posted September 25, 2015 Share Posted September 25, 2015 How would I create the table? I want it to store an ID, name and description. You can create a table like that local aTable = {} --i created my table i named it aTable it's empty local aTable = { --after creating the table i filled it with IDs. {"id1"}, {"id2"}, {"id3"}, } There're alot of ways to do that ,it was just a simple example to understand, You can loop like this table by using ipairs or pairs no matter in this situation Link to comment
StefanAlmighty Posted September 25, 2015 Author Share Posted September 25, 2015 My gridlist has three columns, so I made a table: local data = { {"1", "Los Santos", "Pershing Square, the heart of Los Santos."} {"2", "DMV", "Department of Motor Vehicles."} } But now it wont work at all, not even the GUI. Link to comment
KariiiM Posted September 25, 2015 Share Posted September 25, 2015 Good job, but It's wrong must be like that local data = { {"1", "Los Santos", "Pershing Square, the heart of Los Santos."}, {"2", "DMV", "Department of Motor Vehicles."}, } If you stuck on something post the code, ~Good luck Link to comment
StefanAlmighty Posted September 25, 2015 Author Share Posted September 25, 2015 I modified it a bit so it contains the coordinates, interior, dimension etc. Here: local data = { -- X Y Z Int Dim Rot ls = {"1", "Los Santos", "Teleports you to Pershing Square, Los Santos.", 1479.9873046875, -1710.9453125, 13.36874961853, 0, 0, 0}, sf = {"2", "San Fierro", "Teleports you to Doherty, San Fierro.", -1988.5693359375, 507.0029296875, 35.171875, 0, 0, 90}, lv = {"3", "Las Venturas", "Teleports you to The Strip, Las Venturas", 1691.6801757813, 1449.1293945313, 10.765375, 0, 0, 268}, } I tried looping through them and adding them to my gridlist but it doesn't work, here's the code: for v, k in pairs(data) do gui.row = guiGridListAddRow(gui.grid) local a, b = gui.grid, gui.row guiGridListSetItemText(a, b, gui.colID, data[k][1], false, true) guiGridListSetItemText(a, b, gui.colValue, data[k][2], false, false) guiGridListSetItemText(a, b, gui.colDesc, data[k][3], false, false) end Link to comment
KariiiM Posted September 25, 2015 Share Posted September 25, 2015 Make sure gui.grid is defined as guiCreateGridList function and gui.colID ,gui.colValue, gui.colDesc are the columns local data = { -- X Y Z Int Dim Rot [1] = {"1", "Los Santos", "Teleports you to Pershing Square, Los Santos.", 1479.9873046875, -1710.9453125, 13.36874961853, 0, 0, 0}, [2] = {"2", "San Fierro", "Teleports you to Doherty, San Fierro.", -1988.5693359375, 507.0029296875, 35.171875, 0, 0, 90}, [3] = {"3", "Las Venturas", "Teleports you to The Strip, Las Venturas", 1691.6801757813, 1449.1293945313, 10.765375, 0, 0, 268}, } for index, v in pairs(data) do local row = guiGridListAddRow(gui.grid) guiGridListSetItemText(gui.grid, row, gui.colID, v[1], false, true) guiGridListSetItemText(gui.grid, row, gui.colValue, v[2], false, false) guiGridListSetItemText(gui.grid, row, gui.colDesc, v[3], false, false) end Link to comment
StefanAlmighty Posted September 25, 2015 Author Share Posted September 25, 2015 Okay all good, it's working perfectly. When the player has a row selected and they click "Go" I want it to teleport them to the location. Here's a picture of my GUI: So if the player has Los Santos selected, I want it to teleport them to the LS coordinates in my table. Link to comment
KariiiM Posted September 25, 2015 Share Posted September 25, 2015 Okay all good, it's working perfectly. When the player has a row selected and they click "Go" I want it to teleport them to the location So if the player has Los Santos selected, I want it to teleport them to the LS coordinates in my table. You've to use setElementPosition try by yourself if you stuck i will help you Link to comment
StefanAlmighty Posted September 25, 2015 Author Share Posted September 25, 2015 gui.goWindow = guiCreateButton(5, 205, 91, 35, "Go", false, gui.manager) addEventHandler("onClientGUIClick", gui.goWindow, function () if source == gui.goWindow then local selectedplace = guiGridListGetSelectedItem(gui.manager) if selectedplace == 1 -- LS setElementPosition(getRootElement(), data[ls][4], data[ls][5], data[ls[6]) setElementRotation(getRootElement(), 0, 0, data[ls][9]) setElementInterior(getRootElement(), data[ls][7]) setElementDimension(getRootElement(), data[ls][8]) end end end, false) I've tried but I'm not sure how to find out if the player has selected LS, SF or LV. This doesn't work btw. Link to comment
KariiiM Posted September 25, 2015 Share Posted September 25, 2015 Your code is messy, post the full code and i'll fix it Link to comment
StefanAlmighty Posted September 25, 2015 Author Share Posted September 25, 2015 function openTeleportMenu(locationData) if locationData and type(locationData) == "table" then data = locationData end terminateLocationManager() showCursor(true) local w, h = 400, 250 gui.manager = guiCreateWindow(0, 0, w, h, "Admin Teleporter © Almighty", false) exports.global:centerWindow(gui.manager) gui.grid = guiCreateGridList(10, 23, 380, 172, false, gui.manager) gui.colID = guiGridListAddColumn(gui.grid, "ID", 0.1) gui.colName = guiGridListAddColumn(gui.grid, "Name", 0.3) gui.colDesc = guiGridListAddColumn(gui.grid, "Description", 0.5) for v, k in pairs(data) do gui.row = guiGridListAddRow(gui.grid) local a, b = gui.grid, gui.row guiGridListSetItemText(a, b, gui.colID, data[v][1], false, true) guiGridListSetItemText(a, b, gui.colName, data[v][2], false, false) guiGridListSetItemText(a, b, gui.colDesc, data[v][3], false, false) end gui.closeWindow = guiCreateButton(299, 205, 91, 35, "Close", false, gui.manager) addEventHandler("onClientGUIClick", gui.closeWindow, function () if source == gui.closeWindow then terminateLocationManager() end end, false) gui.goWindow = guiCreateButton(5, 205, 91, 35, "Go", false, gui.manager) addEventHandler("onClientGUIClick", gui.goWindow, function () if source == gui.goWindow then local selectedplace = guiGridListGetSelectedItem(gui.manager) if selectedplace == 1 -- LS setElementPosition(getRootElement(), data[ls][4], data[ls][5], data[ls[6]) setElementRotation(getRootElement(), 0, 0, data[ls][9]) setElementInterior(getRootElement(), data[ls][7]) setElementDimension(getRootElement(), data[ls][8]) end end end, false) end addCommandHandler("tpmenu", openTeleportMenu, false, false) It's on line 28 - 39. Link to comment
KariiiM Posted September 25, 2015 Share Posted September 25, 2015 Do you want only staff team or someone in the ACL who control it? im going to re make this code , it's really messy , you can learn from it later Link to comment
StefanAlmighty Posted September 25, 2015 Author Share Posted September 25, 2015 I want it so anybody can use it for now, and the code works fine. I'd just like to know how to find out which row is selected. Link to comment
KariiiM Posted September 25, 2015 Share Posted September 25, 2015 I want it so anybody can use it for now, and the code works fine. I'd just like to know how to find out which row is selected. Yes, im making it now, 5mins and the code will be done with all features and clear ! Link to comment
KariiiM Posted September 25, 2015 Share Posted September 25, 2015 I re-made the script from the Zero, it's without bugs and clear i just tested it , works perfectly there are two sides , server / client, copy them correctly and i hope that i helped you, have fun scripting ! --client side local w, h = 400, 250 local window = guiCreateWindow(0, 0, w, h, "Admin Teleporter © Almighty", false) guiSetVisible (window, false) guiWindowSetSizable(window,false) local grid = guiCreateGridList(10, 23, 380, 172, false, window) local col1 = guiGridListAddColumn(grid,"ID",0.4) local col2 = guiGridListAddColumn(grid,"Name",0.37) local col3 = guiGridListAddColumn(grid,"Description",0.13) local transport = guiCreateButton(5, 205, 91, 35, "Go", false, window) local cancel = guiCreateButton(299, 205, 91, 35, "Close", false, window) function viewGUI (aTable) if ( source == getLocalPlayer() ) then guiSetVisible (window, true) showCursor (true) if guiGetVisible(window) then guiGridListClear(grid) for index ,val in ipairs (aTable) do local row = guiGridListAddRow (grid) guiGridListSetItemText (grid, row, col1, val[1], false, true) guiGridListSetItemText (grid, row, col2, val[2], false, false) guiGridListSetItemText (grid, row, col3, val[3], false, false) end end end end addEvent ("showGui", true) addEventHandler ("showGui", root, viewGUI) addEventHandler ("onClientGUIClick", root, function () if (source == cancel) then if guiGetVisible(window) ~= nil then guiSetVisible (window, false) showCursor(false) end elseif (source == transport) then local row = guiGridListGetSelectedItem(grid) if row and row == -1 then outputChatBox ("You must selecte the destination",getLocalPlayer(),255,0,0) return false end guiSetVisible(window,false) showCursor(false) triggerServerEvent("warp",getLocalPlayer(),guiGridListGetSelectedItem(grid)+1) end end) --server side: --X, Y, Z, Int, Dim, Rot; local data = { [1] = {"1", "Los Santos", "Teleports you to Pershing Square, Los Santos.", 1479.9873046875, -1710.9453125, 13.36874961853, 0, 0, 0}, [2] = {"2", "San Fierro", "Teleports you to Doherty, San Fierro.", -1988.5693359375, 507.0029296875, 35.171875, 0, 0, 90}, [3] = {"3", "Las Venturas", "Teleports you to The Strip, Las Venturas", 1691.6801757813, 1449.1293945313, 10.765375, 0, 0, 268}, } addCommandHandler("tpmenu", function (player, commandName) triggerClientEvent (player,"showGui", player, data) end) addEvent ("warp",true) addEventHandler ("warp",root, function (i) local data = data[i] local x, y, z = data[4], data[5], data[6] local int , dim = data[7], data[8] fadeCamera(source, false) setTimer(fadeCamera, 2200, 1, source, true) setTimer(setElementPosition,2000,1,source, x, y, z) setTimer(setElementDimension,2000,1,source, dim) setTimer(setElementInterior,2000,1,source, int) setCameraTarget(source, source) end) --meta.xml "KariM" type="script" name="Transporter GUI" version="1.0" /> ~Regards, KariM Link to comment
StefanAlmighty Posted September 25, 2015 Author Share Posted September 25, 2015 I've been studying the code and I think I know where I went wrong. Although, I've tested it and it works like a charm. Thanks for that. Link to comment
KariiiM Posted September 25, 2015 Share Posted September 25, 2015 I've been studying the code and I think I know where I went wrong. Although, I've tested it and it works like a charm. Thanks for that. You're welcome Link to comment
StefanAlmighty Posted September 25, 2015 Author Share Posted September 25, 2015 One more thing, I'm not sure if it's possible but I'll ask. Is it possible to make a command (for example /addnewpos) which adds a new teleport location to the data table from in-game? I'm not sure if it's possible, but I'd like to make my teleport system completely dynamic. Link to comment
KariiiM Posted September 25, 2015 Share Posted September 25, 2015 One more thing, I'm not sure if it's possible but I'll ask.Is it possible to make a command (for example /addnewpos) which adds a new teleport location to the data table from in-game? I'm not sure if it's possible, but I'd like to make my teleport system completely dynamic. It's possible Link to comment
StefanAlmighty Posted September 25, 2015 Author Share Posted September 25, 2015 How would I do that? Is there a function which will add a row to my data table? Link to comment
KariiiM Posted September 25, 2015 Share Posted September 25, 2015 How would I do that? Is there a function which will add a row to my data table? table.insert Also you've to use this function to get the player's position when you type the cmd getElementPosition Link to comment
StefanAlmighty Posted September 25, 2015 Author Share Posted September 25, 2015 Alright so should I use it in this format? table.insert(data, 1, 4) table.insert(data, 2, "Bayside") table.insert(data, 3, "Teleports you to Bayside in Tierra Robada") Link to comment
KariiiM Posted September 25, 2015 Share Posted September 25, 2015 table.insert This function is used to inserts element in table and in this situation you need to store player position what you typed in game You can also use, table.remove to remove what you stored in the table 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