Jump to content
  • 0

lua related problem matching tables


hsusudhbsjwhdhdgsj

Question

How i should match 2 table and if the key  match insert them in a third table the key from second table and the value from first table

basically what im trying to do is this

 

i have a table with all monsters data

 

names {
      101 = "Fairy",
      10111 = "Elucia",
      10112 = "Iselia",
      10113 = "Aeilene",
      10114 = "Neal",
      10115 = "Sorin",
      10131 = "Elucia",
      10132 = "Iselia",
      10133 = "Aeilene",
      10134 = "Neal",
      10135 = "Sorin",

      102 = "Imp",
      10211 = "Fynn",
      10212 = "Cogma",
      10213 = "Ralph",
      10214 = "Taru",
      10215 = "Garok",

      103 = "Pixie",
      10311 = "Kacey",
      10312 = "Tatu",
      10313 = "Shannon",
      10314 = "Cheryl",
      10315 = "Camaryn",
      10331 = "Kacey",
      10332 = "Tatu",
      10333 = "Shannon",
      10334 = "Cheryl",
      10335 = "Camaryn",

      104 = "Yeti",
      10411 = "Kunda",
      10412 = "Tantra",
      10413 = "Rakaja",
      10414 = "Arkajan",
      10415 = "Kumae",
   }

then i retive the monsters that the player Account posses using 

 

offset = offset

function rst(new_tre, new_ire, original_tre, original_ire, offset)
	new_tre[new_ire].address= original_tre[original_ire].address + offset
	new_tre[new_ire].flags = gg.TYPE_DWORD
end

gg.searchNumber(AccID..";6;1065353216::", gg.TYPE_DWORD, false, gg.SIGN_EQUAL, 0, -1, -1)
    	 rF = gg.getResults(gg.getResultsCount())

p={}

			for i=2, #rF, 3 do
				p[i]={}
				rst(p, i, rF, i, offset)
			end
			p_mnst = gg.getValues(p)

so at this point i hate the database with all monster that exist on game on names {} and the monsters ID number that the account have on p_mnst {} now what i want to do is get the names of the IDs on p_mnst {} and insert on new table IDandNames {} so i could ad the monster with the names on a submenu where the people could change data on that particular monster

 

so the p_mnst {} will look like this

p_mnst {
  10115,
  10213,
  10315
}

the  IDandNames {} should look like this

 

 IDandNames {
  10115 = "monster name", -- so the ID number retrived from p_mnst{} and the monster name retrived from Names{}
  10213 = "monster name",
  10315 = "monster name",
}

the  submenu should look something like this  

monsterPoss = gg.choice({
          IDandNames[1], --here should be the name of the monster and not the ID number
          IDandNames[2],
          IDandNames[3],  
		}, nil, " Select the monster you want to edit")
		if monsterPoss == 1 then 
    	   gg.searchNumber(AccID..";"..IDandNames["monster name"]..";1065353216::", gg.TYPE_DWORD, false, gg.SIGN_EQUAL, 0, -1, -1)
    	 rK = gg.getResults(gg.getResultsCount())
				do stuff 
			

where ..IDandNames["monster name"] should be the ID number of the monster you selected to change

i dont know how to do all of this on lua since lua dosnt have table.match or somethink like this

Can someone help me build a code for this

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

6 hours ago, hsusudhbsjwhdhdgsj said:

How i should match 2 table and if the key  match insert them in a third table the key from second table and the value from first table

basically what im trying to do is this

 

i have a table with all monsters data

 


names {
[101]="Fairy",
[10111]="Elucia",
[10112]="Iselia",
[10113]="Aeilene",
[10114]="Neal",
[10115]="Sorin",
[10131]="Elucia",
[10132]="Iselia",
[10133]="Aeilene",
[10134]="Neal",
[10135]="Sorin",

[102]="Imp",
[10211]="Fynn",
[10212]="Cogma",
[10213]="Ralph",
[10214]="Taru",
[10215]="Garok",

[103]="Pixie",
[10311]="Kacey",
[10312]="Tatu",
[10313]="Shannon",
[10314]="Cheryl",
[10315]="Camaryn",
[10331]="Kacey",
[10332]="Tatu",
[10333]="Shannon",
[10334]="Cheryl",
[10335]="Camaryn",
   }

