Thoughts about harvesting non-resource objects

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Thoughts about harvesting non-resource objects

#1 Post by rock5 »

As I mess around with the new harvest function to get it to work harvesting the objects I want, a few thoughts have come to me.

1. Using objects is more like targeting npcs than it is harvesting. It's like targeting npcs because, you want to target both by name, you usually only want it to click once and you don't want it to do any checks because all objects react differently. So I think you will eventually have 1 function that can be used to target npcs and non-resource objects.
2. If an object takes time to use, you could always add a yrest.
3. It would be good if the function return true if it found the object or false if not so you could do something like this if you want to collect more than one item in the area.

Code: Select all

while collectfunction("itemname") then
    yrest(waittime); -- The time it needs to harvest.
end
This way it will continue on when there are no more items to collect and only waits if it finds the item.
4. Actually an even better idea, I think, is to have an optional wait time included in the function eg. collectfunction("itemname",waittime)

What do you think?
  • 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
Administrator
Site Admin
Posts: 5353
Joined: Sat Jan 05, 2008 4:21 pm

Re: Thoughts about harvesting non-resource objects

#2 Post by Administrator »

Sounds good to me. Most of the code could be copied from CPlayer:harvest() (obviously), but I don't think the harvest function would be able to use this general function due to how it has to ignore the last used node and whatnot (so it doesn't try to re-harvest the node that you just finished which is now fading out).

Would be even better if we could find the offset for the use flag instead of just timing it ourselves. I just hope that each type of usable object doesn't use different flags. Are we sure that the current harvesting check will not work?
User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Thoughts about harvesting non-resource objects

#3 Post by rock5 »

Administrator wrote:Sounds good to me. Most of the code could be copied from CPlayer:harvest() (obviously), but I don't think the harvest function would be able to use this general function due to how it has to ignore the last used node and whatnot (so it doesn't try to re-harvest the node that you just finished which is now fading out).
That's what I think, 1 function for harvesting wood, herbs and ore and 1 function for targeting npcs and other objects.
Administrator wrote:Would be even better if we could find the offset for the use flag instead of just timing it ourselves. I just hope that each type of usable object doesn't use different flags. Are we sure that the current harvesting check will not work?
Yes, it seems to ignore the "while( self.Harvesting )" section and just waits the 3000 ms in the "while( not self.Harvesting )" section.

The problem with finding the offset is if you are going to use the same function for npcs, npcs open instantly and so do a lot of objects you might target like mailboxes and bulletin boards. So all that extra work would only be put to use occasionally. Still, if there is only 1 offset to find, it might be worth it.
  • 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
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Thoughts about harvesting non-resource objects

#4 Post by rock5 »

I've been doing some more thinking about all the targeting functions and how they are similar.

1. targeting npcs -
get objectlist
search object list for name
target address
attack

2. target object -
get objectlist
search object list for name
target address
attack
optionally wait for collect time.

3. harvesting -
get objectlist
Search for nearest id that matches node db.
target address
attack
wait for self.harvesting = false
search for next node ignoring current.

Conclusions:
Because the body of 3. is so different it would have to be a totally different function. 1. and 2. are so similar they could be the same function or based on the same function. I can't think of a good name that would suite both so I thought we could keep target_NPC() and use maybe target_Object() to target objects. Because it would be handy to be able to search for an object without actually harvesting it, I thought the common part of 1. and 2. can be a search function that returns the closest object eg.

Code: Select all

function CPlayer:findClosestNameOrId(_objnameorid)
	local closestObject = nil;
	local obj = nil;
	local objectList = CObjectList();
	objectList:update();

	for i = 0,objectList:size() do
		obj = objectList:getObject(i);

		if( obj ~= nil ) then
			if( obj.Type == PT_NODE and (obj.Id == _objnameorid or obj.Name == _objnameorid )) then
				local dist = distance(self.X, self.Z, obj.X, obj.Z);
				if( closestObject == nil ) then
					if( distance(self.X, self.Z, obj.X, obj.Z ) < settings.profile.options.HARVEST_DISTANCE ) then
						closestObject = obj;
					end
				else
					if( distance(self.X, self.Z, obj.X, obj.Z) <
						distance(self.X, self.Z, closestObject.X, closestObject.Z) ) then
						-- this node is closer
						closestObject = obj;
					end
				end
			end
		end
	end

	return closestObject;
