Page 1 of 1

Item Check for Dailyquests

Posted: Wed Aug 19, 2009 1:42 am
by TheRedVex
Can the bot handle a itemcheck? Where i have to include it?

I want to write a Waypointfile for the Dailyquests and so i need the item check for the Fungi or whe Wolfs at the Pioneers.
Would be nice if you could help me.

Re: Item Check for Dailyquests

Posted: Wed Aug 19, 2009 2:17 am
by Administrator
Not at this time, no. Someone would need to find static pointers to inventory slots first. I actually haven't bothered doing this myself, so I'm not sure how it is structured.

Re: Item Check for Dailyquests

Posted: Mon Aug 31, 2009 2:22 am
by TheRedVex
okay i have writen a working ItemInventoryscan where u can search the inventory for a itemid.
Now is my question can i write an Fightvariable for each mob?

like

Code: Select all

fights.fungi
fights.wolfs
...
it would be better to do it with each own Variable for the Dailyquests and itemscan.

TheRedVex

Re: Item Check for Dailyquests

Posted: Mon Aug 31, 2009 2:49 am
by droppen
TheRedVex wrote:okay i have writen a working ItemInventoryscan where u can search the inventory for a itemid.
Now is my question can i write an Fightvariable for each mob?

like

Code: Select all

fights.fungi
fights.wolfs
...
it would be better to do it with each own Variable for the Dailyquests and itemscan.

TheRedVex
care to share the code?

Re: Item Check for Dailyquests

Posted: Mon Aug 31, 2009 2:57 am
by TheRedVex
droppen wrote:
TheRedVex wrote:okay i have writen a working ItemInventoryscan where u can search the inventory for a itemid.
Now is my question can i write an Fightvariable for each mob?

like

Code: Select all

fights.fungi
fights.wolfs
...
it would be better to do it with each own Variable for the Dailyquests and itemscan.

TheRedVex
care to share the code?
if the codes with fungi and wolfs ... are find out i would like to share it yes

Re: Item Check for Dailyquests

Posted: Mon Aug 31, 2009 4:44 am
by TheRedVex
okay i´ve got it. here is my Code



this is the advanced killingfunction

add this to the pawn.lua like this

Code: Select all

CPawn = class(function (self, ptr)
		self.Address = ptr;
		self.Name = "<UNKNOWN>";
		self.Id = 0;
		self.Type = PT_NONE;
		self.Guild = "<UNKNOWN>";
		self.Level = 1;
		self.Level2 = 1;
		self.HP = 1000;
		self.MaxHP = 1000;
		self.MP = 1000;
		self.MaxMP = 1000;
		self.MP2 = 1000;
		self.MaxMP2 = 1000;
		self.X = 0.0;
		self.Y = 0.0;
		self.Z = 0.0;
		self.TargetPtr = 0;
		self.Direction = 0.0;
		self.Attackable = false;
		self.Alive = true;


		-- Directed more at player, but may be changed later.
		self.Battling = false; -- The actual "in combat" flag.
		self.Fighting = false; -- Internal use, does not depend on the client's battle flag
		self.Casting = false;
		self.Mana = 0;
		self.MaxMana = 0;
		self.Rage = 0;
		self.MaxRage = 0;
		self.Energy = 0;
		self.MaxEnergy = 0;
		self.Concentration = 0;
		self.MaxConcentration = 0;
		self.PotionLastUseTime = 0;
		self.Returning = false;		-- Whether following the return path, or regular waypoints
		self.BotStartTime = os.time(); -- Records when the bot was started.
		self.BotStartTime_nr = 0; -- Records when the bot was started, will not return at pause
		self.Unstick_counter = 0;	-- counts unstick tries, resets if waypoint reached
		self.Success_waypoints = 0; -- count consecutively successfull reached waypoints 
		self.Cast_to_target = 0;	-- count casts to our enemy target
		self.LastAggroTimout = 0;	-- remeber last time we wait in vain for an aggro mob
		self.Sleeping = false;		-- sleep mode with fight back if attacked
		self.Sleeping_time = 0;		-- counts the sleeping time
		self.Fights = 0;			-- counts the fights
		self.Death_counter = 0;		-- counts deaths / automatic reanimation
		self.MP_counter = 0;		-- counts use of mana potions
		self.HP_counter = 0;		-- counts use of HP potions
		self.Current_waypoint_type = WPT_NORMAL;	-- remember current waypoint type global
		self.Last_ignore_target_ptr = 0;		-- last target to ignore
		self.Last_ignore_target_time = 0;		-- last target to ignore
		self.lastHitTime = 0;				-- last time the HP of the target changed
		self.ranged_pull = false;			-- ranged pull phase active
		self.free_field1 = nil;				-- free field for user use
		self.free_field2 = nil;				-- free field for user use
		self.free_field3 = nil;				-- free field for user use
		self.free_counter1 = 0;				-- free counter for user use
		self.free_counter2 = 0;				-- free counter for user use
		self.free_counter3 = 0;				-- free counter for user use		
		self.free_flag1 = false;			-- free flag for user use
		self.free_flag2 = false;			-- free flag for user use
		self.free_flag3 = false;			-- free flag for user use
		
		------------------ New attach for specific Mobkilling --------------------------
		--------------------------------------------------------------------------------
		
		self.mobs = {};
		
		--------------------------------------------------------------------------------
		--------------------------------------------------------------------------------

		
		if( self.Address ~= 0 and self.Address ~= nil ) then self:update(); end
	end
);
and then add this to the end of the fightfunction of player.lua