then i retive the monsters that the player Account posses using 

 


offset = offset

function rst(new_tre, new_ire, original_tre, original_ire, offset)
	new_tre[new_ire].address= original_tre[original_ire].address + offset
	new_tre[new_ire].flags = gg.TYPE_DWORD
end

gg.searchNumber(AccID..";6;1065353216::", gg.TYPE_DWORD, false, gg.SIGN_EQUAL, 0, -1, -1)
    	 rF = gg.getResults(gg.getResultsCount())

p={}

			for i=2, #rF, 3 do
				p[i]={}
				rst(p, i, rF, i, offset)
			end
			p_mnst = gg.getValues(p)

so at this point i hate the database with all monster that exist on game on names {} and the monsters ID number that the account have on p_mnst {} now what i want to do is get the names of the IDs on p_mnst {} and insert on new table IDandNames {} so i could ad the monster with the names on a submenu where the people could change data on that particular monster

 

so the p_mnst {} will look like this


p_mnst {
  10115,
  10213,
  10315
}

the  IDandNames {} should look like this

 


 IDandNames {
  10115 = "monster name", -- so the ID number retrived from p_mnst{} and the monster name retrived from Names{}
  10213 = "monster name",
  10315 = "monster name",
}

the  submenu should look something like this  


monsterPoss = gg.choice({
          IDandNames[1], --here should be the name of the monster and not the ID number
          IDandNames[2],
          IDandNames[3],  
		}, nil, " Select the monster you want to edit")
		if monsterPoss == 1 then 
    	   gg.searchNumber(AccID..";"..IDandNames["monster name"]..";1065353216::", gg.TYPE_DWORD, false, gg.SIGN_EQUAL, 0, -1, -1)
    	 rK = gg.getResults(gg.getResultsCount())
				do stuff 
			

where ..IDandNames["monster name"] should be the ID number of the monster you selected to change

i dont know how to do all of this on lua since lua dosnt have table.match or somethink like this

Can someone help me build a code for this

so is even harder cause the values of p_mnst {}  are tables

here the print of p_mnst {}

 

