Jump to content

Attaching GUI with dx


S3Nn4oX

Recommended Posts

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 by StormFighter
Extension
  • Like 1
Link to comment
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
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 by StormFighter
Misspelling
  • Like 1
Link to comment
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 xD !

Edited by S3Nn4oX
Link to comment
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 xD !

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

Link to comment
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

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