Jump to content

[HELP] Gridlist and Tables


Recommended Posts

Hello,

I'm not just going to ask to resolve my problem, because I probably will myself.

I just would like an explanation of tables and how I get all the data from a table filled in a gridlist.

as far as I know I need to use;

--table creation first 
  
guiCreateGridList 
guiGridListAddColumn 
guiGridListAddRow 
guiGridListSetItemText --here's the problem, how to call the table? 

Regards ViRuZ

Link to comment

Yes okay I understand what you are trying to say, I saw it in some examples on the Wiki too.

but I don't quiet understand looping.

it's something like;

for i, v in ipairs (tables) do 

still if this right I don't understand it.

What's the "i", the "v" and the "ipairs"?

Thx in advance

Link to comment

You can do it like this:

tTable = { 
"Row0", --Table index 1 
"Row1", --Table index 2 
"Row2", --Table index 3 
"Row3", --Table index 4 
"Row4", --Table index 5 
"Row5" --Table index 6 
} 
  
function fill() --Make the function 
    local gList = guiCreateGridList(50, 50, 500, 500, false) --Make a grid list 
    local col = guiGridListAddColumn(gList, "Column Name", 1) --Make a column 
    for placeNumber, textData in ipairs(tTable) do --Make a loop, for every index that is in the table, do the next code: 
        local row = guiGridListRow(gList) --Add a row in the gridlist 
        guiGridListSetItemText(gList, row, col, textData, false, false) --Set the text in the row 
    end --'End' the loop 
end --'End' the function 
  
fill() 

(Quick example, not tested, but it is about how to do it anyway :P )

Link to comment
Good, how to explain that...

placeNumber = (in this case) the entry which is being checked now.

textData = the 'data' (can be a table, code, text, etc.) which he gets in this entry from the table.

(My explanation sucks :P )

haha thx for trying, maybe someone else can explain it who's more experienced on the "Tables and Loops" part.

EDIT: Anyhow, thx Et-win you're loop worked fine. I would assume the data works the same.

Edited by Guest
Link to comment

Example 2, I want a table in a table and get texts out of it:

tTable = { --Let's make some tables in a table 
    {"Row0", "This is my row0 string"} --Index 1 of 'tTable', this has a table. This table has "Row0" in the first index of this table, with a text in the second index 
    {"Row1", "Hello world"} 
    {"Row2", "Test123"} 
    {"Row3", "Monkey's"} 
    {"Row4", "Row4"} 
    {"Row5", "Lollol"} 
} 
  
function fill() 
    local gList = guiCreateGridList(50, 50, 500, 500, false) --Make a grid list 
    local col1 = guiGridListAddColumn(gList, "Column 1", 0.45) --Make column 1 
    local col2 = guiGridListAddColumn(gList, "Column 2", 0.45) --Make column 2 
    for placeNumber --[[index number of the 'tTable' table in this case]], tableData --[[He gets the table which is on that index (In this case)]] in ipairs(tTable) do 
        --I want the first index of the table (tableData) in column 1, and the second index in column 2 
        local row = guiGridListAddRow(gList) 
        guiGridListSetItemText(gList, row, col1, tableData[1], false, false) 
        guiGridListSetItemText(gList, row, col2, tableData[2], false, false) 
        --'tableData[1]' means: Get index 1 of the table. 
        --'tableData[2]' means: Get index 2 of the table. 
        --Etc. 
    end --'End' the loop 
end --'End' the function 
  
fill() 

EDIT: I know how everything works, but I can't explain it really good in English. ;)

Link to comment

Okay i'm stuck so i'm going to post my full Client side code;

GUIEditor = { 
    gridlist = {}, 
    window = {}, 
    button = {}, 
    label = {} 
} 
  
tTable = { 
{"Red", "255, 0, 0"}, 
{"Orange", "255, 150, 0"}, 
{"Yellow", "0, 0, 0"}, 
{"Light Green", "0, 0, 0"}, 
{"Dark Green", "0, 0, 0"}, 
{"Light Blue", "0, 0, 0"}, 
{"Dark Blue", "0, 0, 0"}, 
{"Purple", "0, 0, 0"}, 
{"Dark Red", "0, 0, 0"}, 
{"Light Red", "0, 0, 0"}, 
{"Dark Pink", "0, 0, 0"}, 
{"Light Pink", "0, 0, 0"} 
} 
  
addEvent("showModGUI", true) 
addEventHandler("showModGUI", root,  
function () 
        guiSetVisible(modWindow, true) 
end 
) 
  
addEvent("hideModGUI", true) 
addEventHandler("hideModGUI", root,  
function () 
    guiSetVisible(modWindow, false) 
end 
) 
  