Script ended:
{ -- table(84f1af3)
 [101] = { -- table(5ad736)
  ['address'] = 0x72fd2eb420,
  ['flags'] = 4, -- gg.TYPE_DWORD
  ['value'] = 23513,
 },
 [104] = { -- table(ac0d7a4)
  ['address'] = 0x72fd302e40,
  ['flags'] = 4, -- gg.TYPE_DWORD
  ['value'] = 19615,
 },
 [107] = { -- table(c7530c2)
  ['address'] = 0x72fd303f70,
  ['flags'] = 4, -- gg.TYPE_DWORD
  ['value'] = 13231,
 },
 [110] = { -- table(e05ca10)
  ['address'] = 0x72fd308430,
  ['flags'] = 4, -- gg.TYPE_DWORD
  ['value'] = 25111,
 },
 [113] = { -- table(de9970e)
  ['address'] = 0x72fd31b990,
  ['flags'] = 4, -- gg.TYPE_DWORD
  ['value'] = 21512,
 },
 [116] = { -- table(65773c)
  ['address'] = 0x72fd33bd30,
  ['flags'] = 4, -- gg.TYPE_DWORD
  ['value'] = 24713,
 }

 

Link to comment
Share on other sites

Firstly, your table of correspondence of monster ids to their names have multiple occurrences of same names, so a proper reverse table to get id by name can't be constructed because of ambiguity. But it's not a problem, because constructing such table is not required for a solution to your task.

To be able to both get monster name by id and monster id by name (by having groups of id/name pairs) a table of tables with data about player's monsters can be constructed like this: 

local playerMonsters = {}
for k, v in pairs(p_mnst) do
  local id = v.value
  table.insert(playerMonsters, {id = id, name = names[id]})
end

This table can then be used to construct "IDandNames" table with names of the monsters to be passed to "gg.choice" function: 

local IDandNames = {}
for i, v in ipairs(playerMonsters) do
  IDandNames[i] = v.name
end

-- ...

monsterPoss = gg.choice(IDandNames, nil, " Select the monster you want to edit")

Id of a monster corresponding to any selected choice item can then be retrieved like this: 

local selectedMonsterId
if monsterPoss ~= nil then
  selectedMonsterId = playerMonsters[monsterPoss].id
end

Finally, the id can be used to perform the search: 

gg.searchNumber(AccID..";"..selectedMonsterId..";1065353216::", gg.TYPE_DWORD)
Link to comment
Share on other sites

1 hour ago, CmP said:

Firstly, your table of correspondence of monster ids to their names have multiple occurrences of same names, so a proper reverse table to get id by name can't be constructed because of ambiguity. But it's not a problem, because constructing such table is not required for a solution to your task.

To be able to both get monster name by id and monster id by name (by having groups of id/name pairs) a table of tables with data about player's monsters can be constructed like this: 


local playerMonsters = {}
for k, v in pairs(p_mnst) do
  local id = v.value
  table.insert(playerMonsters, {id = id, name = names[id]})
end

This table can then be used to construct "IDandNames" table with names of the monsters to be passed to "gg.choice" function: 


local IDandNames = {}
for i, v in ipairs(playerMonsters) do
  IDandNames[i] = v.name
end

-- ...

monsterPoss = gg.choice(IDandNames, nil, " Select the monster you want to edit")

Id of a monster corresponding to any selected choice item can then be retrieved like this: 


local selectedMonsterId
if monsterPoss ~= nil then
  selectedMonsterId = playerMonsters[monsterPoss].id
end

Finally, the id can be used to perform the search: 


gg.searchNumber(AccID..";"..selectedMonsterId..";1065353216::", gg.TYPE_DWORD)

smooth as butter

 

give me ur paypal i will make sure you will drink a tasty coffee tomorrow 

Link to comment
Share on other sites

 

[added 0 minutes later]
On 6/15/2021 at 1:32 AM, CmP said:

Firstly, your table of correspondence of monster ids to their names have multiple occurrences of same names, so a proper reverse table to get id by name can't be constructed because of ambiguity. But it's not a problem, because constructing such table is not required for a solution to your task.

To be able to both get monster name by id and monster id by name (by having groups of id/name pairs) a table of tables with data about player's monsters can be constructed like this: 


local playerMonsters = {}
for k, v in pairs(p_mnst) do
  local id = v.value
  table.insert(playerMonsters, {id = id, name = names[id]})
end

This table can then be used to construct "IDandNames" table with names of the monsters to be passed to "gg.choice" function: 


local IDandNames = {}
for i, v in ipairs(playerMonsters) do
  IDandNames[i] = v.name
end

-- ...

monsterPoss = gg.choice(IDandNames, nil, " Select the monster you want to edit")

Id of a monster corresponding to any selected choice item can then be retrieved like this: 


local selectedMonsterId
if monsterPoss ~= nil then
  selectedMonsterId = playerMonsters[monsterPoss].id
end

Finally, the id can be used to perform the search: 


gg.searchNumber(AccID..";"..selectedMonsterId..";1065353216::", gg.TYPE_DWORD)

everything is great now but i wanted to sort the table alphabeticaly and tried table.sort(IDandNames) but if selectedMonsterId = playerMonsters[monsterPoss].id when clicked the id dosnt match with the name from IDandNames

should i make a new array like table and sort cause i dont think lua tables can be sort

Link to comment
Share on other sites

You can just sort "playerMonsters" table before using it so that "IDandNames" table elements will be in desired order right after it is constructed: 

table.sort(playerMonsters, function (a, b) return a.name:upper() < b.name:upper() end)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.