<?xml version="1.0" encoding="utf-8"?>
<waypoints>
<onLoad>
<![CDATA[
settings.profile.options.LOOT = false
settings.profile.options.TARGET_LEVELDIF_ABOVE = "15" -- Need to try to kill anything in there or no point.
settings.profile.options.TARGET_LEVELDIF_BELOW = "60" --trash is lvl 15 which people won't allow for in profile.

local function findEnemySeige(aggroOnly, _id, evalFunc, ignore)
	ignore = ignore or 0;
	local aggroOnly = aggroOnly or false;
	local bestEnemy = nil;
	local bestScore = 0;
	local obj = nil;
	local objectList = CObjectList();
	objectList:update();

	if( type(evalFunc) ~= "function" ) then
		evalFunc = function (unused) return true; end;
	end

	-- The 'max' values that each scoring sub-part uses
	local SCORE_DISTANCE = 60;      -- closer = more score; actually score will usually be less than half
	local SCORE_AGGRESSIVE = 80;    -- aggressive = score
	local SCORE_ATTACKING = 100;    -- attacking = score
	local SCORE_HEALTHPERCENT = 150; -- lower health = more score


	for i = 0,objectList:size() do
		obj = objectList:getObject(i);
		if( obj ~= nil ) then
			local inp = memoryReadRepeat("int", getProc(), obj.Address + addresses.pawnAttackable_offset) or 0;
			if not bitAnd(inp,0x4000000) and bitAnd(inp,0x10000) then -- Invisible/attackable?
				if( obj.Type == PT_PLAYER and (_id == obj.Id or _id == nil) and obj.Address ~= ignore) then
					local dist = distance(player.X, player.Z, obj.X, obj.Z);
					local pawn = CPawn(obj.Address);
					pawn:update();
					local _target = pawn:getTarget();

					if evalFunc(obj.Address) == true then
						if( settings.profile.options.MAX_TARGET_DIST > distance(player.X, player.Z, pawn.X, pawn.Z ) and
						(( (pawn.TargetPtr == player.Address or (pawn.TargetPtr == player.PetPtr and player.PetPtr ~= 0) or _target.InParty == true ) and
						aggroOnly == true) or aggroOnly == false) ) then
							local currentScore = 0;
							currentScore = currentScore + ( (settings.profile.options.MAX_TARGET_DIST - dist) / settings.profile.options.MAX_TARGET_DIST * SCORE_DISTANCE );
							currentScore = currentScore + ( (pawn.MaxHP - pawn.HP) / pawn.MaxHP * SCORE_HEALTHPERCENT );
							if( pawn.TargetPtr == player.Address ) then currentScore = currentScore + SCORE_ATTACKING; end;
							if( pawn.Aggressive ) then
								currentScore = currentScore + SCORE_AGGRESSIVE;
							end;
							if _target.InParty == true  then currentScore = currentScore + 5000 end
							if( bestEnemy == nil ) then
								bestEnemy = obj;
								bestScore = currentScore;
							elseif( currentScore > bestScore ) then
								bestEnemy = obj;
								bestScore = currentScore;
							end
						end
					end
				end
			end
		end
	end

	if( bestEnemy ) then
		return CPawn(bestEnemy.Address);
	else
		return nil;
	end
end


local function SeigeDPS()
	if settings.profile.options.PARTY ~= true then settings.profile.options.PARTY = true end --in seige so just make it party settings
	if settings.profile.options.PVP ~= true then settings.profile.options.PVP = true end -- enable PVP for seige
	if settings.profile.options.USE_PHIRIUS_POTION ~= false then settings.profile.options.USE_PHIRIUS_POTION = false end -- Can't use phirius in siege
	
	while(true) do
		player:update();
		player:checkSkills(true);
		
		--=== Find PVP characters to kill ===--
		player:target(findEnemySeige()) 

		if player:haveTarget() then
			player:fight(seige);
		end

		--=== Find Balloons to kill ===--
		player:target(player:findEnemy(nil,nil,nil,nil)) -- add balloon Id's to second arg
		if player:haveTarget() then
			player:fight();
		end
		
		--=== If in combat then defend yourself and party ===--
		if player.Battling then
		player:target(player:findEnemy(true,nil,nil,nil))
			if player:haveTarget() then
				player:fight();
			end
		end
		
		
		--getNameFollow() -- follow has been commented out.
		
		local selficon = player:GetPartyIcon()
		
		--=== if self icon II then mount up and follow ===--
		if selficon == 2 then
			while not player.Mounted do
				player:mount()
			end
		end
		
		--=== If self icon III then just follow ===--
		if selficon == 3 then
			
		end
		
		--=== If self icon VI then logout, also errors MM after logging out ===--
		if selficon == 6 then
			sendMacro("Logout();"); 
		end		
	end
end			

function getNameFollow()
	while (true) do	
  		if ( settings.profile.options.PARTY_FOLLOW_NAME ) then
			if GetPartyMemberName(1) == settings.profile.options.PARTY_FOLLOW_NAME  then RoMScript("FollowUnit('party1');"); break  end
			if GetPartyMemberName(2) == settings.profile.options.PARTY_FOLLOW_NAME  then RoMScript("FollowUnit('party2');"); break  end
			if GetPartyMemberName(3) == settings.profile.options.PARTY_FOLLOW_NAME  then RoMScript("FollowUnit('party3');"); break  end
			if GetPartyMemberName(4) == settings.profile.options.PARTY_FOLLOW_NAME  then RoMScript("FollowUnit('party4');"); break  end
			if GetPartyMemberName(5) == settings.profile.options.PARTY_FOLLOW_NAME  then RoMScript("FollowUnit('party5');"); break  end
			RoMScript("FollowUnit('party1');")
		else 
			RoMScript("FollowUnit('party1');")
		end
		break
	end
end


	SeigeDPS()


]]></onLoad>
</waypoints>