Page 1 of 1

Auto upgrade/plus equipment addon problem

Posted: Thu Dec 31, 2009 9:20 am
by megumi
First, if I have posted this here in error, I apologize. If you could please redirect me to where I should post it?

I had found an addon before RoM version 2 came out that worked well. After the update it no longer works properly. I was wondering if someone here could help out as the original developer (bloodyrain2k) is no longer active. I've been trying to figure this problem out myself but I really don't have the "know-how". I figured out a simple fix for one of the problems, buying the correct jewels for level 51+, but that's as far as I've been able to get. Yes, fairly amateur I know, but I'm trying.

What it did: you enter the command (/atup start #) with # being the target plus you want. From there, you need to have the jewel vendor window open with only the equipment you want upgraded on your character. It then proceeds to either use jewels you have already bought, use these to upgrade, then proceeds to buy the proper jewel one by one attempting to upgrade the equipment to the value specified.

What it does now: Continuously buys jewels without attempting to apply the jewel to the equipment.

If any other info is needed please let me know.

LUA

Code: Select all

-- Thanks to the creators of AdvancedCrafting, pbInfo, wrAutoNeed and XBar. Looking at your code helped me to get my addon working ^^
-- Also thanks to Alleris for telling me how to get the equipments + and other stuff ^^

local color = "|cffff4374"
local AU = color.."AutoUpgrade: "
local command = "/atup or /autoupgrade"
local version = "0.1"

AU_UpgradeStats = {}

local ShopItems = nil
local WantedPlus = 1
local StopUpgrading = true
local UpgradeCD = 0
local WaitingForItem = false

local CurrentUpgrade = {}

local minplus = 1
local maxplus = 6

function AU_OnLoad(this)
	SaveVariables("AU_UpgradeStats")
	this:RegisterEvent( "VARIABLES_LOADED" );
	this:RegisterEvent( "PLAYER_BAG_CHANGED" );
	--this:RegisterEvent( "PLAYER_MONEY" );
	this:RegisterEvent( "STORE_OPEN" );
	--this:RegisterEvent( "STORE_CLOSED" );
	this:RegisterEvent( "UNIT_BUFF_CHANGED" );
	this:RegisterEvent( "CASTING_STOP" );
	this:RegisterEvent( "CASTING_FAILED" );
	this:RegisterEvent( "CHAT_MSG_SYSTEM_GET" );
	DEFAULT_CHAT_FRAME:AddMessage(AU.."AutoUpgrade "..version.." loaded")
end

function AU_OnEvent(this,event,arg1,arg2,arg3,arg4)
	if event == "VARIABLES_LOADED" then
	elseif(event == "SAVE_VARIABLES") then
		SaveVariables("AU_UpgradeStats")
	elseif event == "PLAYER_BAG_CHANGED" then
		-- if WaitingForItem then
			-- WaitingForItem = false
			-- StopUpgrading = false
			-- UpgradeCD = 1
		-- end
		--DEFAULT_CHAT_FRAME:AddMessage(arg1.." - "..arg2.." - "..arg3.." - "..arg4)
	elseif event == "STORE_CLOSED" then
		--DEFAULT_CHAT_FRAME:AddMessage(AU.."shop closed")
	elseif event == "STORE_OPEN" then
		AU_ScanShop()
	elseif event == "UNIT_BUFF_CHANGED" and not StopUpgrading then
		UpgradeCD = 1
		StopUpgrading = false
		--DEFAULT_CHAT_FRAME:AddMessage(AU.."got buffed...")
		--DEFAULT_CHAT_FRAME:AddMessage(arg1.." - "..arg2.." - "..arg3.." - "..arg4)
	elseif event == "CASTING_FAILED" and not StopUpgrading then
		StopUpgrading = true
		--DEFAULT_CHAT_FRAME:AddMessage(AU.."stopping upgrade process")
	elseif event == "CASTING_STOP" then
		--if not StopUpgrading then
			--timestart = GetTime()
			--while GetTime() - timestart < 2 do
			--	if GetTime() - timestart < 0 then break end
			--end
			--AU_Upgrade()
		--end
	elseif event == "CHAT_MSG_SYSTEM_GET" then
		if string.find(arg1,"Refining ") then
			if CurrentUpgrade ~= {} then
				cu = CurrentUpgrade
				CurrentUpgrade = {}
				res = ""
				if string.find(string.lower(arg1)," failed") then res = "failed" else res = "success" end
				hsh = os.date("%y%m%d%H%M%S")..cu.BaseName..cu.Name..res
				AU_UpgradeStats[#AU_UpgradeStats+1] = {Hash = hsh,Slot = cu.Slot,BaseName = cu.BaseName,Name = cu.Name,Quality = cu.Quality,Level = cu.Level,Jewel = cu.Jewel, Result = res}
				SaveVariables("AU_UpgradeStats")
				--DEFAULT_CHAT_FRAME:AddMessage(AU.." result logged: "..hsh..", "..cu.Name..", "..cu.Level..", "..cu.Jewel..", "..res)
			end
			if not StopUpgrading then
				UpgradeCD = 1
				-- timestart = GetTime()
				-- for i = 1,5555555 do
					-- if GetTime() - timestart >= 2 then i = 5555555 end
				-- end
				-- AU_Upgrade()
			end
		end
	end
end

function AU_OnUpdate(this,elapsed)
	if UpgradeCD > 0 then UpgradeCD = UpgradeCD - elapsed end
	if UpgradeCD < 0 then UpgradeCD = 0; AU_Upgrade() end
end

function AU_ScanShop()
	maxitems = GetStoreSellItems()
	ShopItems = {}
	for i = 1,maxitems do
		_,iname,iprice = GetStoreSellItemInfo(i)
		ShopItems[iname] = {Index = i, Price = iprice}
	end
	--DEFAULT_CHAT_FRAME:AddMessage(AU.."shop scanned")
end

function AU_Upgrade()
	--DEFAULT_CHAT_FRAME:AddMessage(AU.."not working yet...");
	UpgradeCD = 0
	ToUpgrade = AU_ToUpgrade(WantedPlus)
	--DEFAULT_CHAT_FRAME:AddMessage(AU..#ToUpgrade);
	if ToUpgrade ~= {} then
		for i = 0,#ToUpgrade do
			--DEFAULT_CHAT_FRAME:AddMessage(i.." : "..ToUpgrade[i].Name.." - "..ToUpgrade[i].Slot);
			--DEFAULT_CHAT_FRAME:AddMessage(AU.."looking for "..ToUpgrade[i].Jewel.." for "..ToUpgrade[i].Name)
			iteminbag = AU_GetJewelInBag(ToUpgrade[i].Jewel)
			if iteminbag > -1 then
				--UseBagItem(GetBagItemInfo(iteminbag))
				CurrentUpgrade = ToUpgrade[i]
				UseItemByName(ToUpgrade[i].Jewel)
				PickupEquipmentItem(ToUpgrade[i].Slot)
				return nil
			end
		end
		if StoreFrame:IsVisible() then
			--DEFAULT_CHAT_FRAME:AddMessage(AU..#ShopItems)
			if ShopItems ~= nil then
				--DEFAULT_CHAT_FRAME:AddMessage(AU..ShopItems[ToUpgrade[0].Jewel].Index)
				if ShopItems[ToUpgrade[0].Jewel].Index > 0 then
					WaitingForItem = true
					DEFAULT_CHAT_FRAME:AddMessage(AU.."buying |r"..ToUpgrade[0].Jewel..color.." for "..ToUpgrade[0].Name)
					StoreBuyItem(ShopItems[ToUpgrade[0].Jewel].Index,1)
					UpgradeCD = 1.5
					return nil
				end
			end	
		else
			StopUpgrading = true
			return nil
		end
		--DEFAULT_CHAT_FRAME:AddMessage(AU.."no jewels found, buying one if possible")
	end
end

function AU_Start(Wanted)
	StopUpgrading = false
	WaitingForItem = false
	UpgradeCD = 0
	WantedPlus = 0 + tonumber(Wanted)
	AU_Upgrade()
end

function AU_JewelType(Tooltip) -- Weapon = 0 / Armor = 1 / Accessory = 2 / Unknown = -1
	accessory = {"Accessory"}
	armor = {"Cloth","Leather","Chain","Plate","Shields"}
	weapon = {"Sword","Dagger","Staff","Wand","Axe","Bludgeon","Hammer","Bow","Crossbow"}

	for i = 1,#accessory do
		if string.find(Tooltip,accessory[i]) then return 2 end
	end
	for i = 1,#armor do
		if string.find(Tooltip,armor[i]) then return 1 end
	end
	for i = 1,#weapon do
		if string.find(Tooltip,weapon[i]) then return 0 end
	end
	return -1
end

function AU_ToUpgrade()
	toupgrade = {}
	count = 0
	findlvl = "requires level "
	for es = 0,21 do
		_,_,equip = GetInventoryItemDurable("player",es)
		--if equip == nil then equip = "" end
		if equip ~= nil then 
			GameTooltip:SetInventoryItem("player",es)
			equipname = GameTooltipTextLeft1:GetText()
			--equiptype = GetInventoryItemType("player",es) -- -1 means nothing, 0 and 1 dunno
			equipquality = GetInventoryItemQuality("player",es) -- 0 is white, 1 is green, 2 is blue
			equiplv = GameTooltipTextLeft2:GetText()
			if not string.find(string.lower(equiplv),findlvl) then
				equiplv = GameTooltipTextLeft3:GetText()
				if not string.find(string.lower(equiplv),findlvl) then
					equiplv = GameTooltipTextLeft4:GetText()
					if not string.find(string.lower(equiplv),findlvl) then
						equiplv = GameTooltipTextLeft5:GetText()
						if not string.find(string.lower(equiplv),findlvl) then
							DEFAULT_CHAT_FRAME:AddMessage(AU.."Can't find level of item "..equipname)
							return nil -- if you know a better way for this tell me...
						end
					end
				end
			end
			equiplv = string.gsub(equiplv,"%D","")
			
			equiptype = AU_JewelType(GameTooltipTextLeft3:GetText())
			if equiptype == -1 then
				equiptype = AU_JewelType(GameTooltipTextLeft4:GetText())
				if equiptype == -1 then
					equiptype = AU_JewelType(GameTooltipTextLeft5:GetText())
					if equiptype == -1 then
						equiptype = AU_JewelType(GameTooltipTextLeft6:GetText())
						if equiptype == -1 then
							DEFAULT_CHAT_FRAME:AddMessage(AU.."Can't find type of item "..equipname)
							return nil -- if you know a better way for this tell me...
						end
					end
				end
			end
			--DEFAULT_CHAT_FRAME:AddMessage(equiptype.." - "..equip.." - "..equipname.." - ".." - "..equipquality.." - "..equiplv.." - "..AU_GetPlus(equipname))
			if AU_GetPlus(equipname) < WantedPlus then
				toupgrade[count] = {Slot = es, Name = equipname, Level = equiplv, Jewel = AU_JewelName(equiptype,equiplv), Quality = equipquality, BaseName = equip}
				--DEFAULT_CHAT_FRAME:AddMessage(AU..toupgrade[count].Jewel)
				count = count + 1
			end
		end
	end
	GameTooltip:Hide()
	return toupgrade
end

function AU_GetPlus(ItemName)
	Plus = string.gsub(ItemName,equip,"")
	--Plus = string.gsub(Plus,"%X","")
	--Plus = string.gsub(Plus," ","")
	Plus = string.gsub(Plus,"|c........","")
	Plus = string.gsub(Plus,"%D","")
	--oPlus = Plus
	Plus = tonumber(Plus)
	if Plus == nil then Plus = 0 end
	--DEFAULT_CHAT_FRAME:AddMessage(oPlus.." = "..Plus)
	return Plus
end

function AU_JewelName(Type,Level)
	Type = string.gsub(Type,"%D","")
	Type = 0 + tonumber(Type)
	Level = string.gsub(Level,"%D","")
	Level = 0 + tonumber(Level)
	--if Level == nil then Level = 0 end
	TypeName = nil

	if Type == 0 then TypeName = "Star" 
	elseif Type == 1 then TypeName = "Moon" 
	elseif Type == 2 then TypeName = "Sun" end

	if TypeName == nil then return "" end
	
	if Level >= 1 and Level <= 20 then return TypeName.." Jewel - Basic"
	elseif Level >= 21 and Level <= 30 then return TypeName.." Jewel - Class I"
	elseif Level >= 31 and Level <= 40 then return TypeName.." Jewel - Class II"
	elseif Level >= 41 and Level <= 50 then return TypeName.." Jewel - Class III"
	elseif Level >= 51 and Level <= 60 then return TypeName.." Jewel - Class IV" end
	
	return ""
end

function AU_GetJewelInBag(JewelName)
	for bi = 1,60 do
		_,_,item = GetBagItemInfo(bi)
		if item == JewelName then return bi end
	end
	return -1
end

SLASH_AUTOUPGRADE1 = "/autoupgrade"
SLASH_AUTOUPGRADE2 = "/atup"
SlashCmdList["AUTOUPGRADE"] = function(editBox, msg)
	local cmd = GetSlashCmdTarget(string.lower(msg))
	if cmd == "start" then
		--DEFAULT_CHAT_FRAME:AddMessage(AU..cmd)
		if string.find(msg,"start ") then
			cmd = string.gsub(msg,"start ","")
			cmd = tonumber(string.sub(cmd,1,1))
			if cmd == nil then cmd = 0 end
			if cmd >= minplus and cmd <= maxplus then AU_Start(cmd)
			else DEFAULT_CHAT_FRAME:AddMessage(AU.."Please enter a possible + value for starting the upgrade process") end
		else AU_Start(1) end
	elseif cmd == "test" then
		for es = 0,21 do
			_,_,equip = GetInventoryItemDurable("player",es)
			if equip == nil then equip = "" end
			--if equip ~= nil then 
				GameTooltip:SetInventoryItem("player",es)
				equipname = GameTooltipTextLeft1:GetText()
				equiptype = GetInventoryItemType("player",es)
				equipquality = GetInventoryItemQuality("player",es)
				DEFAULT_CHAT_FRAME:AddMessage(es.." - "..equip.." - "..equipname.." - "..equiptype.." - "..equipquality)
			--end
		end
		GameTooltip:Hide()
		item1,item2,item3,item4,item5 = GetBagItemInfo(1)
		DEFAULT_CHAT_FRAME:AddMessage(item1.." - "..item2.." - "..item3.." - "..item4.." - "..item5)
	else
		DEFAULT_CHAT_FRAME:AddMessage(AU.."AutoUpgrade "..version.." Help")
		DEFAULT_CHAT_FRAME:AddMessage(AU..command.." start [1-6] - start upgrading your equipment, default is +1 if you want +4 then enter "..command.." start 4")
	end
end
XML

Code: Select all

<Ui xmlns="http://www.runewaker.com/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.runewaker.com/
..\..\WorldXML\UI.xsd">
	<Script file="AutoUpgrade.lua"/>
	<Frame name="AutoUpgrade" parent="UIParent">
		<Scripts>
			<OnLoad>
				AU_OnLoad(this);
			</OnLoad>
			<OnUpdate>
				AU_OnUpdate(this,elapsedTime);</OnUpdate>
			<OnEvent>
				AU_OnEvent(this,event,arg1,arg2,arg3,arg4);
			</OnEvent>
       </Scripts>
	</Frame>
</Ui>

Re: Auto upgrade/plus equipment addon problem

Posted: Wed Jan 13, 2010 7:32 pm
by megumi
Well, found the problem of why it wouldn't apply the jewel to the equipment. I have all bag slots and the addon only checked the first 60 slots. Changed the following

from:

Code: Select all

function AU_GetJewelInBag(JewelName)
	for bi = 1,60 do
to:

Code: Select all

function AU_GetJewelInBag(JewelName)
	for bi = 1,180 do
Here's where it's confusing me. It will upgrade one time if I have 1 jewel in my bag with the shop closed and then stops. If I have more than one jewel in my bag, it still only works one time then picks up the equipment being upgraded and breaks the script. If I have the shop open to start with then it doesn't upgrade at all, it just buys 1 jewel picks up the item and breaks the script. Any help is appreciated.

Thanks in advance.

Re: Auto upgrade/plus equipment addon problem

Posted: Fri Jan 15, 2010 1:33 am
by arntom
"It breaks on equipped items that cannot be refined, such as arrows and projectiles. Unequip those items and it should work just fine." [1]

source:
[1] http://forum.runesofmagic.com/showpost. ... stcount=18

Re: Auto upgrade/plus equipment addon problem

Posted: Fri Jan 15, 2010 5:19 am
by megumi
Not applicable. I only have one item equipped during the test to reduce chances of error.

Re: Auto upgrade/plus equipment addon problem

Posted: Fri Jan 15, 2010 5:39 am
by arntom
Whats the error type?

nothing happend, or is there an error message out ?

Re: Auto upgrade/plus equipment addon problem

Posted: Fri Jan 15, 2010 6:11 am
by megumi
No error message, just the results that I made in my second post.