PotatoHead Posted September 18, 2013 Share Posted September 18, 2013 So I am working on a GridList and I am trying to set the date. What I want to know is if there is a way to have multiple data points. I wish to know so I can find out how to place the data if you need the script posted please let me now. Thanks. Link to comment
xXMADEXx Posted September 18, 2013 Share Posted September 18, 2013 Use a table in guiGridListSetItemData. Examp: guiGridListSetItemData ( gridlist, 2, 1, { "data1", 200, getPlayerName ( localPlayer ) } ) for i, v in ipairs ( guiGridListGetItemData ( gridlist, 2, 1 ) ) do outputChatBox ( tostring ( v ) ) end Link to comment
PotatoHead Posted September 18, 2013 Author Share Posted September 18, 2013 Hey. Thanks it worked. Now I am wondering if there is a way to transfer it to a server side script. I want to know because I am working with spawn cords. I wish to use the X Y Z values in a spawnPlayer() function. Link to comment
Castillo Posted September 18, 2013 Share Posted September 18, 2013 You can send them using triggerServerEvent. Link to comment
PotatoHead Posted September 19, 2013 Author Share Posted September 19, 2013 Okay. But will it send automatically in x, y, z data? If you need the piece of code let me know. Link to comment
Castillo Posted September 19, 2013 Share Posted September 19, 2013 You can unpack the table stored on the grid list. unpack Link to comment
PotatoHead Posted September 19, 2013 Author Share Posted September 19, 2013 Thnaks Solidsnake. One problem where would I put that whne retriving the guiGridListGetData? The code starts by taking the cords from an XML file then sets each x, y, and z cord on those values then sets the gridlist data. Now how could I retrive them in that order with the unpack function? Link to comment
Castillo Posted September 19, 2013 Share Posted September 19, 2013 Get the selected item with guiGridListGetSelectedItem, then use guiGridListGetItemData. Link to comment
PotatoHead Posted September 19, 2013 Author Share Posted September 19, 2013 Hello once again Solidsnake. I hope this will be my final request. Right now I just get the output of nil. c_spawnlist.lua - Client Side function makeList() local file = xmlLoadFile("spawnpoints.xml") if file then for _, spawns in ipairs (xmlNodeGetChildren(file)) do local row = guiGridListAddRow(glistMainList) local name = xmlNodeGetAttribute(spawns, "name") local x = xmlNodeGetAttribute(spawns, "x") local y = xmlNodeGetAttribute(spawns, "y") local z = xmlNodeGetAttribute(spawns, "z") guiGridListSetItemText(glistMainList, row, 1, name, false, false) guiGridListSetItemData(glistMainList, row, 1, {x, y, z}) end xmlUnloadFile(file) end end function spawnHandler(button, state) if button == "left" and state == "up" then local row, col = guiGridListGetSelectedItem(glistMainList) local data = guiGridListGetItemData(glistMainList, row, col) if row and col and row ~= -1 and col ~=-1 then for i, v in ipairs (data) do unpack(data) outputChatBox(x) outputChatBox(y) outputChatBox(z) end --local x, y, z = guiGridListGetItemData(glistMainList, row, col) --x = tonumber(x) --y = tonumber(y) --z = tonumber(z) --outputChatBox(x) end end end spawnpoints.xml "-503" y="-517" z="26" name="Fallen Tree, Los Santos"/> "" y="" z="" name="This one"/> "" y="" z ="" name="That one"/> "" y="" z="" name="You get the point..."/> "" y="" z="" name="I hope."/> Link to comment
Castillo Posted September 19, 2013 Share Posted September 19, 2013 No need for loops. function makeList() local file = xmlLoadFile("spawnpoints.xml") if file then for _, spawns in ipairs (xmlNodeGetChildren(file)) do local row = guiGridListAddRow(glistMainList) local name = xmlNodeGetAttribute(spawns, "name") local x = xmlNodeGetAttribute(spawns, "x") local y = xmlNodeGetAttribute(spawns, "y") local z = xmlNodeGetAttribute(spawns, "z") guiGridListSetItemText(glistMainList, row, 1, name, false, false) guiGridListSetItemData(glistMainList, row, 1, {x, y, z}) end xmlUnloadFile(file) end end function spawnHandler(button, state) if button == "left" and state == "up" then local row, col = guiGridListGetSelectedItem(glistMainList) local data = guiGridListGetItemData(glistMainList, row, col) if row and col and row ~= -1 and col ~=-1 then local x, y, z = unpack ( data ) outputChatBox(x) outputChatBox(y) outputChatBox(z) end end end Link to comment
PotatoHead Posted September 19, 2013 Author Share Posted September 19, 2013 Works great. Thanks Solidsnake. You rock man! Link to comment
PotatoHead Posted September 19, 2013 Author Share Posted September 19, 2013 Last issue. Now I am getting a stack overflow error. These are my scripts in full. c_spawnist.lua local player = getLocalPlayer() function createSpawnList() local sW, sH = guiGetScreenSize() wdwList = guiCreateWindow((sW-830)/2, (sH-538)/2, 830, 538, "Spawn List", false) guiWindowSetSizable(wdwList, false) guiWindowSetMovable(wdwList, false) glistMainList = guiCreateGridList((830-711)/2, (538-441)/2, 711, 441, false, wdwList) guiGridListAddColumn(glistMainList, "Spawn Points", 0.9) btnSpawn = guiCreateButton((830-264)/2, (538-35), 264, 35, "Spawn", false, wdwList) addEventHandler("onClientGUIClick", btnSpawn, spawnHandler, false) makeList() end addEventHandler("onClientResourceStart", getResourceRootElement(getThisResource()), function() createSpawnList() guiSetVisible(wdwList, false) end ) function showSpawnList() if not guiGetVisible(wdwList) then guiSetVisible(wdwList, true) showCursor(true, true) end end addCommandHandler("spawn", showSpawnList) function makeList() local file = xmlLoadFile("spawnpoints.xml") if file then for _, spawns in ipairs (xmlNodeGetChildren(file)) do local row = guiGridListAddRow(glistMainList) local name = xmlNodeGetAttribute(spawns, "name") local x = xmlNodeGetAttribute(spawns, "x") local y = xmlNodeGetAttribute(spawns, "y") local z = xmlNodeGetAttribute(spawns, "z") guiGridListSetItemText(glistMainList, row, 1, name, false, false) guiGridListSetItemData(glistMainList, row, 1, {x, y, z}) end xmlUnloadFile(file) end end function spawnHandler(button, state) if button == "left" and state == "up" then local row, col = guiGridListGetSelectedItem(glistMainList) local data = guiGridListGetItemData(glistMainList, row, col) if row and col and row ~= -1 and col ~=-1 then local x, y, z = unpack(data) triggerServerEvent("spawnPlayer", player, x, y, z, player) end end end s_spawnlist.lua function spawnPlayer(x, y, z, player) spawnPlayer(player, x, y, z) end addEvent("spawnPlayer", true) addEventHandler("spawnPlayer", getRootElement(), spawnPlayer) Link to comment
Castillo Posted September 19, 2013 Share Posted September 19, 2013 function spawnPlayer(x, y, z, player) spawnPlayer(player, x, y, z) end addEvent("spawnPlayer", true) addEventHandler("spawnPlayer", getRootElement(), spawnPlayer) There's the problem, you named the function the same as the native one you are using, so, is executing over and over again. Rename it, like this: function spawnPlayer_(x, y, z, player) spawnPlayer(player, x, y, z) end addEvent("spawnPlayer", true) addEventHandler("spawnPlayer", getRootElement(), spawnPlayer_) 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