Page 10 of 11

Re: New EggPet class.

Posted: Tue Aug 23, 2011 10:56 pm
by Dsanchez
no, this was with RBAssist.xml and pretty sure last time was with a normal waypoint file.

Code: Select all

	<onSkillCast><![CDATA[
		-- 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
		-- e.g.:

--	if( 50 > player.HP/player.MaxHP*100 ) then
--		if player.Class1 == CLASS_PRIEST then
--			player:cast("PRIEST_SOUL_SOURCE");
--			player:cast("PRIEST_URGENT_HEAL");
--		end
--		if player.Class2 == CLASS_PRIEST then
--			player:cast("PRIEST_HOLY_AURA");
--			player:cast("PRIEST_URGENT_HEAL");
--			player:cast("PRIEST_URGENT_HEAL");
--		end
--	elseif( 75 > player.HP/player.MaxHP*100 ) then
--		if player.Class1 == CLASS_PRIEST then
--			player:cast("PRIEST_HOLY_AURA");
--			player:cast("PRIEST_URGENT_HEAL");
--		end
--		if player.Class2 == CLASS_PRIEST then
--			player:cast("PRIEST_URGENT_HEAL");
--		end
--	end;
	]]></onSkillCast>

Re: New EggPet class.

Posted: Wed Aug 24, 2011 12:43 am
by rock5
Ah no wonder. RBAssist is not a normal waypoint file. It has no waypoints but instead does everything manually in the onLoad section. A lot of the things I've been checking don't apply to it. It has no death checks as it doesn't need it, because if you are playing manually with it, and die, you can rez yourself.

As to it happening previously with a normal file, that's another issue. Hopefully it was fixed with that death check I added to the pet summoning function. If you have furthure problems with normal files then let us know.

Re: New EggPet class.

Posted: Wed Aug 24, 2011 6:22 am
by Dsanchez
kk, i'll let you know if it happens again. looks like the eggpet editions have fixed it.


thanks!

Re-summoning pet fail because the bot doesn't stop moving

Posted: Fri Dec 09, 2011 2:29 am
by kkulesza
revison 680 (i know there is 681 but i havent seen any changes to Eggpet class)

Feeding and summoning a pet works great at beginning.

But after i run a long time in the same location pet is getting hungry.
Then the bot feeds it and tries to summon but cast is interrupted because bot keeps moving.

Bot is running and summoning in an endless loop.

Re: New EggPet class.

Posted: Fri Dec 09, 2011 3:02 am
by lisa
What is the bot trying to do at the time?
Is it trying to get somewhere?
Or is it supposed to be staying still the entire time?

Re: New EggPet class.

Posted: Fri Dec 09, 2011 11:56 am
by kkulesza
lisa wrote:What is the bot trying to do at the time?
Is it trying to get somewhere?
Or is it supposed to be staying still the entire time?
Bot is supposed to run and fight mobs (it is waypoint type activity - not wander type).

It used to be working with earlier revisions.
Bot stoped running feeded and resummoned pet and then started to move again.
But now it doesn't stop running.

Re: New EggPet class.

Posted: Fri Dec 09, 2011 9:01 pm
by rock5
kkulesza wrote:But after i run a long time in the same location pet is getting hungry.
Then the bot feeds it and tries to summon but cast is interrupted because bot keeps moving.
That sounds like maybe after awhile the game slows down a bit and it takes longer than 500ms to start summoning the pet. If so then it wont wait for it to finish summoning.

Try this. Around line 216 of eggpet.lua you will find the summon function

Code: Select all

function CEggPet:Summon()
	self:update()
	while self.EggId > 0 and self.Summoned == false and player.Alive and player.HP > 0 do
		RoMScript("SummonPet("..self.EggSlot..")")
		repeat
Add a 'yrest' just before the 'repeat' of about 500ms.

Code: Select all

function CEggPet:Summon()
	self:update()
	while self.EggId > 0 and self.Summoned == false and player.Alive and player.HP > 0 do
		RoMScript("SummonPet("..self.EggSlot..")")
		yrest(500)
		repeat
Then it will wait a full second before the first time it checks for the casting bar. See if that helps.

Re: New EggPet class.

Posted: Sat Dec 10, 2011 1:54 am
by kkulesza
rock5 wrote: Add a 'yrest' just before the 'repeat' of about 500ms.

Code: Select all

function CEggPet:Summon()
	self:update()
	while self.EggId > 0 and self.Summoned == false and player.Alive and player.HP > 0 do
		RoMScript("SummonPet("..self.EggSlot..")")
		yrest(500)
		repeat
It worked for the first resummoning but it didn't for the second time.
So I've added another yrest() before SummonPet() command to make sure that bot stops before casting:

Code: Select all

while self.EggId > 0 and self.Summoned == false and player.Alive and player.HP > 0 do
		yrest(500);
		RoMScript("SummonPet("..self.EggSlot..")")
		yrest(500);
		repeat
