Jump to content

guiGridListSetData. Need Help.


PotatoHead

Recommended Posts

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

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

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
  
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...