need help sir about autosell

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
ggsir
Posts: 5
Joined: Mon Feb 15, 2010 11:42 pm

need help sir about autosell

#1 Post by ggsir »

ok first of all i would like to thanks all for this wonderful program 8-)

i followed the tips of the admin by adding PH = "durabilty" in the item tool tip durabilty but the bot can't read my lua it appears like this classes/inventory.lua:1:C:....../classes.item.lua:9: ') expected to close '(' at line 4) near 'PH' and when i delete the ph=durability in item.lua my bot is working but it can't sell nor buy any items
btw here is the example of my MM,

Moving to waypoint #7, (-5583, 3349)
We try to find NPC Miles: Lordworm, Halissa, Lordworm, Halissa, Lordworm, Haliss
a, Lordworm, Lordworm, Lordworm, Lordworm, Lordworm, Lordworm, Lordworm, Lordwor
m, Jeff, Jeff, Jeff, Jeff, Halissa, Halissa, Halissa, Misfit, Halissa, Halissa,
Halissa, Halissa, Halissa, Jeff, Jeff, Jeff, Cooking Supplies Merchant, Miles,
We successfully target NPC Miles and try to open the dialog window.
Mapping inventory (bagslot 1 to 60)...
100% [**************************************************]
[DEBUG] Check item so sell: 203022 Lover's Passion
Lang: PH
durakey: nil
...Desktop/micromacro/scripts/rom/classes/inventory.lua:394: attempt to concaten
ate local 'durakey' (a nil value)
thanx for advance
User avatar
Administrator
Site Admin
Posts: 5353
Joined: Sat Jan 05, 2008 4:21 pm

Re: need help sir about autosell

#2 Post by Administrator »

You did it wrong, then. If you want help, you're going to have to provide more information.
ggsir
Posts: 5
Joined: Mon Feb 15, 2010 11:42 pm

Re: need help sir about autosell

#3 Post by ggsir »

btw my client is philippines

by the help of the search button in the forums ive search the problem same as mine about inventory.lua
and i also recieve this error
inventory.lua:394: attempt to concatenate local 'durakey' <a nil value>
so i decided to follow your instructions and as you said sir i followed it by adding below this on line389 in inventory.lua
printf("Lang: %s\n", tostring(bot.ClientLanguage));
printf("durakey: %s\n", tostring(durakey) or "nil");

by adding PH= "durability" in item.lua but after adding ph=durability my MM didnt work properly and when i delete the ph="durability" it came back to normal
User avatar
Administrator
Site Admin
Posts: 5353
Joined: Sat Jan 05, 2008 4:21 pm

Re: need help sir about autosell

#4 Post by Administrator »

And again, i need to see exactly what changes you are making. That is, the before and after of you adding or removing anything. I'm assuming you are adding the line for PH client wrong.

You're also using an outdated copy. Try copying addresses.lua, updating, then swap your current addresses.lua back in (so you'll be using the old copy of it, not the updated one).
ggsir
Posts: 5
Joined: Mon Feb 15, 2010 11:42 pm

Re: need help sir about autosell

#5 Post by ggsir »

this is my waypoints

Code: Select all

<waypoints>
	<!-- #  1 --><waypoint x="-5350" z="144">	</waypoint>
	<!-- #  2 --><waypoint x="-5493" z="739">	</waypoint>
	<!-- #  3 --><waypoint x="-5657" z="1532">	</waypoint>
	<!-- #  4 --><waypoint x="-5772" z="2086">	</waypoint>
	<!-- #  5 --><waypoint x="-6025" z="2554">	</waypoint>
	<!-- #  6 --><waypoint x="-5884" z="3125">	</waypoint>
	<!-- #  7 --><waypoint x="-5583" z="3349">__WPL:reverse()		player:merchant("Miles");
if( player.Fights-player.free_counter1 > 1000 ) then
		player.free_counter1 = player.Fights;
		load_paths("test7");
end
	</waypoint>
</waypoints>
this is my profile

Code: Select all

