userfunction to addon ?

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
acrata
Posts: 9
Joined: Fri Apr 26, 2013 2:46 am

userfunction to addon ?

#1 Post by acrata » Fri Apr 26, 2013 3:21 am

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.

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: userfunction to addon ?

#2 Post by rock5 » Fri Apr 26, 2013 4:17 am

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.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: userfunction to addon ?

#3 Post by lisa » Fri Apr 26, 2013 6:33 am

it is more than likely "possible" but yeah would basically need to be written from scratch and it would take a while.
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

acrata
Posts: 9
Joined: Fri Apr 26, 2013 2:46 am

Re: userfunction to addon ?

#4 Post by acrata » Fri Apr 26, 2013 3:54 pm

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.

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: userfunction to addon ?

#5 Post by lisa » Fri Apr 26, 2013 7:42 pm

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}
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual

acrata
Posts: 9
Joined: Fri Apr 26, 2013 2:46 am

Re: userfunction to addon ?

#6 Post by acrata » Mon Apr 29, 2013 12:40 pm

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)

User avatar
attackspeedzero
Posts: 28
Joined: Sat Mar 02, 2013 6:24 pm

Re: userfunction to addon ?

#7 Post by attackspeedzero » Mon Apr 29, 2013 3:44 pm

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.

acrata
Posts: 9
Joined: Fri Apr 26, 2013 2:46 am

Re: userfunction to addon ?

#8 Post by acrata » Tue Apr 30, 2013 4:31 am

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.

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: userfunction to addon ?

#9 Post by rock5 » Tue Apr 30, 2013 4:59 am

Your getting closer.

Code: Select all

if resourcenames == text then
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
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

acrata
Posts: 9
Joined: Fri Apr 26, 2013 2:46 am

Re: userfunction to addon ?

#10 Post by acrata » Tue Apr 30, 2013 5:19 am

rock5 wrote:Your getting closer.

Code: Select all

if resourcenames == text then
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 !! :D

Thanks for all the help guys !

jester
Posts: 15
Joined: Sun May 13, 2012 12:48 pm

Re: userfunction to addon ?

#11 Post by jester » Mon Aug 26, 2013 8:48 pm

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

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests