Problem with pawn.Alive

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
alvoro
Posts: 3
Joined: Wed Mar 21, 2012 10:59 pm

Problem with pawn.Alive

#1 Post by alvoro »

Why pawn.Alive always return TRUE:
1. found mob, go to him - pawn.Alive=true
2. kill mob - pawn.Alive=true
3. loot corpse, dead body dissapeared - only now pawn.Alive=false

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<waypoints>
<onLoad>
--- func ---
function TargetInRange(_range)
	local pawncount = 0
	local thepawn = nil
	local mindist = _range
	local objectList = CObjectList();
	objectList:update();
	for i = 0,objectList:size() do
		local obj = objectList:getObject(i);
		if( obj ~= nil and obj.Type == PT_MONSTER) then
			local pawn = CPawn(obj.Address);
			local dist = distance(pawn.X,pawn.Z,pawn.Y,player.X,player.Z,player.Y)
			if (_range >= dist) and pawn.Alive and pawn.Attackable then
				pawncount = pawncount + 1
				if mindist > dist then
					thepawn = pawn
					mindist = dist
				end
			end
			cprintf(cli.white, "Target: %s  range: %s\n", pawn.Name, dist);
		end
	end
	return thepawn,mindist,pawncount
end

--- main ---
  while (true) do
	tgt,dalnost,vsego = TargetInRange(500);
	cprintf(cli.white, "Nearest: %s  range: %s  All tgts:%s\n", tgt.Name, dalnost, vsego);
    if tgt then
	player:target(tgt)
	player:moveInRange(tgt, 10, true)
--	player:fight()	player:checkSkills(true, tgt)
	player:update()
	RoMScript("UseSkill(1,1)")
	tgt:update()
	if tgt.Alive then cprintf(cli.white, utf82oem_russian("Alive\n")) end
    end

    player:sleep()
  end
</onLoad>
</waypoints>
Tested on lowlevel mobs. Works fine except pawn.Alive ALWAYS = true, that is why script kills 1 mob and stay on corps
untill corps disappered.
User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: Problem with pawn.Alive

#2 Post by lisa »

yup the .Alive offset for mobs means the mob exists that is why the bot checks it's HP to decide if the mob is dead or not.

Code: Select all

	-- Not attackable
	if( not target.Attackable ) then
		return false;
	end

	-- Dead
	if( target.HP < 1 ) then
		return false;
	end

	-- Also dead (and has loot)
	if( target.Lootable ) then
		return false;
	end

	if( not target.Alive ) then
		return false;
	end
Remember no matter you do in life to always have a little fun while you are at it ;)

wiki here http://www.solarstrike.net/wiki/index.php?title=Manual
Post Reply