acrata wrote:data.lua
Code: Select all
local Mats = {
[1] = {Name = TEXT("Sys206591_name"), ID = 206591, Type = "WOOD"},
[2] = {Name = TEXT("Sys206590_name"), ID = 206590, Type = "HERB"},
[3] = {Name = TEXT("Sys206592_name"), ID = 206592, Type = "MINING"},
}
Return Mats
when I call Donatemats() function in game, the addon donates all items. Please help me making addon donate only some items, i dont know how to add a working table. (
almost all code is from pet auto craft addon lol)
"Mats" above is a 2-dimensional table, a table of tables (aka a Matrix). Doesn't seem to be anything wrong with it, really. What you have is the same as
Code: Select all
Mats[1] = {Name = TEXT("Sys206591_name"), ID = 206591, Type = "WOOD"}
Mats[2] = {Name = TEXT("Sys206590_name"), ID = 206590, Type = "HERB"}
or to further break it down for understanding,
Code: Select all
Mats[1][Name] = TEXT("Sys206591_name")
Mats[1][ID] = 206591
Mats[1][Type] = "WOOD"
Again, there's nothing wrong with the matrix as written.
Based on what you've already written, you probably want to check each inventory slot to see if it contains any of the items in the data table. This should be fairly simple, basically, you want 2 for loops, one to check each slot of your inventory, and one to check each entry in the table of items that you want donated, and then check them against each other. Something like
Code: Select all
for i = 1, 240 do -- check all inventory slots
for j = 1, #data do -- check for all possible items from data table
-- PSEUDOCODE NOW
if _Inventory[i] contains _Data[j] then DONATE end
end
end
And then build from there.