<?xml version="1.0" encoding="utf-8"?><waypoints>
	<!--
		ElementEvent for Colorweave Festival
		By Dx
		
		Uses CountMobs by Rock5
		Loosly based on help from Lisa
		
		NPC: Ayna Rett ID: 120888
		
		Red bubble: 121055
		Blue bubble: 121057
		Yellow bubble: 121056
		
		Blue Element ID: 103015
		Yellow Element ID: 103014
		Red Element ID: 103013
		Purple Element ID: 106548
		
		Stone marker ID: 121045
		
		'Times Having Helped Out' ID: 623045 
		'Magic Thread' ID: 623044 
	-->
	<onLoad>
		<![CDATA[
			maxdist  = 150    	-- Max dist to take an element on
			slowdown = 750		-- Pause after taking an element
			
			-- To go 'rape mode' set maxdist to 200 and slowdown to 0
			
			brel = {}
			brel[121055]={Id=103013,color="Red"}
			brel[121057]={Id=103015,color="Blue"}
			brel[121056]={Id=103014,color="Yellow"}
			
			-- Wait until NPC can be talked to "Let me help you out!"
			cprintf(cli.lightblue, "Waiting for event registration!\n")
			repeat yrest(1000) until player:hasBuff(623044)
			cprintf(cli.lightblue, "Waiting for event to start!\n")
			repeat yrest(1000) until player:hasBuff(623041)
			cprintf(cli.lightblue, "Event started!\n")
			
			-- Setup event
			color = nil
			helped = 0
			hname = GetIdName(623045)
			npc = player:findNearestNameOrId({120888})
			
			-- Do event
			repeat
				bobj = player:findNearestNameOrId({121055, 121056, 121057})
				if bobj then
					if color ~= brel[bobj.Id].color then
						color = brel[bobj.Id].color
						cprintf(cli.lightblue, "Bubble changed to %s\n", color)
					end
					
					-- Wait until element is a little closer, looks bad killing at spawn
					obj=player:findNearestNameOrId({103013, 103014, 103015, 106548})					
					if obj and distance(npc.X, npc.Z, npc.Y, obj.X, obj.Z, obj.Y) < maxdist then
						player:target(obj)
						if obj.Id == brel[bobj.Id].Id then
							RoMScript("UseExtraAction(1)")
						else
							RoMScript("UseExtraAction(2)")
						end
						
						-- Keep track of number of times helped
						if player.Buffs[hname] then
							helped = player.Buffs[hname].Level
						end

						-- If other players in circle, slow down
						if CountPlayers(200) > 0 then
							yrest(slowdown) 
						end
					end
				end
				
				yrest(200)
				player:updateBuffs()
			until not player:hasBuff(623041)

			-- And were done
			cprintf(cli.lightblue, "You got %d points\n", helped)
   			error("Finished")
		]]>
	</onLoad>
</waypoints>