function drawModWindow () 
    modWindow = guiCreateWindow(350, 170, 1300, 608, "Mod Shop", false) 
    guiWindowSetSizable(modWindow, false) 
    guiWindowSetMovable(modWindow, false) 
    guiSetVisible(modWindow, false) 
     
    modLabel1 = guiCreateLabel(10, 20, 300, 40, "Front", false, modWindow) 
    guiSetFont(modLabel1, "default-bold-small") 
    guiLabelSetHorizontalAlign(modLabel1, "center", false) 
    guiLabelSetVerticalAlign(modLabel1, "center") 
    modLabel2 = guiCreateLabel(990, 20, 300, 40, "Color", false, modWindow) 
    guiSetFont(modLabel2, "default-bold-small") 
    guiLabelSetHorizontalAlign(modLabel2, "center", false) 
    guiLabelSetVerticalAlign(modLabel2, "center") 
    modLabel3 = guiCreateLabel(680, 20, 300, 40, "Misc", false, modWindow) 
    guiSetFont(modLabel3, "default-bold-small") 
    guiLabelSetHorizontalAlign(modLabel3, "center", false) 
    guiLabelSetVerticalAlign(modLabel3, "center") 
    modLabel4 = guiCreateLabel(322, 20, 300, 40, "Back", false, modWindow) 
    guiSetFont(modLabel4, "default-bold-small") 
    guiLabelSetHorizontalAlign(modLabel4, "center", false) 
    guiLabelSetVerticalAlign(modLabel4, "center") 
    modGridlist1 = guiCreateGridList(22, 66, 278, 431, false, modWindow) 
    modGridlist2 = guiCreateGridList(334, 66, 278, 431, false, modWindow) 
    modGridlist3 = guiCreateGridList(692, 66, 278, 431, false, modWindow) 
    colorList = guiCreateGridList(1002, 66, 278, 431, false, modWindow) 
        colorColumn = guiGridListAddColumn (colorList, "Colors", 1) 
            for placeNumber, textData in ipairs(tTable) do 
            colorRow = guiGridListAddRow (colorList) 
            guiGridListSetItemText ( colorList, colorRow, colorColumn, tostring(textData[1]), false, false ) 
            guiGridListSetItemData ( colorList, colorRow, colorColumn, tostring(textData[2]), false, false ) 
            end 
    previewButton = guiCreateButton(32, 516, 570, 48, "Preview", false, modWindow) 
        addEventHandler("onClientGUIClick", previewButton, previewTheCar) 
    applyButton = guiCreateButton(702, 516, 568, 48, "Apply!", false, modWindow) 
    closeButton = guiCreateButton(622, 516, 60, 48, "Close", false, modWindow)  
        addEventHandler ("onClientGUIClick", closeButton, closeModGUI, false) 
end 
  
addEventHandler("onClientResourceStart", resourceRoot,drawModWindow) 
  
function cancelPreview () 
    guiSetVisible (modWindow, true) 
    destroyElement (closeButtonOnPreview) 
    if ( getElementDimension ( getLocalPlayer() ) == 1 ) then 
        setElementDimension ( getLocalPlayer(), 0 ) 
        setElementDimension ( getLocalPlayer(), 0 )  
        fadeCamera(false, 1) 
    end 
end 
  
function previewTheCar () 
    local theVehicle = getPedOccupiedVehicle ( getLocalPlayer() ) 
    local driver = getVehicleController ( theVehicle ) 
    if ( getElementDimension (driver) == 0 ) then 
        setElementDimension ( driver, 1 ) 
        setElementDimension ( theVehicle, 1 )  
        fadeCamera(true) 
        setCameraMatrix ( -1940.6650390625, 251.3447265625, 37.063766479492, -1936.1552734375, 246.1298828125, 34.4609375) 
        closeButtonOnPreview = guiCreateButton(850, 1000, 350, 30, "Close", false) 
        addEventHandler("onClientGUIClick", closeButtonOnPreview, cancelPreview) 
        guiSetVisible (modWindow, false) 
            if source == colorList then 
  
            end 
    end 
end 
  
function closeModGUI () 
    guiSetVisible(modWindow, false) 
    triggerServerEvent("onCancel", getLocalPlayer()) 
    setCameraTarget( getLocalPlayer(), getLocalPlayer() ) 
end 

How can I get the textData[2] and then use it as a setVehicleColor

Link to comment
GUIEditor = { 
    gridlist = {}, 
    window = {}, 
    button = {}, 
    label = {} 
} 
  
