Page 1 of 1
userfunction to addon ?
Posted: Fri Apr 26, 2013 3:21 am
by acrata
hello
I want to convert
this into an addon. I tried creating a folder and a .toc file, but when I run
GuildDonateItems function in game got this error:
[string "?"]:20: attempt to index global 'inventory' (a nil value)
Is possible convert that function? and if it is possible, what I should do?
Thanks, and excuse me if my english is too bad.
Re: userfunction to addon ?
Posted: Fri Apr 26, 2013 4:17 am
by rock5
They are completely different. Userfunctions use bot and micromacro functions and variables that are not available to the game. It would have to be completely rewritten using different methods, assuming it's even possible.
Re: userfunction to addon ?
Posted: Fri Apr 26, 2013 6:33 am
by lisa
it is more than likely "possible" but yeah would basically need to be written from scratch and it would take a while.
Re: userfunction to addon ?
Posted: Fri Apr 26, 2013 3:54 pm
by acrata
Thanks for the answers.
If you can help creating the addon i will be very grateful.
I'm just trying to make a function like
GuildDonateItems userfunction.
Code: Select all
function GuildDonateBagID(bagid) --this part should work good--
local i=bagid
PickupBagItem(i)
GCB_GetContributionItem(n)
if CursorHasItem() then
PickupBagItem(i)
else
GCB_OnOK()
end
end
function GuildDonateItems(itemslist)
local i=1
while -dont know what must be here- do local inventoryIndex, _, name, _, _, _ = GetBagItemInfo(i)
if itemlist == name then
GuildDonateBagID(inventoryIndex)
end
i = i + 1
end
end
I don't understand much about programming, just took ideas from other functions.
Re: userfunction to addon ?
Posted: Fri Apr 26, 2013 7:42 pm
by lisa
Tell you what, if you do all the "grunt" work I'll help you put it together.
Simplest way of making this work would be to have a table of names all the resources you want to donate.
This will get you started.
Code: Select all
local resourcenames = {"Teardrop Ruby","Wisdom Core","Magic Fortune Grass","Moonlight Pearl","Nightmare Essence"}
Note this will be language dependant, as in only work for English, if you want it to be used for any language then the table will need to be of the item ID's, I can make it work with ID's aswell.
It would probably be better if you did it using ID's
Code: Select all
local resourceID = {207930,207330,206590,206592,207326}
Re: userfunction to addon ?
Posted: Mon Apr 29, 2013 12:40 pm
by acrata
I almost done the addon, but i dont know how to donate only some items
addon.lua
Code: Select all
function Donatemats()
if not CursorHasItem() then
local id
for i = 1, 240 do
id = Linkitem(GetBagItemLink(i))
PickupBagItem(i)
GCB_GetContributionItem(n)
if CursorHasItem() then
PickupBagItem(i)
else
GCB_OnOK()
end
end
end
end
function Linkitem(link)
local data
if link and link ~= "" then
_, data, _ = ParseHyperlink(link)
if data then
return tonumber(string.sub(data, 1, 5), 16)
end
end
return nil
end
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)
Re: userfunction to addon ?
Posted: Mon Apr 29, 2013 3:44 pm
by attackspeedzero
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.
Re: userfunction to addon ?
Posted: Tue Apr 30, 2013 4:31 am
by acrata
I'm having troubles with the table.
When I use this code addon is not working.
Code: Select all
function Donate(i)
PickupBagItem(i)
GCB_GetContributionItem(n)
if CursorHasItem() then
PickupBagItem(i)
else
GCB_OnOK()
end
end
function Donatemats()
local resourcenames = {TEXT("Sys206591_name"),TEXT("Sys206590_name"),TEXT("Sys206592_name")}
if not CursorHasItem() then
for i = 1, 240 do
GetBagItemLink(i)
if GetBagItemLink(i)~= nil then
local _, _, text = ParseHyperlink(GetBagItemLink(i))
if resourcenames == text then
Donate(i)
end
end
end
end
end
But if I change table to
Code: Select all
local resourcenames = TEXT("Sys206591_name")
the addon works good, but only donate one item.
Re: userfunction to addon ?
Posted: Tue Apr 30, 2013 4:59 am
by rock5
Your getting closer.
compares a table with a text. You have to compare the text names within the table to "text". So something like
Code: Select all
for k,v in pairs(resourcenames) do
if v == text then
Donate(i)
break -- item donated so break
end
end
Re: userfunction to addon ?
Posted: Tue Apr 30, 2013 5:19 am
by acrata
rock5 wrote:Your getting closer.
compares a table with a text. You have to compare the text names within the table to "text". So something like
Code: Select all
for k,v in pairs(resourcenames) do
if v == text then
Donate(i)
break -- item donated so break
end
end
It finally works !!
Thanks for all the help guys !
Re: userfunction to addon ?
Posted: Mon Aug 26, 2013 8:48 pm
by jester
But what about the complete solution to the others?
Now, that there are danomu question on the official forum:
bagid = 1
repeat
local inventoryIndex, icon, name, itemCount, locked, invalid = GetBagItemInfo(bagid)
if itemCount ~= 0 then
PickupBagItem(inventoryIndex)
GCB_GetContributionItem()
if CursorHasItem() then
PickupBagItem(inventoryIndex)
else
GCB_OnOK()
end
end
bagid = ( bagid + 1 )
until bagid == 10