end
Then you could do this;

Code: Select all

function CPlayer:target_NPC(_npcname)
	local npc = self:findClosestNameOrId(_npcname)
	if npc then
		memoryWriteInt(getProc(), self.Address + addresses.pawnTargetPtr_offset, npc.Address);
		RoMScript("UseSkill(1,1)");
		yrest(1500);
		return true
	else
		return false
	end
end

function CPlayer:target_Object(_objname,_waittime)
	local obj = self:findClosestNameOrId(_objname)
	if obj then
		memoryWriteInt(getProc(), self.Address + addresses.pawnTargetPtr_offset, obj.Address);
		RoMScript("UseSkill(1,1)");
		yrest(waittime);
		return true
	else
		return false
	end
end
You would of course still need to add the messages and error checks, etc.
  • 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
Administrator
Site Admin
Posts: 5353
Joined: Sat Jan 05, 2008 4:21 pm

Re: Thoughts about harvesting non-resource objects

#5 Post by Administrator »

Looks good to me. The only other suggestion I would add is the 'ignore' variable as can be seen in the harvest function. This allows you to one specific object, which can be useful when you're trying to harvest multiple nearby objects. It prevents you from attempting to harvest the same you just finished harvesting from.
User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Thoughts about harvesting non-resource objects

#6 Post by rock5 »

Administrator wrote:Looks good to me. The only other suggestion I would add is the 'ignore' variable as can be seen in the harvest function. This allows you to one specific object, which can be useful when you're trying to harvest multiple nearby objects. It prevents you from attempting to harvest the same you just finished harvesting from.
That could be tricky as sometimes you do want to harvest the same one, for example the chickens we have been working on. Sometimes it says they are not full and you need to click them again.

Maybe target_Object needs to be a more complex function eg.

Code: Select all

target_Object(_nameorid, _waittime, _harvestall, _donotignore)
So minimum you would use

Code: Select all

target_Object(_nameorid)
would harvest once with waittime of 0.

Code: Select all

target_Object(_nameorid, _waittime)
would harvest once and wait _waittime.

Code: Select all

target_Object(_nameorid, _waittime, _harvestall)
would harvest all nearby matching nodes ignoring the last harvested node by default and

Code: Select all

target_Object(_nameorid, _waittime, _harvestall, _donotignore)
would harvest all nearby matching nodes not ignoring the last harvested node (may have to put in a check if we get stuck not being able to harvest the node).
  • 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
Administrator
Site Admin
Posts: 5353
Joined: Sat Jan 05, 2008 4:21 pm

Re: Thoughts about harvesting non-resource objects

#7 Post by Administrator »

The harvest function makes use of 'ignore' by being optional. It is used for harvesting, so the call to the sub-function (findNearestNode()) includes it. If it's not included, it will then attempt to harvest the same node twice.

I'm not entirely sure how many option we will need. Outside of actual harvesting, would the '_harvestall' option be necessary?
User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Thoughts about harvesting non-resource objects

#8 Post by rock5 »

Administrator wrote:The harvest function makes use of 'ignore' by being optional. It is used for harvesting, so the call to the sub-function (findNearestNode()) includes it. If it's not included, it will then attempt to harvest the same node twice.

I'm not entirely sure how many option we will need. Outside of actual harvesting, would the '_harvestall' option be necessary?
I understand that 'ignore' in the harvest function is used internally to ignore disappearing nodes. So the harvest function always needs 'ignore'.

I'm talking about 'ignore' in the target_Object function. Most times it can ignore like harvest does but because sometimes you want to keep targeting the same object I thought an optional _dontignore might be handy. It would, after all, default to ignore when collecting multiple items.

If you have the '_harvestall" option you can use;

Code: Select all

player:target_Object("Bulletin Board")
to target 1 item only and not try to target multiple items which might cause you to loose your target in the process.

or

Code: Select all

player:target_Object("Chicken",3000,true)
to collect all items nearby.

Otherwise, every time someone wants to collect all near nodes they would have to use

Code: Select all

while player:target_Object("Chicken",3000) do end
This works but requires the user to know some programming basics and lets face it, some don't.
  • 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
Post Reply