<profile>
	<options>
		<!-- Try the bot with a new char mage                   -->
		<!-- At the pioneer village. Use demo.xml waypoint file -->
		<option name="HP_LOW"			value="65" />
		<option name="MP_LOW_POTION"	value="50" />
		<option name="HP_LOW_POTION"	value="60" />

		<!-- Rest if HP or Mana is below that level -->
		<option name="HP_REST" value="40" />
		<option name="MP_REST" value="40" />

		<!-- Shopping options, how many of what do you want to keep in your inventory -->
		<option name="HEALING_POTION"	value="50" />
		<option name="MANA_POTION"		value="50" />
		<option name="ARROW_QUIVER"		value="0" />
		<option name="THROWN_BAG"		value="0" />

		<!-- Combat options -->
		<option name="COMBAT_TYPE"			value="" />		<!-- leave empty or choose ranged/melee if not using class default -->
		<option name="COMBAT_RANGED_PULL"	value="false" />	<!-- only important for melees -->
		<option name="COMBAT_DISTANCE"		value="200" />
		<option name="MAX_FIGHT_TIME"		value="15" />		<!-- Max time without damage before break -->
		<option name="DOT_PERCENT"			value="90" />
		<option name="ANTI_KS"				value="true" />

		<!-- Attack monsters 3 levels above or 10 below your level -->
		<option name="TARGET_LEVELDIF_ABOVE" value="10" />
		<option name="TARGET_LEVELDIF_BELOW" value="10" />

		<!-- Waypoint and movement settings -->
		<option name="WAYPOINTS"			value="test7" /> 	<!-- leave empty to show a list -->
		<option name="RETURNPATH"			value="" />
		<option name="PATH_TYPE"			value="waypoints" />	<!-- waypoints | wander -->
		<option name="WANDER_RADIUS"		value="300" />
		<option name="WAYPOINT_DEVIATION"	value="0" />
		<option name="QUICK_TURN" 			value="true" />
		
		<!--AUTOSELL-->
		<option name="INV_AUTOSELL_ENABLE"	value="true" />
		<option name="INV_AUTOSELL_FROMSLOT"	value="31" />
		<option name="INV_AUTOSELL_TOSLOT"	value="60" />
		<option name="INV_AUTOSELL_QUALITY"	value="white,green" />
		<option name="INV_AUTOSELL_IGNORE"	value="Pfeil,Elementar" />
		<option name="INV_AUTOSELL_NOSELL_DURA"      value="110" />
		<option name="INV_AUTOSELL_STATS_NOSELL"      value=" X,XI" />
		<option name="INV_AUTOSELL_STATS_SELL"      value="IX" />
		<option name="DEBUG_AUTOSELL"      value="true" />

		<!-- Loot settings -->
		<option name="LOOT"					value="true" />
		<option name="LOOT_IN_COMBAT"		value="true" />
		<option name="LOOT_DISTANCE"		value="100" />
		<option name="LOOT_PAUSE_AFTER"		value="0" />		<!-- probability in % for a short rest -->

		<!-- Log out and resurrect settings -->
		<option name="LOGOUT_TIME"			value="0" />		<!-- in minutes, 0 = timer disabled -->
		<option name="LOGOUT_SHUTDOWN"		value="false" />
		<option name="LOGOUT_WHEN_STUCK"	value="true" />
		<option name="RES_AUTOMATIC_AFTER_DEATH" value="true" />


		<!-- For more options and documentation see the RoM Bot Wiki:  -->
		<!-- http://www.solarstrike.net/wiki/index.php5?title=RoM_Bot  -->

	</options>

	<friends>
		<!-- names of friends we help fighting or enemys we don't want to attack -->
		<!-- for umlauts use \129 (ue),\132 (ae),\148 (oe) e.g. K\132fer         -->
		<friend name="friendname1" />
		<friend name="elitemob K\132fer" />
		<friend name="elitemob H\129ter" />
	</friends>

	<hotkeys>
		<!-- to communicate with the RoM API / define ingame a dummy macro at place 1 -->
		<hotkey name="MACRO"		key="VK_0" />
	</hotkeys>

	<!-- define your skills depending from your actual primary class -->
	<!-- see the example for a priest/mage                           -->
	<!-- delete skills you don't have or don't want to use.          -->
	<!-- For more skills to use see /database/skills.xml             -->
	<!-- demo skills for LvL 1 character for all classes             -->
	<skills_mage>
		<skill name="MAGE_FLAME"              hotkey="VK_3" priority="80" />
		<skill name="MAGE_ELEMENTAL_CATALYST" hotkey="VK_2" priority="30" hpper="30" inbattle="true" />
	</skills_mage>
	
	<skills_priest>
		<skill name="PRIEST_REGENERATE"    hotkey="VK_7" priority="90" />
		<skill name="PRIEST_RISING_TIDE"   hotkey="VK_3" priority="80" />
		<skill name="MAGE_FIREBALL"        hotkey="VK_4" priority="70" />
		<skill name="PRIEST_BONE_CHILL"    hotkey="VK_5" priority="70" />
		<!--skill name="PRIEST_SOUL_BOND"     hotkey="VK_T" priority="30" /> -->
		<!--skill name="PRIEST_MAGIC_BARRIER" hotkey="VK_F" priority="20" rebuffcut="60" inbattle="false" /> -->
	</skills_priest>
		
	
	<onLoad>
		-- Additional Lua code to execute after loading the profile
		-- and before the bot starts. e.g. You could overwrite profile settings here
		-- like: changeProfileOption("HP_REST", 60);
		inventory:update();

		if(player.Level == 1) then
			openGiftbags1To10(player.Level);
		else
			levelupSkills1To10("loadonly");
		end;

		if(player.Class1 == CLASS_SCOUT ) then
			changeProfileOption("ARROW_QUIVER", 2);
		end;

	</onLoad>

	<onDeath>
		-- Additional Lua code to execute on death
		-- pauseOnDeath(); -- Stop the script
	</onDeath>

	<onLeaveCombat>
		-- Additional Lua code to execute after a target is finished

			if(player.Level == 10) then
				__WPL:setForcedWaypointType("TRAVEL")
			end;


	</onLeaveCombat>

	<onLevelup>
		-- thats a demo for opening the gift bags from Lvl 1-10
		-- and levelup the skills for a new character (mage or priest recommended)
		-- you can delete that lines if you don't want to use that

			-- single skill would be: sendMacro("SetSpellPoint(4,2);");
			-- or levelupSkill(_skillname, _times)
			levelupSkills1To10();

			-- open giftbag and equipt content
			openGiftbags1To10(player.Level);

	</onLevelup>

	<onSkillCast>
		-- Additional Lua code to execute when casting a skill
		-- Note: arg1 contains the skill being used.
		-- i.e. arg1.Name will be the name of the skill being cast.
	</onSkillCast>