Now it works :)
Thx for help

---UPDATE:
After an hour the problem is back :(
yrest() functions are working because now there 1 second pause betwin casts.
But the bot still runs forward like there was "W" key pressed.
I'll try to insert two commands:

Code: Select all

	while self.EggId > 0 and self.Summoned == false and player.Alive and player.HP > 0 do
		keyboardRelease(key.VK_W);
		RoMScript("MoveForwardStop()");
		yrest(500);
		RoMScript("SummonPet("..self.EggSlot..")")
		yrest(500);
		repeat
I hope it will work

Re: New EggPet class.

Posted: Sat Dec 10, 2011 5:00 am
by rock5
That might be asolution but if some code is pressing W then it might not work because it will keep pressing W. It's strange that it's doing that. I'll think some more on it. Let us know if it worked.

Re: New EggPet class.

Posted: Sat Dec 10, 2011 5:11 am
by rock5
I been thinking, if it actuallly stops then starts moving again after that 1 second while it's casting, there can only really be 2 reasons I can thinks of.

1. There is something wrong with your rombot installation and it doesn't see that you are casting, ie. player.Casting is coming up false instead of true.

or
2. In that loop when it does 'yrest(500)' it yeilds to some timer event that presses "w". Do you have any userfunctions that registers timers?

Re: New EggPet class.

Posted: Sat Dec 10, 2011 11:48 am
by kkulesza

Code: Select all

	while self.EggId > 0 and self.Summoned == false and player.Alive and player.HP > 0 do
		keyboardRelease(key.VK_W);
		--RoMScript("MoveForwardStop()");
		--yrest(500);
		RoMScript("SummonPet("..self.EggSlot..")")
		--yrest(500);
		repeat
This code works. Bot did work for several hours.

Re: New EggPet class.

Posted: Sat Dec 10, 2011 2:13 pm
by rock5
That supports the idea that the 'yrest' was yeilding to something that was making it move. With it commented out do you still need to do the 'keyboardRelease'? Of couse there should still be a pause in the loop. If you change the yrest(500) to rest(500) it will pause without yeilding. That should fix the problem.

The question remains, though, what code is causing problems when it yields? Usually the only registeredtimer is the one used to attack during melee combat. Lisa's popular GMMonitor userfunction uses registertimer but it doesn't press any keys or do movements. If you have a way of doing searches for text in folders (I use FileSeek and recommend it) you could do a search in the 'userfunctions' or 'waypoints' folder for 'registertimer'. That might tell you which file is causing problems.

Re: New EggPet class.

Posted: Sat Dec 10, 2011 6:06 pm
by kkulesza
rock5 wrote:That supports the idea that the 'yrest' was yeilding to something that was making it move. With it commented out do you still need to do the 'keyboardRelease'?
Yes i need to do keyRelease
rock5 wrote:Of couse there should still be a pause in the loop. If you change the yrest(500) to rest(500) it will pause without yeilding. That should fix the problem.
I'll try it this next time

---UPDATE:
rest() did work few times (3 resummoning succesful), but failed later.
I guess i'll stay with keyRelease() because it worked for all night.
-------------
rock5 wrote: If you have a way of doing searches for text in folders (I use FileSeek and recommend it) you could do a search in the 'userfunctions' or 'waypoints' folder for 'registertimer'. That might tell you which file is causing problems.
I have 2 userfunctions with registertimer (both downloaded from this forum):
-userfunction_MountSpeedHack.lua
-userfunction_setwindow.lua
I do not call their functions though. So i doubt it's their fault.
Also i do not use registertimer at all in my waypoints.

Re: New EggPet class.

Posted: Mon Jun 04, 2012 5:06 pm
by BillDoorNZ
Been fiddling with automating egg merging and managed to get a couple of things going (in case anyone is interested).

Code: Select all

-- _reagent is the index of the pet you want to merge into this egg.
function CEggPet:merge(_reagent)
	local max, count = RoMScript("GetPetMixDayMergeCount("..tostring(self.EggSlot)..")");
	--printf(tostring(count).."/"..tostring(max).." merges\n");
	if (count >= max) then
		printf("Maximum number of merges has been reached");
	end;
	
	RoMScript("/run PET_MIX_SELECT_ID1="..tostring(self.EggSlot).."; PET_MIX_SELECT_ID2="..tostring(_reagent).."; SetPetMix(PET_MIX_SELECT_ID1, PET_MIX_SELECT_ID2, 0)");
	self:update();
end

-- _eggSlot is the slot you wish to extract the egg to
-- _item is the inventory item that is the pet egg you wish to extract (I haven't gotten to the point yet where I can easily find items that are eggs and that are the level I want etc)
function ExtractNewEgg(_eggSlot, _item)
	if (_item == nil) then
		printf("No egg item was specified. Cannot Extract the egg.\n");
		return;
	end;
	
	if (_eggSlot == nil) then
		printf("You must specify an egg slot into which to extract the new egg.\n");
		return;
	end;
	
	local inUse = RoMScript("HasPetItem("..tostring(_eggSlot)..")");
	
	if (inUse) then
		printf("The pet slot is already in use\n");
		return;
	end;

	_item:use();
	
	RoMScript("SetPetItem("..tostring(_eggSlot)..")");
end;

Re: New EggPet class.

Posted: Tue Jun 05, 2012 2:04 am
by rock5
Well there are people interrested in doing this so it would be worth adding to the bot.

Observations:
1. This is supposed to stop here. So there should be a 'return' after the print message.

Code: Select all

   if (count >= max) then
      printf("Maximum number of merges has been reached");
   end;
2. I don't think you need that "/run".
3. You shouldn't need to convert numbers to strings. Lua is good at handling that.
4. It could probably do with a few extra checks such as; is the 'agent' and 'reagent' egg the same, is the 'reagent' egg level lower or equal to the 'agent' egg, is the egg slot you are trying to extract the egg to open, are they the same element? Most of this information can be gotten using the eggpet class eg.

Code: Select all

egg1 = CEggPet(1)
egg2= CEggPet(2)
Hmm... There's nothing indicating if the slot is available. Don't know why I never added that. There must be some indicator.
5. From what I understand about pet merging (I was never into it myself) you really do need to know info about the eggs in your inventory. I'll see if I can whip up an eggitem class. I'll try to keep it simple.

Re: New EggPet class.

Posted: Tue Jun 05, 2012 4:51 am
by BillDoorNZ
cheers rock,

there is an api call to check if a slot is free - will dig it up in the morning...no, its: HasPetItem(index)

the /run is required - not sure why - if i dont use it, it fails...hmm...having said that, that may have been to a previous issue - will test in the AM.

I thought i'd post that code as a WIP rather than polish it any further in case someone had already done some work in that area - no point reinventing the wheel.

Re: New EggPet class.

Posted: Tue Jun 05, 2012 5:27 am
by rock5
BillDoorNZ wrote:there is an api call to check if a slot is free - will dig it up in the morning...no, its: HasPetItem(index)
I saw that. I thought that was just to check if there was a pet in the slot, not if the slot is available ie. rented.

I found the slot availablity in memory so I'll add it to the eggpet class. It just accured to me to also include if the slot is empty like the item class uses. You can just check whether the EggId == 0 but 'Empty' is handy. So you could do something like

Code: Select all

egg1 = CEggPet(1)
if egg1.Empty and egg1.Available then
   ... Extract egg to it.
end
Here's a simple class for pet eggs in the inventory. I made it a userfunction file for ease of testing.
userfunction_petegg.lua
(778 Bytes) Downloaded 94 times
To use it just find the egg in the inventory. Probably the best way is by Id, there are only so many of them. So lets call the item you found 'item'. You would then go

Code: Select all

egg = CPetEgg(item.Address)
'egg' will then have the following information

Code: Select all

Id -- The Id of the egg
Name -- The name of the egg eg. Holy Pet Egg
PetId -- The id of the creature it creates
PetName -- The name of the creature it creates
Element -- The pets element (-1=none, 0=Earth, 1=Water, 2=Fire, 3=Wind, 4=Light, 5=Dark)
Level 
Aptitude
I've added some constants for the elements so you can do

Code: Select all

if egg.Element == ELEMENT_FIRE then
I'm not sure of the best way to incorporate this into the bot but probably "ExtractNewEgg" should be a function of this class, eg. after you found your egg

Code: Select all

egg:extract(slot)
Or maybe you could have it search for an empty slot to extract to.

Re: New EggPet class.

Posted: Tue Jun 05, 2012 2:01 pm
by BillDoorNZ
nice work dude..appreciate it :)

I'll have a fiddle with it all and think more about it too and come back with any suggestions :)

Re: New EggPet class.

Posted: Tue Jun 05, 2012 7:10 pm
by BillDoorNZ
I've updated the userfunction as attached. It includes an extension for CEggPet:merge(_reagent) (where reagent is a CEggPet too). Not 100% sure as yet that its a good way to do it. There are also a couple of YRests in there just in case :)

Below is the code I used to get it to automerge (my main pet is in slot 1).

Code: Select all

local slotToUse = 2;
local mainPet = CEggPet(1);

for i=1, inventory.MaxSlots, 1 do
	local item = inventory.BagSlot[i];
	local itemName = string.lower(item.Name);
	if (string.find(itemName, ".*pet egg")) then
		printf("Found a pet egg at slot "..i.." called "..item.Name.."\n");
		local egg = CPetEgg(item);
		if (egg) then
			local reagentPet = egg:extract(slotToUse);
			
			if (mainPet and reagentPet) then
				mainPet:merge(reagentPet);
			end;
		end;
	end;
end;

Re: New EggPet class.

Posted: Tue Jun 05, 2012 7:13 pm
by BillDoorNZ
I should probably have checked the element in that loop too!!! ah well :)