tTable = { 
{"Red", 255, 0, 0}, 
{"Orange", 255, 150, 0}, 
{"Yellow", 0, 0, 0}, 
{"Light Green", 0, 0, 0}, 
{"Dark Green", 0, 0, 0}, 
{"Light Blue", 0, 0, 0}, 
{"Dark Blue", 0, 0, 0}, 
{"Purple", 0, 0, 0}, 
{"Dark Red", 0, 0, 0}, 
{"Light Red", 0, 0, 0}, 
{"Dark Pink", 0, 0, 0}, 
{"Light Pink", 0, 0, 0} 
} 
  
addEvent("showModGUI", true) 
addEventHandler("showModGUI", root,  
function () 
        guiSetVisible(modWindow, true) 
end 
) 
  
addEvent("hideModGUI", true) 
addEventHandler("hideModGUI", root,  
function () 
    guiSetVisible(modWindow, false) 
end 
) 
  
function drawModWindow () 
    modWindow = guiCreateWindow(350, 170, 1300, 608, "Mod Shop", false) 
    guiWindowSetSizable(modWindow, false) 
    guiWindowSetMovable(modWindow, false) 
    guiSetVisible(modWindow, false) 
     
    modLabel1 = guiCreateLabel(10, 20, 300, 40, "Front", false, modWindow) 
    guiSetFont(modLabel1, "default-bold-small") 
    guiLabelSetHorizontalAlign(modLabel1, "center", false) 
    guiLabelSetVerticalAlign(modLabel1, "center") 
    modLabel2 = guiCreateLabel(990, 20, 300, 40, "Color", false, modWindow) 
    guiSetFont(modLabel2, "default-bold-small") 
    guiLabelSetHorizontalAlign(modLabel2, "center", false) 
    guiLabelSetVerticalAlign(modLabel2, "center") 
    modLabel3 = guiCreateLabel(680, 20, 300, 40, "Misc", false, modWindow) 
    guiSetFont(modLabel3, "default-bold-small") 
    guiLabelSetHorizontalAlign(modLabel3, "center", false) 
    guiLabelSetVerticalAlign(modLabel3, "center") 
    modLabel4 = guiCreateLabel(322, 20, 300, 40, "Back", false, modWindow) 
    guiSetFont(modLabel4, "default-bold-small") 
    guiLabelSetHorizontalAlign(modLabel4, "center", false) 
    guiLabelSetVerticalAlign(modLabel4, "center") 
    modGridlist1 = guiCreateGridList(22, 66, 278, 431, false, modWindow) 
    modGridlist2 = guiCreateGridList(334, 66, 278, 431, false, modWindow) 
    modGridlist3 = guiCreateGridList(692, 66, 278, 431, false, modWindow) 
    colorList = guiCreateGridList(1002, 66, 278, 431, false, modWindow) 
        colorColumn = guiGridListAddColumn (colorList, "Colors", 1) 
            for placeNumber, textData in ipairs(tTable) do 
            colorRow = guiGridListAddRow (colorList) 
            guiGridListSetItemText ( colorList, colorRow, colorColumn, tostring(textData[1]), false, false ) 
            guiGridListSetItemData ( colorList, colorRow, colorColumn, textData[2], textData[3], textData[4], false, false ) 
            end 
    previewButton = guiCreateButton(32, 516, 570, 48, "Preview", false, modWindow) 
        addEventHandler("onClientGUIClick", previewButton, previewTheCar) 
    applyButton = guiCreateButton(702, 516, 568, 48, "Apply!", false, modWindow) 
    closeButton = guiCreateButton(622, 516, 60, 48, "Close", false, modWindow)  
        addEventHandler ("onClientGUIClick", closeButton, closeModGUI, false) 
end 
  
addEventHandler("onClientResourceStart", resourceRoot,drawModWindow) 
  
function previewTheCar () 
    local theVehicle = getPedOccupiedVehicle ( getLocalPlayer() ) 
    local driver = getVehicleController ( theVehicle ) 
    local vehColor = getVehicleColor ( theVehicle ) 
    if ( getElementDimension (driver) == 0 ) then 
        setElementDimension ( driver, 1 ) 
        setElementDimension ( theVehicle, 1 )  
        fadeCamera(true) 
        setCameraMatrix ( -1940.6650390625, 251.3447265625, 37.063766479492, -1936.1552734375, 246.1298828125, 34.4609375) 
        closeButtonOnPreview = guiCreateButton(850, 1000, 350, 30, "Close", false) 
        addEventHandler("onClientGUIClick", closeButtonOnPreview, cancelPreview) 
        guiSetVisible (modWindow, false) 
        for placeNumber, textData in ipairs(tTable) do 
        local selectedRow, selectedColumn = guiGridListGetSelectedItem(colorList) 
        local colorData = guiGridListGetItemData(colorList, selectedRow, selectedColumn) 
        setVehicleColor ( theVehicle, textData[2], textData[3], textData[4] ) 
        end 
    end 
