Page 1 of 1

player:target_Object() problem

Posted: Sat Apr 25, 2015 6:59 am
by Ego95
Hi,

I got some problems with the player:target_Object() function. Like you know we need a minimal distance to objects, to harvest them. The problem is, that the library in the guild castle is so huge, that the center point is too far away.

In player.lua I found (lines 3741-3747)

Code: Select all

				if( distance(self.X, self.Z, obj.X, obj.Z) > 39 ) then
					self:moveInRange(CWaypoint(obj.X, obj.Z), 39, true);
					repeat
						yrest(50)
						self:updateActualSpeed()
					until not self.Moving
				end
I needed to change the distance from 39 to 50, so that the player can click the library. Better would be 75. The thing is, that this affects harvesting materials and other things too. Is there no way to check via memory, from which distance an object is clickable? Or could there be an other workaround for this?

Re: player:target_Object() problem

Posted: Sat Apr 25, 2015 12:01 pm
by BlubBlab
Perhaps make change of the distance optional as an extra argument ?

Re: player:target_Object() problem

Posted: Sat Apr 25, 2015 7:04 pm
by lisa
If the library is the only Object with this issue then I would just not use player:target_Object() for the library.

You could make up a user function to click library which uses the code in target_Object but with a distance of 50.
If there was more objects with the issue then I would look at adding in another argument to target_Object for distance and just do default at 39 if the argument isn't used.

Just my 2 cents

Re: player:target_Object() problem

Posted: Sun Apr 26, 2015 3:27 pm
by Ego95
Okay, thanks for your answers =) I took BlubBlabs idea and added an extra argument. I dont know, if the code can be made cleaner, this is, how I did it:

Code: Select all

function CPlayer:target_Object(_objname, _waittime, _harvestall, _donotignore, _objdistance, evalFunc)
(line 3705)

and

Code: Select all

				if( distance(self.X, self.Z, obj.X, obj.Z) > 39 ) and _objdistance == nil then
					self:moveInRange(CWaypoint(obj.X, obj.Z), 39, true);
					repeat
						yrest(50)
						self:updateActualSpeed()
					until not self.Moving
				else
					self:moveInRange(CWaypoint(obj.X, obj.Z), _objdistance, true);
					repeat
						yrest(50)
						self:updateActualSpeed()
					until not self.Moving
				end
(from line 3741)

The repeat-part is double, but but works =)

Re: player:target_Object() problem

Posted: Sun Apr 26, 2015 6:11 pm
by lisa
Probably not the way I would do it but this is a neater version of what you posted.

--=== Untested ===--

Code: Select all

function CPlayer:target_Object(_objname, _waittime, _harvestall, _donotignore, _objdistance, evalFunc)
if  type(_objdistance) ~= "number" then  _objdistance = 39 end


           if( distance(self.X, self.Z, obj.X, obj.Z) > _objdistance ) then
               self:moveInRange(CWaypoint(obj.X, obj.Z), _objdistance, true);
               repeat
                  yrest(50)
                  self:updateActualSpeed()
               until not self.Moving
            end

Re: player:target_Object() problem

Posted: Sun Apr 26, 2015 9:55 pm
by rock5
Basically player:targetObject is a complicated special targeting function that has arguments to help target harvestable type items. That's items that have collect time or you need to collect until it disappears or you need to ignore it after using it, etc.

If all you want to do is click something then I would use target_NPC but unfortunately that also has a distance check.

Honestly, in this case, I would just use the more basic commands.

Code: Select all

lib = player:findNearestNameOrId("Library")
player:target(lib)
Attack()
I think the reason this hasn't come up before because usually you would use the Library manually when needed.

Re: player:target_Object() problem

Posted: Mon Apr 27, 2015 2:43 am
by Ego95
The thing is, that I used target_Object because I need the waittime. For a special reason I need to click the library once until the castingbar has been full, then go on.
The library is a complicated thing, maybe I should change it to target_NPC. But I think I already tried that, but my character tried to get to the center point of the building again.

I will test your idea, with findNearestNameOrId, rock =)

Edit: Just read the thing with the distance check of target_NPC...yes, this is why it didn't work either

Re: player:target_Object() problem

Posted: Mon Apr 27, 2015 4:16 am
by rock5
You can probably use player.Casting to make sure you are casting and player:waitTillCastingEnds() to wait until the castbar goes away, eg.

Code: Select all

repeat
   Attack()
   yrest(500)
   player:updateCasting()
until player.Casting == true
player:waitTillCastingEnds()

Re: player:target_Object() problem

Posted: Mon Apr 27, 2015 4:43 am
by rock5
Looks like player:waitTillCastingEnds() wont work with that. Instead you can use player.Casting again.

Code: Select all

repeat
   yrest(500)
   player:updateCasting()
until player.Casting == false