</profile>

in classes folder before, Im using the default settings of item.lua and inventory.lua nothing errors appear, and just i posted earlier when i put the PH= "durability" in item.lua it didnt work but when i used the default item.lua w/o ph=durability it turns back to normal..

Code: Select all

-- A little class

-- Tooltip parser keywords
ITEM_TOOLTIP_DURABILITY = {
	DE		= "Haltbarkeit",
	FR		= "Structure",
	ENEU	= "Durability", 
	ENUS	= "Durability"
        PH = "Durability"


	};

-- itemquality -> color code
ITEMCOLOR = { 
	WHITE = "ffffff",
	GREEN = "00ff00",
	BLUE = "0072bc",
	PURPLE = "c805f8",
	ORANGE = "f68e56",
	GOLD = "a37d50",
	}

CItem = class(
	function(self,slotNumber)
		self.Id = 0;
		self.BagId = 0;
		self.Name = "";
		self.ItemCount = 0;
		self.Color = "ffffff";
		self.SlotNumber = slotNumber;
		self.Icon = "";
		self.ItemLink = "|Hitem:33BF1|h|cff0000ff[Empty]|r|h";
	end
)


function CItem:use()

	-- TODO: because client is to slow to notice the use in time, we reduce it by hand
	-- after we use it / we will have to check that if we also use other things
	-- that are not consumable like mounts, armor
	self:update();
	
	-- TODO: avoid some unclear bug / should be solved if we really clear empty slots
	-- or if we update fast enough?
	if( self.BagId == nil ) then
		cprintf(cli.yellow, "Empty BagId, that should not happen!\n" );
		return 0;
	end

	RoMScript("UseBagItem("..self.BagId..");");

	if (database.consumables[self.Id]) then 	-- is in consumable database? / could be reduced
		self.ItemCount = self.ItemCount - 1;
	end;

	if( settings.profile.options.DEBUG_INV) then	
		cprintf(cli.lightblue, "DEBUG - Use Item BagId: #%s ItemCount: %s\n", self.BagId, self.ItemCount );				-- Open/eqipt item:
	end;

	return self.ItemCount;
end

function CItem:delete()
    RoMScript("PickupBagItem("..self.BagId..");");
	RoMScript("DeleteCursorItem();");
	
	-- Update it!
	self:update();
end 

function CItem:__tonumber()
	return self.Id;
end

function CItem:update()

--	local old_BagId = self.BagId;	-- remember bagId before update
	local itemLink, bagId, icon, name, itemCount = RoMScript("GetBagItemLink(GetBagItemInfo("..self.SlotNumber..")),GetBagItemInfo("..self.SlotNumber..")");
	local id, color;