Code: Select all

------------------ New attach for specific Mobkilling --------------------------
	--------------------------------------------------------------------------------
	local mobid = string.format("%s",target.Name);
	if(self.mobs[mobid] == nil) then
		self.mobs[mobid] = 0
	end
	self.mobs[mobid] = self.mobs[mobid] + 1
	cprintf(cli.lightblue, "%s kills : %s\n",mobid,self.mobs[mobid]);
	
	--------------------------------------------------------------------------------
	--------------------------------------------------------------------------------
	
	self.Fighting = false;
	self:clearTarget();
and comment the clearTarget line under Self:loot();

add this to the end of the Player.lua

Code: Select all

function CPlayer:ScanForItem(itemid)
	local item;
	local anzahl;
	local slot;
	local gesamt = 0;
	for i=0, 29 do
		slot = i + 1
		item = memoryReadInt(getProc(), Inv[i]);
		if(item == itemid) then
			anzahl = memoryReadInt(getProc(), Anzahl[i]);
			gesamt = anzahl + gesamt
			cprintf(cli.yellow,"Slot %s: %sx %s\n",slot,anzahl,item);
		end
		
	end
	if(gesamt >=1) then
		cprintf(cli.yellow,"Gesamt %s: %sx\n",itemid,gesamt);
		return gesamt
	else
		return 0
	end
end
add this to the adresses.lua

Code: Select all

Inv = {
	[0] = 0x008EEB78,
	[1] = 0x008EEB38,
	[2] = 0x008EED58,
	[3] = 0x008EEAB0,
	[4] = 0x008EE7C0,
	[5] = 0x008EEAF0,
	[6] = 0x008EE5E4,
	[7] = 0x008EE9E0,
	[8] = 0x008EE5A0,
	[9] = 0x008EE804,
	[10] = 0x008EE848,
	[11] = 0x008EE890,
	[12] = 0x008EE8D0,
	[13] = 0x008EE918,
	[14] = 0x008EE958,
	[15] = 0x008EE9A0,
	[16] = 0x008EE628,
	[17] = 0x008EEA28,
	[18] = 0x008EEA68,
	[19] = 0x008EE670,
	[20] = 0x008EE6B0,
	[21] = 0x008EE6F8,
	[22] = 0x008EE738,
	[23] = 0x008EEBC0,
	[24] = 0x008EEC00,
	[25] = 0x008EEC48,
	[26] = 0x008EEC88,
	[27] = 0x008EECD0,
	[28] = 0x008EED10,
	[29] = 0x008EE780,
};
Anzahl = {
	[0] = 0x008EEB88,
	[1] = 0x008EEB44,
	[2] = 0x008EED64,
	[3] = 0x008EEABC,
	[4] = 0x008EE5F4,
	[5] = 0x008EEB00,
	[6] = 0x008EE5F4,
	[7] = 0x008EE9F0,
	[8] = 0x008EE5B0,
	[9] = 0x008EE814,
	[10] = 0x008EE858,
	[11] = 0x008EE89C,
	[12] = 0x008EE8E0,
	[13] = 0x008EE924,
	[14] = 0x008EE968,
	[15] = 0x008EE9AC,
	[16] = 0x008EE638,
	[17] = 0x008EEA34,
	[18] = 0x008EEA78,
	[19] = 0x008EE67C,
	[20] = 0x008EE6C0,
	[21] = 0x008EE704,
	[22] = 0x008EE748,
	[23] = 0x008EEBCC,
	[24] = 0x008EEC10,
	[25] = 0x008EEC54,
	[26] = 0x008EEC98,
	[27] = 0x008EECDC,
	[28] = 0x008EED20,
	[29] = 0x008EE78C,
};
you will not die if you thank me for that.

Re: Item Check for Dailyquests

Posted: Mon Aug 31, 2009 5:48 am
by droppen
Wow! nice coding there! The item checking is now possible though too. I made this function for you

Code: Select all

function countItemTotal(itemName)
	local itemTotal = 0;
	for i = 1, 60, 1 do
		local bagid, icon, name, itemCount = RoMScript("GetBagItemInfo("..i..");");
		if (itemName == name) then
			itemTotal = itemTotal + itemCount;
		end
	end
	return itemTotal;
