<?xml version="1.0" encoding="utf-8"?><waypoints>

<!--        Rock5's Millers Ranch Chickens run        -->
<!--           By Rock5(v2.0)     MOD Version 1.3     -->
<!-- www.solarstrike.net/phpBB3/viewtopic.php?p=12139 -->
<!--	MODDED by jduartedj		thx to fobsauce 	  -->
<!--    THIS WP FILE REQUIRES TELEPORT UserFunction   -->

<onLoad>
		deliver = 100; -- change if you want to enable/disable deliver  0=disable, any number = deliver after that amount of eggs (must b bigger than 9)
		lagtime = 0; -- if you have more than 1 bot running set to 500+ if not 100/200 should be ok depending on your machine. MAX recommended 750

	changeProfileOption("HARVEST_DISTANCE", 150);
	changeProfileOption("QUICK_TURN", true);
	repeat questname=RoMScript("TEXT('Sys422386_name')"); yrest(500) until questname -- ie. "An Easy Lay?"
	repeat npcname=RoMScript("TEXT('Sys114930_name')"); yrest(500) until npcname -- ie. "Jenna Miller"
	
	function Deliver() --note the caps
		while inventory:itemTotalCount(204795)>9 do --if 9+ fresh eggs
		player:target_NPC(npcname);
		sendMacro("AcceptQuest()"); yrest(lagtime);
		player:target_NPC(npcname);
		sendMacro("CompleteQuest()"); yrest(lagtime+1000);
		end
	end
	
	repeat zoneid = RoMScript("GetZoneID()") until zoneid
	if zoneid ~= 304 then -- not at Miller's Ranch
		-- Try to find Sorrun and teleport in
		if player:target_NPC("Sorrun") then
			sendMacro("ChoiceOption(3)") yrest(lagtime)
			sendMacro("ChoiceOption(1)")
			waitForLoadingScreen()
		else
			error("You are too far from Miller's Ranch")
		end
	end

	function feedHenEvalFunc(address)
		hen = CObject(address)

		-- Don't target hens in coop
		if hen.Z > 3240 then return false end -- Hen in coop

		-- Don't target moving hens
		oldX = hen.X; oldZ = hen.Z
		yrest(lagtime+200);
		hen:update()
		if distance(hen.X,hen.Z,oldX,oldZ) > 2 then return false end

		return true
	end

	function coopHenEvalFunc(address)
		-- Only target coop Hens
		if 3240 > CObject(address).Z then return false end

		return true
	end
	
	function feedHen()
		local hen = player:findNearestNameOrId(112955)
		local feed
		if hen then
			hen = CObject(hen.Address)
			if distance(player.X,player.Z,hen.X,hen.Z) > 15 then
				teleport(hen.X+10,hen.Z+10) --rather not be on top of it!
			end
			feed = player:target_Object(112955,4250+lagtime,false,true,feedHenEvalFunc)
		end
			return hen and feed
	end
</onLoad>
	<!-- #  1 --><waypoint x="4033" z="3450">	</waypoint>
	<!-- #  2 --><waypoint x="4029" z="3327">	</waypoint>
	<!-- #  3 --><waypoint x="4016" z="3172">	</waypoint>
	<!-- #  4 --><waypoint x="3948" z="3107" tag="Main">
			local target;
			local queststate = getQuestStatus(questname);
		if queststate ~= "incomplete" and queststate ~="complete" then --needs to get the quest before harvesting
			-- Accept quest
			player:target_NPC(npcname);
			sendMacro("AcceptQuest()"); 
			yrest(lagtime);
			__WPL:setWaypointIndex(__WPL:findWaypointTag("Main"))
		else
			if inventory:itemTotalCount(204795) >= deliver and deliver ~=0 then 
				Deliver() --delivers if set to
				__WPL:setWaypointIndex(__WPL:findWaypointTag("Main"))
			else
					
				while inventory:itemTotalCount(204789) > 0 and feedHen() do -- Feed Hens no point being bigger than 0 when also must be bigger than 9
				end
				-- Out of feed or hens
				if 1 > inventory:itemTotalCount(204789) then -- Get more feed
					if distance(player.X,player.Z,3940,3055)>128 then
						teleport(3948,3107); -- back to main
					end
					__WPL:setWaypointIndex(__WPL:findWaypointTag("Get Feed"));
					teleport(3940,3055);
				else
					if distance(player.X,player.Z,3928,3185)>128 then
						teleport(3948,3107); -- back to main
					end
					__WPL:setWaypointIndex(__WPL:findWaypointTag("Get Eggs"))
					teleport(3928,3185);
				end
				
			end -- end of deliver
		end
	</waypoint>
	<!-- #  2 --><waypoint x="3940" z="3055" tag="Get Feed">teleport(3937,2978);	</waypoint>
	<!-- #  4 --><waypoint x="3937" z="2978" tag="Get FeedT">
	player:target_Object(112956,4250+lagtime,true);
	teleport(3940,3055);
	</waypoint>
	<!-- #  5 --><waypoint x="3940" z="3055" tag="Get FeedR">teleport(3948,3107);__WPL:setWaypointIndex(__WPL:findWaypointTag("Main"));	</waypoint>
	
	
	<!-- #  6 --><waypoint x="3928" z="3185" tag="Get Eggs">teleport(3929,3261);	</waypoint>
	<!-- #  8 --><waypoint x="3929" z="3261" tag="Get EggsT">
		changeProfileOption("HARVEST_DISTANCE", 40)
		
-- OLD fix by 4ipok		while player:target_Object("Ranch Hen",1250+lagtime,nil,true,coopHenEvalFunc) do -- Check for hens (112955)
		while player:target_Object(112955,1250+lagtime,nil,true,coopHenEvalFunc) do -- Check for hens (112955)
			yrest(lagtime)
			if not player:target_Object(112958,1250+lagtime,true) then -- Get Fresh Eggs
			player:target_Object(114931,1250+lagtime,true) -- Get Golden Eggs
			end
		end

		changeProfileOption("HARVEST_DISTANCE", 150)
		
		teleport(3926,3198);
		if 1 > inventory:itemTotalCount(204789) then yrest(lagtime+1000) end --if he gooes directly to feed he is rubberbanded!
	</waypoint>
	<!-- #  9 --><waypoint x="3926" z="3198">teleport(3948,3107);__WPL:setWaypointIndex(__WPL:findWaypointTag("Main"));	</waypoint>
</waypoints>