end 
  
function cancelPreview () 
    guiSetVisible (modWindow, true) 
    destroyElement (closeButtonOnPreview) 
    if ( getElementDimension ( getLocalPlayer() ) == 1 ) then 
        setElementDimension ( getLocalPlayer(), 0 ) 
        setElementDimension ( getLocalPlayer(), 0 )  
        fadeCamera(false, 1) 
        local theVehicle = getPedOccupiedVehicle ( getLocalPlayer() ) 
        setVehicleColor ( theVehicle, vehColor ) 
    end 
end 
  
function closeModGUI () 
    guiSetVisible(modWindow, false) 
    triggerServerEvent("onCancel", getLocalPlayer()) 
    setCameraTarget( getLocalPlayer(), getLocalPlayer() ) 
end 

Link to comment
for placeNumber, textData in ipairs(tTable) do 
        local selectedRow, selectedColumn = guiGridListGetSelectedItem(colorList) 
        local colorData = guiGridListGetItemData(colorList, selectedRow, selectedColumn) 
        setVehicleColor ( theVehicle, textData[2], textData[3], textData[4] ) 

Logical. He is going to set the vehicle's color for every color that is in the table. The last color in the table is 'Light Pink' so that color will be set.

Link to comment

First of all set this:

local vehColor = getVehicleColor ( theVehicle ) 
--To: 
vehColor = getVehicleColor ( theVehicle ) 

If you put it local, the code on line 106 will not be able to read it.

You will need to make another function which detects when you click on a the gridlist (onClientGUIClick), then set the vehicle's color.

Link to comment

Error; bad argument @ setVehicleColor (line 25 here)

function previewTheCar () 
    local theVehicle = getPedOccupiedVehicle ( getLocalPlayer() ) 
    local driver = getVehicleController ( theVehicle ) 
    vehColor = getVehicleColor ( theVehicle ) 
    if ( getElementDimension (driver) == 0 ) then 
        setElementDimension ( driver, 1 ) 
        setElementDimension ( theVehicle, 1 )  
        fadeCamera(true) 
        setCameraMatrix ( -1940.6650390625, 251.3447265625, 37.063766479492, -1936.1552734375, 246.1298828125, 34.4609375) 
        closeButtonOnPreview = guiCreateButton(850, 1000, 350, 30, "Close", false) 
        addEventHandler("onClientGUIClick", closeButtonOnPreview, cancelPreview) 
        guiSetVisible (modWindow, false) 
        addEventHandler("onClientGUIClick", colorList, setVehicleColorMod) 
    end 
end 
  
function cancelPreview () 
    guiSetVisible (modWindow, true) 
    destroyElement (closeButtonOnPreview) 
    if ( getElementDimension ( getLocalPlayer() ) == 1 ) then 
        setElementDimension ( getLocalPlayer(), 0 ) 
        setElementDimension ( getLocalPlayer(), 0 )  
        fadeCamera(false, 1) 
        local theVehicle = getPedOccupiedVehicle ( getLocalPlayer() ) 
        setVehicleColor ( theVehicle, vehColor ) 
    end 
end 

Link to comment

Try this:

function previewTheCar () 
    local theVehicle = getPedOccupiedVehicle ( getLocalPlayer() ) 
    local driver = getVehicleController ( theVehicle ) 
    c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12 = getVehicleColor ( theVehicle, true ) 
    if ( getElementDimension (driver) == 0 ) then 
        setElementDimension ( driver, 1 ) 
        setElementDimension ( theVehicle, 1 ) 
        fadeCamera(true) 
        setCameraMatrix ( -1940.6650390625, 251.3447265625, 37.063766479492, -1936.1552734375, 246.1298828125, 34.4609375) 
        closeButtonOnPreview = guiCreateButton(850, 1000, 350, 30, "Close", false) 
        addEventHandler("onClientGUIClick", closeButtonOnPreview, cancelPreview) 
        guiSetVisible (modWindow, false) 
        addEventHandler("onClientGUIClick", colorList, setVehicleColorMod) 
    end 
end 
  
function cancelPreview () 
    guiSetVisible (modWindow, true) 
    destroyElement (closeButtonOnPreview) 
    if ( getElementDimension ( getLocalPlayer() ) == 1 ) then 
        setElementDimension ( getLocalPlayer(), 0 ) 
        setElementDimension ( getLocalPlayer(), 0 ) 
        fadeCamera(false, 1) 
        local theVehicle = getPedOccupiedVehicle ( getLocalPlayer() ) 
        setVehicleColor ( theVehicle, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12 ) 
    end 
end 

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