S3Nn4oX Posted June 23, 2017 Share Posted June 23, 2017 It is possible to attach GUI with dx element? Link to comment
WorthlessCynomys Posted June 23, 2017 Share Posted June 23, 2017 Hy. As I know, it is not possible, unless you make some tricky solution with some variables or such. I never tried tbh, it doesn't worth the time for me. 1 Link to comment
S3Nn4oX Posted June 23, 2017 Author Share Posted June 23, 2017 I know that Tables are needed and i'm very bad i don't know what's tables for what they're used for.., can you send me tutorials about it? or you can explain to me by yr self . I always lose my way on lua.org Link to comment
WorthlessCynomys Posted June 23, 2017 Share Posted June 23, 2017 (edited) So in Lua {} this is a table. Tables have indexes and values So like: exampleTable = {1, 8, 4} --[[ The index is the place in this table. So like the Index of 1 is 1, cuz it's on the first place of the table, it's value is 1. The index of 8 is 2, the value is 8..... you can get an exact value from the table by exampleTable[2] for example. exampleTable[2] is 8. --]] exampleTable2 = {"toy", "story"} --[[ The index of "toy" is 1, the value is "toy". You get "toy" as result by exampleTable2[1] --]] exampleTable3 = {toy = 1, story = 8} --[[ The index of 1 is "toy", it's value is 1. Same with story. You get 8 as result by exampleTable3["story"] --]] --[[ You can also handle tables with for loops. If your table has only numerical INDEXES, your loop will look like this: --]] for i, v in ipairs(exampleTable2) do outputChatBox(v) --This will output all outputable values of that table. end -- If your table has indexes, not numbers u use "pairs" for i, v in pairs(exampleTable3) do outputChatBox(v) end If you need further help, I'll do my best to help you. Edited June 23, 2017 by StormFighter Extension 1 Link to comment
S3Nn4oX Posted June 23, 2017 Author Share Posted June 23, 2017 8 minutes ago, StormFighter said: So in Lua {} this is a table. Tables have indexes and values So like: exampleTable = {1, 8, 4} --[[ The index is the place in this table. So like the Index of 1 is 1, cuz it's on the first place of the table, it's value is 1. The index of 8 is 2, the value is 8..... you can get an exact value from the table by exampleTable[2] for example. exampleTable[2] is 8. --]] exampleTable2 = {"toy", "story"} --[[ The index of "toy" is 1, the value is "toy". You get "toy" as result by exampleTable2[1] --]] exampleTable3 = {toy = 1, story = 8} --[[ The index of 1 is "toy", it's value is 1. Same with story. You get 8 as result by exampleTable3["story"] --]] --[[ You can also handle tables with for loops. If your table has only numerical INDEXES, your loop will look like this: --]] for i, v in ipairs(exampleTable2) do outputChatBox(v) --This will output all outputable values of that table. end -- If your table has indexes, not numbers u use "pairs" for i, v in pairs(exampleTable3) do outputChatBox(v) end If you need further help, I'll do my best to help you. Didn't expect that bro Thanks fam i appreciate it. now i finally know what are tables. the basics but how do i use tables to store MTA elements ? Link to comment
WorthlessCynomys Posted June 23, 2017 Share Posted June 23, 2017 (edited) 7 minutes ago, S3Nn4oX said: Didn't expect that bro Thanks fam i appreciate it. now i finally know what are tables. the basics but how do i use tables to store MTA elements ? -- You declare the table myTable = {} -- Have an element (I'll make one here) myTable[1] = createPed(29, 0, 0, 0) -- OR ped = createPed(29, 0, 0, 0) myTable[1] = ped -- OR ped = createPed(29, 0, 0, 0) table.insert(myTable, ped) -- This will insert the ped in the table as an adittional element, unless you declare an index, while the upper ones overwrite myTable[1] Edited June 23, 2017 by StormFighter Misspelling 1 Link to comment
S3Nn4oX Posted June 23, 2017 Author Share Posted June 23, 2017 (edited) 16 minutes ago, StormFighter said: -- You declare the table myTable = {} -- Have an element (I'll make one here) myTable[1] = createPed(29, 0, 0, 0) -- OR ped = createPed(29, 0, 0, 0) myTable[1] = pes -- OR ped = createPed(29, 0, 0, 0) table.insert(myTable, ped) -- This will insert the ped in the table as an adittional element, unless you declare an index, while the upper ones overwrite myTable[1] Table = { } function test(thePlayer) Table[1] = thePlayer Table[2] = "Has committed suicide" r, g, b = 255, 0, 0 Table[3] = r, g, b killPed(Table[1], Table[1]) outputChatBox(Table[1]..Table[2].."!", root, Table[3], true) end addCommandHandler("suicide", test) I tried to script something with a table, if i want to store addCommandHandler into a table, it is possible, ? Table = { } Command = addCommandHandler("suicide", test) Table[4] = Command function test(thePlayer) Table[1] = thePlayer Table[2] = "Has committed suicide" r, g, b = 255, 0, 0 Table[3] = r, g, b killPed(Table[1], Table[1]) outputChatBox(Table[1]..Table[2].."!", root, Table[3], true) end Table[4] --Or Table[4] = addCommandHandler("suicide", test) I think i understood almost everything , thanks to you ! Edited June 23, 2017 by S3Nn4oX Link to comment
WorthlessCynomys Posted June 23, 2017 Share Posted June 23, 2017 3 minutes ago, S3Nn4oX said: Table = { } function test(thePlayer) Table[1] = thePlayer Table[2] = "Has committed suicide" r, g, b = 255, 0, 0 Table[3] = r, g, b killPed(Table[1], Table[1]) outputChatBox(Table[1]..Table[2].."!", root, Table[3], true) end addCommandHandler("suicide", test) I think i understood almost everything , thanks to you ! Out of pure curiosity, did that code work? Cuz i've never declared 3 values to one table "slot" like that (Table[3]). Btw, team effort... that's what community's for. Link to comment
S3Nn4oX Posted June 23, 2017 Author Share Posted June 23, 2017 1 minute ago, StormFighter said: Out of pure curiosity, did that code work? Cuz i've never declared 3 values to one table "slot" like that (Table[3]). Btw, team effort... that's what community's for. Don't know, i didn't test it yet Link to comment
WorthlessCynomys Posted June 23, 2017 Share Posted June 23, 2017 Allright. I don't wanna confuse you, but if you want to store a color i.e in a table but in one "slot", You can have tables within tables. myTable = {1, 8, {255, 0, 0, 255}, 3} -- And you handle it like: myTable[3][1] -- This is 255 1 Link to comment
S3Nn4oX Posted June 23, 2017 Author Share Posted June 23, 2017 (edited) How can i merge 2 tables?, i.e I merge 2 strings with '..' so how do i do that with tables the script works fine i tested it, but it didn't output the text? ty . Edited June 23, 2017 by S3Nn4oX Link to comment
WorthlessCynomys Posted June 23, 2017 Share Posted June 23, 2017 Well... that's something, I've never done. --But maybe table1 = {1,3,9,2} table2 = {3, 10, 4, 6} tableCount = #table1 for i, v in ipairs(table2) do table1[tableCount+i] = v end 1 Link to comment
S3Nn4oX Posted June 23, 2017 Author Share Posted June 23, 2017 12 minutes ago, StormFighter said: Well... that's something, I've never done. --But maybe table1 = {1,3,9,2} table2 = {3, 10, 4, 6} tableCount = #table1 for i, v in ipairs(table2) do table1[tableCount+i] = v end ty bru I appreciate it, you helped me a lot!. Link to comment
Enargy, Posted June 24, 2017 Share Posted June 24, 2017 4 hours ago, S3Nn4oX said: It is possible to attach GUI with dx element? You can do that calculating dxElement's position and use onClientRender for updating the gui's position. 1 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