end
Usage:

Code: Select all

countItemTotal("Barbarian Herbs")
it returns the total number of any one item in your backpack.


Thanks for the address list!

Re: Item Check for Dailyquests

Posted: Mon Aug 31, 2009 6:05 am
by TheRedVex
ive got it allready

but the adresslist is only for the first 30 inventarslots

Code: Select all

function CPlayer:ScanForItem(itemid)
   local item;
   local anzahl;
   local slot;
   local gesamt = 0;
   for i=0, 29 do
      slot = i + 1
      item = memoryReadInt(getProc(), Inv[i]);
      if(item == itemid) then
         anzahl = memoryReadInt(getProc(), Anzahl[i]);
         gesamt = anzahl + gesamt
         cprintf(cli.yellow,"Slot %s: %sx %s\n",slot,anzahl,item);
      end
      
   end
   if(gesamt >=1) then
      cprintf(cli.yellow,"Gesamt %s: %sx\n",itemid,gesamt);
      return gesamt
   else
      return 0
   end
end
there u add the itemid

EDIT: CODE tag added.

Re: Item Check for Dailyquests

Posted: Mon Aug 31, 2009 6:16 am
by droppen
Yep, impressive.

Re: Item Check for Dailyquests

Posted: Tue Sep 01, 2009 8:07 am
by master121
ItemCount function doesn´t work
Tried this :

Code: Select all

for k = 1, 60 , 1 do
    local bagid, icon, name, itemCount = RoMScript("GetBagItemInfo(k);");
end
MicroMacro writes this into the RoM macro :: a={GetBagItemInfo(k);}
So the coders must find a way to write what the variable holds instead of writing the variable name.

Re: Item Check for Dailyquests

Posted: Tue Sep 01, 2009 8:15 am
by Administrator
master121 wrote:ItemCount function doesn´t work
Tried this :

Code: Select all

for k = 1, 60 , 1 do
    local bagid, icon, name, itemCount = RoMScript("GetBagItemInfo(k);");
end
MicroMacro writes this into the RoM macro :: a={GetBagItemInfo(k);}
So the coders must find a way to write what the variable holds instead of writing the variable name.
String concatenation.

Code: Select all

    local bagid, icon, name, itemCount = RoMScript("GetBagItemInfo(" .. k .. ");");

Re: Item Check for Dailyquests

Posted: Tue Sep 01, 2009 9:54 am
by master121
I get this error:
functions.lua:371 bad argument #1 to 'char' (invalid value)

Re: Item Check for Dailyquests

Posted: Tue Sep 01, 2009 10:12 am
by Administrator
Debug it by placing a print statement right above that line. What is the value of 'byte' when it gives that error?

Re: Item Check for Dailyquests

Posted: Tue Sep 01, 2009 10:15 am
by master121

Code: Select all

for k = 1, 60, 1 do
    local bagid, icon, name, itemCount = RoMScript("GetBagItemInfo(" .. k .. ");");
end
With loop :
byte = plenty of numbers with a negative number at the end
Without loop
byte = plenty of numbers WITHOUT a negative number at the end

// So it has to do something with the negative number and the loop ... but what ?
readsz = readsz .. string.char(byte); causes the error

Code: Select all

string.char(i1, i2, ...)

Generate a string representing the character codes passed as arguments. Numerical codes are not necessarily portable across platforms.

    > = string.char(65,66,67)
    ABC
    > = string.char()  -- empty string
So i think in the function you shouldn´t use negative numbers.

// But why is there a negativ number ?

Re: Item Check for Dailyquests

Posted: Tue Sep 01, 2009 3:12 pm
by Administrator
What exactly is the negitive number that it dies on? What is the number directly before it?

I assume it's a problem with signed vs. unsigned on line 356. Change memoryReadByte() to memoryReadUByte() and see if that works.

Re: Item Check for Dailyquests

Posted: Wed Sep 02, 2009 6:54 am
by master121
It works with memoryReadUByte()
Thanks champ ;)

Re: Item Check for Dailyquests

Posted: Sat Sep 05, 2009 4:59 pm
by d003232
TheRedVex wrote:this is the advanced killingfunction

add this to the pawn.lua like this

Code: Select all

CPawn = class(function (self, ptr)
...		
		------------------ New attach for specific Mobkilling --------------------------
		--------------------------------------------------------------------------------
		
		self.mobs = {};
		
		--------------------------------------------------------------------------------
		--------------------------------------------------------------------------------

		
		if( self.Address ~= 0 and self.Address ~= nil ) then self:update(); end
	end
);
I added the player.mobs array to SVN 213. Kills will now be counted per target name.

@TheRedVex: THX for your help and suggestions.