Page 1 of 1

player:figh() or Cast problem

Posted: Wed Jun 26, 2013 4:30 pm
by dr-nuker
Hello there,

i made myself a very long script for this new title stuff and i end up with a quest in waterdragon cave.
So basically the quests needs you to pass by and kill 10 of the elements hanging around at 10 fixed spots.

So i tried to find the elements, target them and use player:fight() so that the bot is clever and kills the target automatically.
It is the same as when using Attack()
I also found that when checking for battle and fighting spawn gates in malatinas course of survival.
The bot just clears the target...

So here is a snippet that is a workaround:

Code: Select all

  function attackelementalincave()

  local chests = {}
	local objectList = CObjectList();
	objectList:update();
	local objSize = objectList:size()
	for i = 0,objSize do
		local obj = objectList:getObject(i);
		obj:update()
   print(obj.HP)
		if obj.Name == "Possessed Water Elemental" and obj.Attackable then
			obj.Dist = distance(player.X,player.Z,obj.X,obj.Z)
      if 200 > obj.Dist then
			   table.insert(chests, table.copy(obj))
      end
		end
	end
	table.sort(chests,function(a,b) return b.Dist>a.Dist end)
	table.print(chests)
	for k,v in ipairs(chests) do
		player:target(v)
    keyboardPress( key.VK_2 )
		yrest(3200) -- 2 seconds
    keyboardPress( key.VK_2 )
		yrest(3200) -- 2 seconds
    yrest(2000)
    break
  end
   
  end
Dont get confused by the chests. I was just lazy and did a c&p of a Tempesthigh waypoint.
This snippet finds the elements and targets the closest then it uses my button 2. This works.
but

Code: Select all

           
player:fight()
player:cast("MAGE_FLAME");
do both not work :/

I've already tried to change leveldependancies, mob settings, RUN/NORMAL waypoint-style but nothing helps.

This is also bad when killing the boss, since it just does not do that -.-

any idea?

Br,
nuker

Re: player:figh() or Cast problem

Posted: Sat Jun 29, 2013 9:56 am
by dr-nuker
No idea?
Anybody?

I also tried via console. But i can not target mobs and also not cast or fight them (besides Attack())

This was never a problem before but i can not work out what is missing now :&

Re: player:figh() or Cast problem

Posted: Fri Jul 05, 2013 3:41 am
by lisa
run it using debug and see what is printed about the target and using player:fight(), it will tell you exactly why it isn't attacking it.

Re: player:figh() or Cast problem

Posted: Tue Jul 09, 2013 2:47 am
by lolita
maybe you need set elite factor to more then 5

Code: Select all

	<option name="AUTO_ELITE_FACTOR"    value="5" />			<!-- (value * your max HP) to designate a mob as "elite" -->

Re: player:figh() or Cast problem

Posted: Tue Jul 09, 2013 12:47 pm
by dr-nuker
lolita wrote:maybe you need set elite factor to more then 5

Code: Select all

	<option name="AUTO_ELITE_FACTOR"    value="5" />			<!-- (value * your max HP) to designate a mob as "elite" -->
Well thanks.

I'm the world's "not so smart"est person.
Actually this line somehow got lost in my profile. Then the bot seems to use 0 as value :evil:
Wonder why Attack() still works ...

Re: player:figh() or Cast problem

Posted: Tue Jul 09, 2013 1:29 pm
by rock5
'Attack()' just attacks, it does no other checks. It's basically the same as just pressing the attack key or double clicking a target.

Re: player:figh() or Cast problem

Posted: Sat Jul 27, 2013 12:27 pm
by dr-nuker
Well sorry for digging this out...

I still don't get it!

I thought player:fight() would work again, but it does NOT.

If i do like

Code: Select all

function myfight(target)
	target = CPawn(target.Address)

	-- Kill any aggro mobs before going back to target
	player:update()
	if player.Battling then
		repeat
			local _enemy = findaggroenemy()
			if _enemy then
				player:target(_enemy);
				player:fight()
			end
		until _enemy == nil or player.HP < 1 or player.Alive == false
	end

	-- Attack target
	target:update()
	player:aimAt(target)
	while target.Id ~= 0 and target.HP > 4 do
		player:target(target)
		if aoefound == false and (player.Class1 == CLASS_WARRIOR or player.Class1 == CLASS_CHAMPION) then Attack() end
		-- Check skills
		for i,v in pairs(settings.profile.skills) do
			if v.AutoUse and v:canUse(false, target) and
			   (v.Type == STYPE_DOT or v.Type == STYPE_DAMAGE) and
			   AllowSkillCastTime >= v.CastTime then
				local oldHP = target.HP -- Remember HP for extra check
				player:cast(v) -- Cast attack skill
				repeat yrest(50) player:update() until not player.Casting
				player:checkSkills(true) -- Friendly skills only.
				-- Wait a bit of time for damage to register, avoids casting another skill needlessly.
				local starttime = os.clock()
				yrest(150)
				repeat
					yrest(50)
					target:update()
				until target.Id == 0 or 5 > target.HP or target.HP < oldHP or aoefound or (os.clock()-starttime) >= 1
				-- End checking skills if target dead or if using AOE
				local damage = memoryReadInt(getProc(), target.Address + 0x1D0)
				if target.Id == 0 or 5 > target.HP or damage == oldHP or aoefound then
					break
				end
			end
		end
		target:update()
		player:update()
		-- player dead?
		if (player.HP < 1 or player.Alive == false) then break end
		player:checkPotions()
	end
	player:resetSkills()
end
it does just stand there and not cast anything.

This is annoying since i never had problems with that before :/ any ideas? I resolved all files but it did not help -.-

Re: player:figh() or Cast problem

Posted: Sat Jul 27, 2013 12:59 pm
by rock5
Try adding print statements to see where it gets stuck, especially in loops. Then when you know where it gets stuck add print statements that print some of the values so you can find any unexpected values that might be causing unexpected behavior.

Re: player:figh() or Cast problem

Posted: Sat Jul 27, 2013 1:03 pm
by dr-nuker
Well i already found it.

It get's stuck in the loop

Code: Select all

   if player.Battling then
      repeat
         local _enemy = findaggroenemy()
         if _enemy then
            player:target(_enemy);
            player:fight()
         end
      until _enemy == nil or player.HP < 1 or player.Alive == false
   end
It finds the enemy but does not use the fight statement. It even targets it...
Auto elite and everything is setup in a good way!

Re: player:figh() or Cast problem

Posted: Sat Jul 27, 2013 2:35 pm
by rock5
I'd say your function is finding a target but the player:fight function doesn't think it's a valid target. What's in findaggroenemy? It might help if you ran it with debug enabled. It might tell you why it wont attack it. Just start the bot with the extra argument "debug".