-- FIX: THERE SEEM TO BE A BUG IN THE ROM CLIENT COMMUNICATION
-- in very rar cases, the client deliver an empty or wrong bagId
-- e.g. if we press a modifier while running the bot in background
-- sometimes slot 1-10 don't have bagid 61-70? I don't know the rule :-(
-- so we can only check missing bagIds, but not wrong bagIds
--	if( old_BagId ~= nil  and				-- not the default value
--		old_BagId ~= 0	  and
--		old_BagId ~= bagId ) then			-- but a wrong value back, so we skip that item update
	if( type(bagId) ~= "number" or			-- no valid bagId return
		bagId < 1	or						-- bag I-VI are from 61-240 / itemshop bag from 1-50 / arcaner transmutor from 51-55
		bagId > 240 ) then
		cprintf(cli.yellow, "Item:update(): empty or wrong bagid return, we don't update slot %s name %s\n", self.SlotNumber, self.Name);
		return;		-- dont' change the values, the new ones are wrong
	end

	if (itemLink == "") then		-- no item in slot
		self = CItem(self.SlotNumber);
		self.BagId = bagId;			-- always there
--		self.ItemCount = 0;			-- 0 if no item at the slot
--		self.Name = "";				
--		self.Id	= 0;
	else
		id, color = self:parseItemLink(itemLink);

		self.Id = id			     -- The real item id
		self.BagId = bagId;          -- GetBagItemLink and other RoM functions need this..
    	self.Name = name;
    	self.Icon = icon;
    	self.ItemCount = itemCount;  -- How many?
    	self.Color = color; 		 -- Rarity
    	self.ItemLink = itemLink     -- Item link, so that you can use it in chat messages
	end

	if( settings.profile.options.DEBUG_INV) then	
		local msg = "DEBUG item:update(): ";
		if(self.SlotNumber) then msg = msg.."slot "..self.SlotNumber; end;
		if(self.BagId) then msg = msg.." bagId "..self.BagId; end;
		if(self.Id) then msg = msg.." Id "..self.Id; end;
--		if(itemLink) then msg = msg.."/"..itemLink; end;
		if(self.Name) then msg = msg.." name "..self.Name; end;
		if(self.ItemCount) then msg = msg.." qty "..self.ItemCount; end;
		cprintf(cli.lightblue, "%s\n", msg);				-- Open/eqipt item:
	end;
	

end

-- Parse from |Hitem:33BF1|h|cff0000ff[eeppine ase]|r|h
-- hmm, i whonder if we could get more information out of it than id, color and name.
function CItem:parseItemLink(itemLink)
	if itemLink == "" or itemLink == nil then
		return;
 	end
 	
	local id = tonumber(string.sub(itemLink, 8, 12), 16);  -- Convert to decimal
	local color = string.sub(itemLink, 19, 24);
	-- this is causing some problems so lets be safe
	local name_parse_from = string.find(itemLink, '[\[]');
	local name_parse_to = string.find(itemLink, '[\]]');
	local name = "Error parsing name";
	if not name_parse_from == nil or not name_parse_to == nil then
		name = string.sub(itemLink, name_parse_from+1, name_parse_to-1);
	end
	return id, color, name;
end

function CItem:getGameTooltip(_place)
-- _place = Left | Right
--
-- here the whole ingame function more clear:
-- ------------------------------------------
--	GameTooltip:SetBagItem(_bagid);
--	local tooltip_right = {};
--	for i=1,40,1 do
--		local lineobj, text = _G["GameTooltipTextRight"..i];
--		
--		if(lineobj) then
--			text = lineobj:GetText();
--			lineobj:SetText("");
--		end;
--		
--		if (text) then
--			table.insert(tooltip_right, text);
--		end;
--	end;
--
--	return tooltip_right;
-- ----------------------------------

	local t = {};
	
	t[1],t[2],t[3],t[4],t[5],t[6],t[7],t[8],t[9],t[10],
	t[11],t[12],t[13],t[14],t[15],t[16],t[17],t[18],t[19],t[20],
	t[21],t[22],t[23],t[24],t[25],t[26],t[27],t[28],t[29],t[30],
	t[31],t[32],t[33],t[34],t[35],t[36],t[37],t[38],t[39],t[40]
	= RoMScript("igf_GetTooltip('Right',"..self.BagId..")");

--cprintf(cli.yellow, "it %s\n", t[1]);
--cprintf(cli.yellow, "it %s\n", t[2]);
--cprintf(cli.yellow, "it %s\n", t[3]);
--cprintf(cli.yellow, "it %s\n", t[4]);
--cprintf(cli.yellow, "it %s\n", t[5]);
--cprintf(cli.yellow, "it %s\n", t[6]);
--
--	local code1 = "GameTooltip:SetBagItem("..self.BagId..");";
--	local code2 = "local t={};for i=1,40,1 do local l,t=_G[\"GameTooltipText".._place.."\"..i];x=l:GetText();l:SetText(\"\");t[i]=x;end;return t;";
--	RoMScript(code1);	-- load the tooltip for the item
--	local tooltip = RoMScript(code2);	-- read the tooltip

	if( t[1]  and
		t[1] ~= false ) then
		return t;
	else
		return false
	end
	
end

-- translate the hex color code into the color string
function CItem:getColorString()

	for i,v in pairs(ITEMCOLOR) do

		if( v == self.Color ) then
			return i;
		end
	end

	return false

end

Code: Select all

include("item.lua");


CInventory = class(
	function (self)
		self.BagSlot = {} 
		for slotNumber = 1, settings.profile.options.INV_MAX_SLOTS, 1 do
			self.BagSlot[slotNumber] = CItem(slotNumber);
		end
		
		self.NextItemToUpdate = 1;
		
	end
)


function CInventory:getAmmunitionCount()
	local count = RoMScript("GetInventoryItemCount('player', 9);");
	if count == nil then
		count = 0;
	end
	return count;
end

 
-- return is true or false. false if there was no ammunition in the bag, type is "thrown" or "arrow"
function CInventory:reloadAmmunition(type) 
	item = self:bestAvailableConsumable(type);
	-- if theres no ammunition, open a ammunition bag
	if not item then
		if type == "arrow" then
			openItem = self:bestAvailableConsumable("arrow_quiver");
		elseif type == "thrown" then
			openItem = self:bestAvailableConsumable("thrown_bag");
		end
		
		if not openItem then
			return false;
		end
		
		openItem:use();
		
		-- after opening, update the inventory (this takes about 10 sec)
		self:update();
		
		item = self:bestAvailableConsumable(type);
	end
	
	if item then
		-- use it
		item:use();
	end
end

function CInventory:getDurability(_slot)
-- return item durability for a given slot in percent from 0 - 100

	if( not _slot) then _slot = 15; end		-- 15=MainHand | 16=OffHand | 10=Ranged

    local durability, durabilityMax = RoMScript("GetInventoryItemDurable('player',".._slot..");");

	-- prevent aritmetic on a nil value if RoMScript failed/wrong values come back
	if( type(durability) ~= "number" or  
		type(durabilityMax) ~= "number" 
		or durabilityMax == 0) then
		return 100;
	end

	return tonumber(durability)/tonumber(durabilityMax)*100;
	
end

function CInventory:getMainHandDurability()
-- return values between 0 - 1 for combatibility reasons

	return inventory:getDurability(15) / 100;		-- 15=Main Hand

end

-- Make a full update
-- or update slot 1 to _maxslot
function CInventory:update(_maxslot)
	if( not _maxslot ) then _maxslot = settings.profile.options.INV_MAX_SLOTS; end;

	printf(language[1000], _maxslot);  -- Updating
	
	keyboardSetDelay(0);
	for slotNumber = 1, _maxslot, 1 do
		self.BagSlot[slotNumber]:update();
		displayProgressBar(slotNumber/_maxslot*100, 50);
	end
	printf("\n");
	keyboardSetDelay(50);
	
	player.InventoryDoUpdate = false;			-- set back update trigger
	player.InventoryLastUpdate = os.time();		-- remember update time

	--cprintf(cli.green, language[1002], settings.profile.options.INV_UPDATE_INTERVAL );	-- inventory update not later then
	
end


-- update x slots until given time in ms is gone
function CInventory:updateSlotsByTime(_ms)
local start_update = getTime();

	keyboardSetDelay(0);
	while ( deltaTime(getTime(), start_update ) < _ms ) do
		self:updateNextSlot();
	end
	keyboardSetDelay(50);

end

-- update x slots
function CInventory:updateNextSlot(_times)

	if(not _times) then _times = 1; end
	
	for i = 1, _times do
		local item = self.BagSlot[self.NextItemToUpdate];

--		if( settings.profile.options.DEBUG_INV) then	
--			local msg = "";
--			msg = "DEBUG updateNextSlot(): Slot #"..self.NextItemToUpdate..": ";
--			if(item.Name) then 
--				msg = msg.." name "..item.Name; 
--			else
--				msg = msg.." name ".." <Slot Empty>"; 
--			end;
--			if(item.ItemCount) then msg = msg.." ItemCount:"..item.ItemCount; end;
--			cprintf(cli.lightblue, "%s\n", msg);				
--		end;

		self.BagSlot[self.NextItemToUpdate]:update();
		self.NextItemToUpdate = self.NextItemToUpdate + 1;
		if (self.NextItemToUpdate > settings.profile.options.INV_MAX_SLOTS) then
			self.NextItemToUpdate = 1;
		end

	end
	
end

-- uses romscript, its 
function CInventory:getItemCount(itemId)
	if(itemId == nil) then
		cprintf(cli.yellow, "Inventory:getItemCount with itemId=nil, please (do not) inform the developers.\n" );	
		return 0;
	end

	itemCount = RoMScript("GetBagItemCount("..itemId..")");
	return tonumber(itemCount);
end

-- uses pre existing information
function CInventory:itemTotalCount(itemNameOrId)
	totalCount = 0;
 	for slot,item in pairs(self.BagSlot) do
	    if item.Id == itemNameOrId or item.Name == itemNameOrId then
			totalCount = totalCount+item.ItemCount;
		end
	end
	return totalCount;
end

function CInventory:useItem(itemNameOrId)
	for slot,item in pairs(self.BagSlot) do
		if item.Id == itemNameOrId or item.Name == itemNameOrId then
			item:use();
			return true, item.Id, item.Name;
		end
	end
	return false
end

-- Returns item name or false, takes in type, example: "healing" or "mana" or "arrow" or "thrown"
function CInventory:bestAvailableConsumable(type)
	local bestLevel = 0;		-- required player level of a potion
	local bestPotency = 0;		-- power of a potion
	local bestItem = false;
	local bestSmallStack = 999;
	local select_strategy;
	local select_strategy_best = "best";
	local select_strategy_minstack = "minstack";
	local select_strategy_default = "best";


	-- set select strategy
	if( type == "mana" ) then
		if( settings.profile.options.USE_MANA_POTION == select_strategy_minstack ) then
			select_strategy = select_strategy_minstack;
		else
			select_strategy = select_strategy_default;
		end
	elseif(type == "healing" ) then
		if( settings.profile.options.USE_HP_POTION == select_strategy_minstack ) then
			select_strategy = select_strategy_minstack;
		else
			select_strategy = select_strategy_default;
		end
	else
		select_strategy = select_strategy_default;	-- default = 'best'
	end


	-- check item slots slot by slot
	for slot,item in pairs(self.BagSlot) do
		local consumable = database.consumables[item.Id];		

		if( consumable  and							-- item in database
		    consumable.Type == type and	 			-- right type (mana, arrow, ...)
		 	consumable.Level <= player.Level and	-- level ok
		 	item.ItemCount > 0 ) then				-- use only if some available

			if( select_strategy == select_strategy_minstack ) then
				-- select smallest stack
				if item.ItemCount < bestSmallStack then
					bestSmallStack = item.ItemCount;
					bestItem = item;
				end
			else	-- select best available consumable (& smallest stack by default)
				-- select better level
				if( consumable.Level > bestLevel  ) then
					bestLevel = consumable.Level;
					bestPotency = consumable.Potency;
					bestSmallStack = item.ItemCount;
					bestItem = item;
				-- same level but select better potency
				elseif( consumable.Level == bestLevel  and
				  		consumable.Potency > bestPotency) then
					bestLevel = consumable.Level;
					bestPotency = consumable.Potency;
					bestSmallStack = item.ItemCount;
					bestItem = item;
				-- same/same but select smaller stack
				elseif( consumable.Level == bestLevel  and
						consumable.Potency == bestPotency  and
						item.ItemCount < bestSmallStack ) then
					bestLevel = consumable.Level;
					bestPotency = consumable.Potency;
					bestSmallStack = item.ItemCount;
					bestItem = item;
				end
			end

		end

	end
	return bestItem;
end

-- Returns item name or false, takes in type, example: "healing" or "mana" or "arraw_quver" or "thrown_bag"
-- quantity is how many of them do we need, for example, for potions its 99 or 198
-- but for arraws it might be 1 or 2
-- type: healing|mana|arrow_quiver|thrown_bag|poison
function CInventory:storeBuyConsumable(type, quantity)
	local bestLevel = 0;
	for storeSlot = 1, 20, 1 do
		local storeItemLink, icon, name, storeItemCost = RoMScript("GetStoreSellItemLink("..storeSlot.."),GetStoreSellItemInfo("..storeSlot..")");

		if (storeItemLink == "" or storeItemLink == nil) then
			break;
		end
		
		storeItemId, storeItemColor, storeItemName = CItem:parseItemLink(storeItemLink);
--		printf("%s %s\n", storeItemId, storeItemName);

		local consumable = database.consumables[storeItemId];

		if( consumable 
		  and consumable.Type == type 
		  and consumable.Level <= player.Level ) then
			if consumable.Level > bestLevel then
				bestLevel = consumable.Level;
				bestItem = storeItemId;
				bestItemSlot = storeSlot;
			end
		end
	end

	if bestLevel == 0 then
	    return false;
 	end

 	
	if self:getItemCount(bestItem) < quantity then
	    numberToBuy = quantity - self:itemTotalCount(bestItem);
	    printf(language[1001]);  -- Shopping
	    for i = 1, numberToBuy, 1 do
	    	RoMScript("StoreBuyItem("..bestItemSlot..")");
	    	printf(".");
		end
		printf("\n");
	end
	
	return true;
end

function CInventory:deleteItemInSlot(slot)
 	self.BagSlot[slot]:delete();
end


function CInventory:autoSell()

	if( settings.profile.options.INV_AUTOSELL_ENABLE ~= true ) then
		return false
	end

	-- warning if not all inventory slots are updated
	if( settings.profile.options.INV_AUTOSELL_TOSLOT > settings.profile.options.INV_MAX_SLOTS ) then
		cprintf(cli.yellow, language[1003], settings.profile.options.INV_MAX_SLOTS, settings.profile.options.INV_AUTOSELL_TOSLOT);
	end
	
	-- warning if igf addon is missing
	if( bot.IgfAddon == false	and
		( settings.profile.options.INV_AUTOSELL_NOSELL_DURA > 0	or
		  settings.profile.options.INV_AUTOSELL_STATS_NOSELL ~= nil ) ) then
		cprintf(cli.yellow, language[1004]);	-- Ingamefunctions addon (igf) is not installed
		 return false;
	end

	-- move color settings into table
	local hf_quality = string.gsub (settings.profile.options.INV_AUTOSELL_QUALITY, "%s*[;,]%s*", "\n");	-- replace ; with linefeed
	local hf_quality_table = explode( hf_quality, "\n" );	-- move colors to table

	local hf_ignore_table;
	-- move ignore list into table
	if( settings.profile.options.INV_AUTOSELL_IGNORE ) then
		local hf_explode = string.gsub (settings.profile.options.INV_AUTOSELL_IGNORE, "%s*[;,]%s*", "\n");	-- replace ; with linefeed
		hf_ignore_table = explode( hf_explode, "\n" );	-- move ignore list
	end

	local hf_stats_nosell;
	-- move ignore stats list into table
	if( settings.profile.options.INV_AUTOSELL_STATS_NOSELL ) then
		local hf_explode = string.gsub (settings.profile.options.INV_AUTOSELL_STATS_NOSELL, "[;,]", "\n");	-- replace ; with linefeed/ no trim
		hf_stats_nosell = explode( hf_explode, "\n" );	-- move ignore list
	end

	local hf_stats_sell;
	-- move ignore stats list into table
	if( settings.profile.options.INV_AUTOSELL_STATS_SELL ) then
		local hf_explode = string.gsub (settings.profile.options.INV_AUTOSELL_STATS_SELL, "[;,]", "\n");	-- replace ; with linefeed/ no trim
		hf_stats_sell = explode( hf_explode, "\n" );	-- move ignore list
	end


	--	ITEMCOLORS table is defined in item.lua
	local function sellColor(_itemcolor)
		
		for i,v in pairs(hf_quality_table) do
		
			if( ITEMCOLOR[string.upper(v)] == _itemcolor ) then
				return true
			end
		end
		
		return false
		
	end

	-- check if itemname or itemid is in the ignorelist
	local function isInIgnorelist(_item)
	
		if ( not hf_ignore_table ) then
			return false
		end
	
		for i,ignorelistitem in pairs(hf_ignore_table) do

			if( string.find( string.lower(_item.Name), string.lower(ignorelistitem), 1, true) or
				_item.ItemId == ignorelistitem ) then
				debugMsg(settings.profile.options.DEBUG_AUTOSELL,
				  "Itemname/id is in ignore list INV_AUTOSELL_IGNORE:", _item.ItemId, _item.Name, "=>", ignorelistitem);
				return true
			end

		end
		
		return false
		
	end
	
	local function isDuraIgnore(_tooltip_right)
		
		local duramax;		-- durability max value (if found)
		local durakey = ITEM_TOOLTIP_DURABILITY[bot.ClientLanguage];	-- keyword to search for
		printf("Lang: %s\n", tostring(bot.ClientLanguage));<---- I added this one
		printf("durakey: %s\n", tostring(durakey) or "nil"); <---- I added this one
		-- read durability from tooltip
		for i,text in pairs(_tooltip_right) do
			for _keyword, _dura, _duramax in string.gfind(text, "("..durakey..")%s*(%d+)/(%d+)") do
				duramax = tonumber(_duramax);
			end
		end

		debugMsg(settings.profile.options.DEBUG_AUTOSELL,
		  "Durability check, search for:", durakey, "=>", duramax);
		
		-- check dura
		if( settings.profile.options.INV_AUTOSELL_NOSELL_DURA 		and
			settings.profile.options.INV_AUTOSELL_NOSELL_DURA > 0	and
			duramax													and
			duramax >= settings.profile.options.INV_AUTOSELL_NOSELL_DURA ) then
			debugMsg(settings.profile.options.DEBUG_AUTOSELL,
			  "Durability check: nosell, durability > then limit =>", duramax, ">",
			    settings.profile.options.INV_AUTOSELL_NOSELL_DURA );
			return true;
		end
		
		return false		
		
	end
	

	local function isInStatsNoSell(_tooltip_right)
		
		if ( not hf_stats_nosell ) then
			return false
		end
	
		for i1,tooltipline in pairs(_tooltip_right) do
			for i2,nosellstat in pairs(hf_stats_nosell) do

				debugMsg(settings.profile.options.DEBUG_AUTOSELL,
				  "Check nosellstat line:", i1, tooltipline, "=>", nosellstat);

				if( string.find( string.lower(tooltipline), string.lower(nosellstat), 1, true)  ) then
					debugMsg(settings.profile.options.DEBUG_AUTOSELL,
					  "Not to sell stat found:", tooltipline);
					return true
				end

			end
		end
		
		return false
		
	end

	local function isInStatsSell(_tooltip_right)
		
		if ( not hf_stats_sell ) then
			return false
		end
	
		for i,tooltipline in pairs(_tooltip_right) do
			for i,sellstat in pairs(hf_stats_sell) do

				if( string.find( string.lower(tooltipline), string.lower(sellstat), 1, true)  ) then
					debugMsg(settings.profile.options.DEBUG_AUTOSELL,
					  "Allways sell stat found:", tooltipline);
					return true
				end

			end
		end
		
		return false
		
	end



	local hf_wesell = false;
	-- check the given slot numbers to autosell
	for slotNumber = settings.profile.options.INV_AUTOSELL_FROMSLOT, settings.profile.options.INV_AUTOSELL_TOSLOT, 1 do
		local sell_item = true
		local slotitem = self.BagSlot[slotNumber];

    	if( slotitem  and  (slotitem.Id or 0) > 0 ) then

			debugMsg(settings.profile.options.DEBUG_AUTOSELL,
			  "Check item so sell:", slotnumber, slotitem.Id, slotitem.Name);

			-- check item quality color
			if( sellColor(slotitem.Color) == false ) then
				debugMsg(settings.profile.options.DEBUG_AUTOSELL,
				  "Itemcolor not in option INV_AUTOSELL_QUALITY:", slotitem:getColorString() );
				sell_item = false;
			end

			-- check itemname against ignore list
			if( isInIgnorelist(slotitem) == true ) then
				sell_item = false;
			end

			-- read tooltip
			local tooltip_right;
			if( bot.IgfAddon == true ) then
				tooltip_right = slotitem:getGameTooltip("right");
				if( tooltip_right == false ) then	-- error while reading tooltip
					cprintf(cli.yellow, "Error reading tooltip for bagslot %s, %s %s\n", 
					 slotitem.SlotNumber, slotitem.Id, slotitem.Name);
					 sell_item = false;
				end
			end

			-- check max durability value
			if( bot.IgfAddon == true	and
				tooltip_right			and
				isDuraIgnore(tooltip_right) == true ) then
				debugMsg(settings.profile.options.DEBUG_AUTOSELL,
				  "Don't sell, durability > INV_AUTOSELL_NOSELL_DURA:", 
				  settings.profile.options.INV_AUTOSELL_NOSELL_DURA );
				sell_item = false;
			end

			-- check if stats / text strings are on the ingnore list
			if( bot.IgfAddon == true	and
				tooltip_right			and
				isInStatsNoSell(tooltip_right) == true ) then

				-- check if in sell always stats
				if( isInStatsSell(tooltip_right) == true ) then
					-- don't change the sell flag
				else
					sell_item = false;
				end

			end

			-- sell the item
			if( sell_item == true ) then
				hf_wesell = true;
				slotitem:use();
			end
			
		end		-- end of: if( slotitem  and  slotitem.Id > 0 )

	end
	
	if( hf_wesell == true ) then
		return true;
	else
		return false;
	end
	
end

function CInventory:getMount()
	-- Id of all mounts (except 15 minute, and 2 hour mounts)
    mounts = {
	203559,203556,203553,203568,203565,204942,204943,204941,204988,204987,202227,
	202230,202217,203297,203320,202229,202232,202226,203299,203322,204997,204998,
	204999,205748,205749,204279,204278,204277,204281,204280,203573,202452,202450,
	201966,203301,203324,202481,202473,202465,203309,203332,203288,203286,203290,
	203318,203341,204292,204293,204276,204295,204294,203571,201698,202246,202248,
	203296,203319,202479,202471,202463,203307,203330,202486,202478,202470,203314,
	203337,202480,202472,202464,203308,203331,204954,204955,204953,204994,204993,
	202461,202458,201927,203305,203328,204144,204142,204146,204148,204150,202484,
	202476,202468,203312,203335,204936,204937,204935,204984,204983,202482,202474,
	202466,203310,203333,204963,204964,204962,204972,204971,203287,203285,203289,
	203317,203340,204960,204961,204959,204948,204947,204939,204940,204938,204986,
	204985,203913,203914,203915,203968,203970,204286,204285,204287,204291,204290,
	202228,202231,202218,203298,203321,203669,203670,203671,203672,203673,204945,
	204946,204944,204990,204989,202456,202455,202454,203303,203326,202483,202475,
	202467,203311,203334,204930,204931,204929,204978,204977,204145,204143,204147,
	204149,204151,202485,202477,202469,203313,203336,202933,202931,202935,203315,
	203338,204933,204934,204932,204982,204979,203560,203557,203554,203569,203566,
	204084,204083,204085,202821,204072,202460,202457,201130,203304,203327,204951,
	204952,204950,204992,204991,202462,202459,201928,203306,203329,203674,203675,
	203676,203677,203678,203561,203558,203555,203570,203567,203572,202245,202095,
	202247,203300,203323,204969,204970,204968,204976,204975,202453,202451,201965,
	203302,203325,203562,203563,203564,203969,203971,204283,204282,204284,204289,
	204288,204966,204967,204965,204974,204973,202934,202932,202936,203316,203339,
	204957,204958,204956,204996,204995,201468 };

	print(self);
 	for slot,item in pairs(self.BagSlot) do
	    for i, mount in pairs(mounts) do
			if item.Id == mount then
				return item;
			end
		end
	end
	
	return false;
end
And this is my previous items.lua and inventory.lua

(line 388 inventory.lua)

Code: Select all

local duramax;		-- durability max value (if found)
local durakey = ITEM_TOOLTIP_DURABILITY[bot.ClientLanguage];	-- keyword to search for
printf("Lang: %s\n", tostring(bot.ClientLanguage));
printf("durakey: %s\n", tostring(durakey) or "nil");
edit: where i can get the latest addresses.lua i downloaded the MM last week, Is the MM that i dowlnoad was already outdated?
User avatar
Administrator
Site Admin
Posts: 5353
Joined: Sat Jan 05, 2008 4:21 pm

Re: need help sir about autosell

#6 Post by Administrator »

Code: Select all

   DE      = "Haltbarkeit",
   FR      = "Structure",
   ENEU   = "Durability",
   ENUS   = "Durability"
        PH = "Durability"
You're missing a comma after the entry for ENUS.
ggsir
Posts: 5
Joined: Mon Feb 15, 2010 11:42 pm

Re: need help sir about autosell

#7 Post by ggsir »

wow im very thankful to you sir..just a simple comma can solve my problem... thank you very much and godbless sir admin more power!
ggsir
Posts: 5
Joined: Mon Feb 15, 2010 11:42 pm

Re: need help sir about autosell

#8 Post by ggsir »

another problem, is it normal that sometimes the bot can't find the NPC that i chose?
User avatar
Administrator
Site Admin
Posts: 5353
Joined: Sat Jan 05, 2008 4:21 pm

Re: need help sir about autosell

#9 Post by Administrator »

ggsir wrote:another problem, is it normal that sometimes the bot can't find the NPC that i chose?
Yes. It happens sometimes.
Post Reply