Page 1 of 3

Automatically created waypointfiles

Posted: Thu Feb 02, 2012 4:43 am
by trias
Hi,

Is it possible to add some special functions in createpath.lua file, like automatically saving waypoints and harvestpoints which saves automatically waypoints in specify distance perioids of each waypoint e.g. 100 or it would be even better if distance between two waypoints can be manually changed in startmenu of the createpath.lua.

For example, I'm traveling from point A to point B and I want to make waypointfile from that automatically (waypoint distance of each waypoints to be e.g. 100) and if there is any harvestable in the path in radius from path e.g. 50 it will then save harvestpoint.

Keep up the great work!

Re: Automatically created waypointfiles

Posted: Thu Feb 02, 2012 4:52 am
by rock5
I like the idea of auto waypoints but I'm not so sure about auto harvest. Not all waypoints are for harvest and even if you had auto harvest a lot of people would still add the extra harvest points where there aren't any nodes because their ygather addon tells them nodes spawn there. So it's only minimally useful.

Re: Automatically created waypointfiles

Posted: Thu Feb 02, 2012 6:38 am
by trias
Yeah, maybe you're right about auto harvest, but auto waypoints I see usefull. It will make much easier to make waypointfiles for some guests which needes to kill a lot of mobs to complete. By putting auto waypoint in background when doing first round and then let RoMbot do the rest of the rounds to complete the guests. There is no need to concentrate making waypointfile when killing mobs.

However it would be nice if bot harvests at the same time while doing guests, maybe it will look like more human though ;)

Re: Automatically created waypointfiles

Posted: Thu Feb 02, 2012 9:01 am
by rock5
One problem is we are running out of keypad numbers. lol

Re: Automatically created waypointfiles

Posted: Thu Feb 02, 2012 9:29 am
by lisa
problem I see is I like to have a waypoint at corners, so you would still need to be able to add a point manually. So you may end up with points very very close to each other.

Re: Automatically created waypointfiles

Posted: Thu Feb 02, 2012 9:44 am
by Pushing40
What if it set a waypoint marker everytime you say, Clicked the mouse to turn or pressed the 'A' or 'D' keys?
That could possibly help with cutting corners. Just a thought.

Re: Automatically created waypointfiles

Posted: Thu Feb 02, 2012 10:17 am
by rock5
I envision having a button to start/pause auto waypoints. So if you wanted to manually place a corner waypoint you could pause auto beforehand then mark the corner then continue with auto. Probably if there are a lot of corners you would just stick with manual waypoints.

Re: Automatically created waypointfiles

Posted: Thu Feb 02, 2012 10:35 am
by lisa
Pushing40 wrote:What if it set a waypoint marker everytime you say, Clicked the mouse to turn or pressed the 'A' or 'D' keys?
That could possibly help with cutting corners. Just a thought.
Actually just clicking numpad 1 will add a waypoint.

Re: Automatically created waypointfiles

Posted: Thu Feb 02, 2012 12:02 pm
by trias
lisa wrote:problem I see is I like to have a waypoint at corners, so you would still need to be able to add a point manually. So you may end up with points very very close to each other.
I meant if waypoints could be added automatically a certain distance of each other, not a travel distance what character travels. So waypoints are added beforehand specified distance e.g. 150 of each other, no mater if character does zig zag between two waypoints, it will still mark new waypoint only after 150 distance of preceding waypoint.
Certainly there could be some problems of some objects, but when you are recording a waypointfile, you are aware of the recording, so you can make waypoints by caution.

Re: Automatically created waypointfiles

Posted: Fri Feb 03, 2012 11:06 pm
by MiesterMan
I wrote an addon that would run in the background and record harvest waypoints for you indefinately. When you save the waypoints they save in files named after zone names so if you go across multiple zones it won't jumble them together, it acutally seperates them.

The reason I haven't posted it (or retracted it rather) is because I had a problem with updating existing. For some reason it would erase the old waypoints and just write the new ones instead of combining the lists like I coded it to. If this sounds like something you want I could post the code here for someone else to look at since I can't figure out what's wrong with it.

Re: Automatically created waypointfiles

Posted: Fri Feb 03, 2012 11:40 pm
by lisa
I can have a look at the code for you if you want, been doing a lot of file and table manipulation lately.

Re: Automatically created waypointfiles

Posted: Fri Feb 03, 2012 11:53 pm
by MiesterMan
Hehe, bad habbits die hard. I started fiddling with the code right after I posted that and removed at least one error in logic I had going through. There is probably something wrong with my load function but it needs to be tested as is.

There are two files, first the userfunction file with the functions in it. The second is a waypoint file that runs with "rom/bot path:RecordHP" where the interface is similar to what the createpath.lua interface looks like but shorter (and with different options).

userfunction_HPRecorder.lua

Code: Select all

local wpList = {};
zID = 1;

callLang = {
	[0] = "  (%s)\tSave recorded nodes and quit\n",
	[2] = "  (%s)\tSave and clear recorded nodes\n",
	[1] = "  (%s)\tDiscard (clear) recorded nodes\n",
	[3] = "  Recording nodes at a %d second interval\n"
};

local function roundIt(_number)
	if _number > (math.floor(_number) + 0.5) then
		return math.ceil(_number);
	else
		return math.floor(_number);
	end
end

function findNodes()
	player:update();
	zID = getZoneID();
	--To compensate for different channels
	while(zID > 1000) do
		zID = zID - 1000;
	end
	if not wpList[zID] then
		wpList[zID] = {};
		wpList[zID].checked = false;
	end
	local obj = nil;
	local objectList = CObjectList();
	objectList:update();
		for i = 0,objectList:size() do
		obj = objectList:getObject(i);
			if( obj ~= nil ) then
			if( obj.Type == PT_NODE ) then
				if( database.nodes[obj.Id] ) then
					local harvestType = database.nodes[obj.Id].Type;
					if( harvestType == NTYPE_WOOD ) then
						hType = "WOOD";
					elseif( harvestType == NTYPE_HERB ) then
						hType = "HERB";
					elseif( harvestType == NTYPE_ORE ) then
						hType = "MINE";
					else
						hType = "FAIL";
					end
					
					-- Add the node to the table by ZoneID
					local tmp = {};
					tmp.X    = roundIt(obj.X);
					tmp.Z    = roundIt(obj.Z);
					tmp.Y    = roundIt(obj.Y);
					tmp.Type = hType;
					tmp.Name = obj.Name;
					local hpExists = false;
					for j,z in pairs(wpList[zID]) do
						if ((type(z) == "table") and (tmp.X == z.X) and (tmp.Z == z.Z) and (tmp.Y == z.Y)) then
							hpExists = true;
							break;
						end
					end
					if not hpExists then
						printf("Adding %s node at - X:%d Z:%d Y:%d\n", tmp.Type, tmp.X, tmp.Z, tmp.Y);
						table.insert(wpList[zID], tmp);
					end					
				end
			end
		end
	end
end

function saveRecpoints()
	local filename = ""

	for i,v in pairs(wpList) do
		if not wpList[i].checked then
			-- Zone the nodes are in is the filename
			zName = "/waypoints/HPoints/" .. string.gsub(sendMacro("GetZoneEnglishName(" .. i .. ");"), " ", "")
			filename = getExecutionPath() .. zName .. ".xml";
			--print(filename);
			-- Check if file exists
			file, err = io.open(filename, "r");
			
			-- File exists, add to table
			if file then
				print("Loading existing node records for " .. zName);
				loadHPoints(filename, i);
				file:close();
			end
			
			-- To write the new file
			print("Saving nodes to file...");
			file, err = io.open(filename, "w");
			
			while( not file ) do
				if not (string.find(err, "No such file or directory") == nil) then
					os.execute("mkdir scripts\\rom\\waypoints\\HPoints");
				else
					print("Could not open file to write, close the file!  Then press (Delete) to continue.\n");
					stopPE();
				end
				file, err = io.open(filename, "w");
			end
			
			--print("Writing file: " .. zName);
			
			local openformat = "\t<waypoint x=\"%d\" z=\"%d\" y=\"%d\" nodetype=\"%s\" node=\"%s\">%s";
			local closeformat = "</waypoint>\n";

			file:write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
			local str = sprintf("<waypoints>\n");	-- create first tag
			file:write(str);					-- write first tag
			
			local hf_line, tag_open = "", false;
			for j,z in pairs(wpList[i]) do
				if (type(z) == "table") then
					hf_line = hf_line .. sprintf(openformat, z.X, z.Z, z.Y, z.Type, string.gsub(z.Name, " ", ""), "\tplayer:harvest();") .. closeformat;
				end
			end
			
			file:write(hf_line);
			file:write("</waypoints>");
			file:close();
			
			wpList[i].checked = true;
		end
	end
	print("Clearing nodes...");
	wpList = {};
end

function loadHPoints(filename, hZone)
	local root = xml.open(filename);
	if( not root ) then
		error(sprintf("Failed to load recorded nodes from \'%s\'", filename), 0);
	end
	local elements = root:getElements();

	local retPoints = {};
	local tmp = {};
	for i,v in pairs(elements) do
		tmp.X,tmp.Z,tmp.Y,tmp.Type,tmp.Name = v:getAttribute("x"), v:getAttribute("z"), v:getAttribute("y"), v:getAttribute("nodetype"), v:getAttribute("node");
		local hpExists = false;
		for j,z in pairs(wpList[hZone]) do
			if (type(z) == "table") then
				printf("Checking existing %s node at - X:%d Z:%d Y:%d\n", tmp.Type, tmp.X, tmp.Z, tmp.Y);
				printf("To recorded       %s node at - X:%d Z:%d Y:%d\n", z.Type, z.X, z.Z, z.Y)
				if ((tmp.X == z.X) and (tmp.Z == z.Z) and (tmp.Y == z.Y)) then
					printf("Existing %s node at - X:%d Z:%d Y:%d already in list, not adding.\n", z.Type, z.X, z.Z, z.Y)
					hpExists = true;
				end
			end
		end
		if not hpExists then
			printf("Adding %s node at - X:%d Z:%d Y:%d\n", tmp.Type, tmp.X, tmp.Z, tmp.Y);
			table.insert(wpList[hZone], tmp);
		end
	end
end
RecordHP.xml

Code: Select all

<waypoints type="RUN">
	<onLoad>
		rInterval = 5;
		
		saveKey 	= key.VK_NUMPAD3;	-- save recorded nodes and exit
		resetKey 	= key.VK_NUMPAD8;	-- discard (clear) recorded nodes
		restartKey 	= key.VK_NUMPAD9;	-- save and clear recorded nodes
		cprintf(cli.green, "RoM harvest node recorder\n");
		printf(callLang[0]				-- Save recorded nodes and exit
			.. callLang[1]				-- Discard (clear) recorded nodes
			.. callLang[2]				-- Save and clear recorded nodes
			.. callLang[3],				-- Recording at %d interval
			getKeyName(saveKey), getKeyName(resetKey), 
			getKeyName(restartKey), rInterval);

		local hf_key_pressed, hf_key;
		local lCount = 0;
		while(true) do
			lCount = lCount + rInterval;
			hf_key_pressed = false;

			if( keyPressed(saveKey) ) then	-- save key pressed
				hf_key_pressed = true;
				hf_key = "SAVE";
			end;
			if( keyPressed(restartKey) ) then	-- restart key pressed
				hf_key_pressed = true;
				hf_key = "RESTART";
			end;
			if( keyPressed(resetKey) ) then	-- reset key pressed
				hf_key_pressed = true;
				hf_key = "RESET";
			end;

			if( hf_key_pressed == false and 	-- key released, do the work
				hf_key ) then					-- and key not empty

				-- SAVE Key: save waypoint file and exit
				if( hf_key == "SAVE" ) then
					findNodes();
					saveRecpoints();
					hf_key = " ";	-- clear last pressed key
					error("\nSaving nodes and exiting node recorder.", 0);
					break;
				end;

				if( hf_key == "RESET" ) then
					wpList = {}; -- DON'T save clear table
					hf_key = " ";	-- clear last pressed key
					print("Nodes discarded, list is now empty.");
				end;

				if( hf_key == "RESTART" ) then
					findNodes();
					saveRecpoints();
					hf_key = " ";	-- clear last pressed key
				end

				hf_key = nil;	-- clear last pressed key
			end;
			
			if lCount >= (rInterval * 1000) then
				findNodes();
				lCount = 0;
			end
			
			yrest(rInterval);
			
		end
	</onLoad>
</waypoints>

Re: Automatically created waypointfiles

Posted: Sat Feb 04, 2012 3:54 am
by trias
I've tried to test MiesterMans code, but when I start the recorder it starts ok but after a few seconds I'm getting errormessage:

10:38am - scripts\rom/bot.lua:465: onLoad error: ...cripts/rom/userfunctions/use
rfunction_HPRecorder.lua:21: attempt to call global 'getZoneID' (a nil value)


It seems to do something about ZoneID.

Re: Automatically created waypointfiles

Posted: Sat Feb 04, 2012 4:22 am
by lisa
yup it should be

Code: Select all

getZoneId()
Interesting I didn't know getZoneId would be +1000 if in another channel.

hmm can't think of any maps on my server who use more then 1 chann, so can't really test this.

Re: Automatically created waypointfiles

Posted: Sat Feb 04, 2012 6:22 am
by rock5
I think this came up previously. the fourth digit is the channel and the first 3 is the zone. You could parse the number to separate it so it always return the same zone number.

Re: Automatically created waypointfiles

Posted: Sat Feb 04, 2012 6:29 am
by lisa
but if that was the case then it would be 1006 and not just 6.
Memory address I found has always been exactly what you see on screen.

ZoneID: #
it always returns the #

Mind you like I said I can't think of any maps with more then 1 channel to be able to test it on my server.

Re: Automatically created waypointfiles

Posted: Sat Feb 04, 2012 6:48 am
by rock5
Well like you said, you always tested on server with only one channel. Obviosly channel 1 comes up as 0 so you dont see it. I confirmed this by logging on my eu account.

-- Channel 1

Code: Select all

Command> print(getZoneId())
2
-- Channel 2

Code: Select all

Command> print(getZoneId())
1002
-- Channel 3

Code: Select all

Command> print(getZoneId())
2002
All you need to do is a modulo in getZoneId. Just change line 1533 of functions.lua to

Code: Select all

		return zone%1000

Re: Automatically created waypointfiles

Posted: Sat Feb 04, 2012 10:48 am
by MiesterMan
Somewhere along the line they started randomly increasing the zone differentials, there are 10's and 100s in zone id's now. However everything over 1000 is just a channel difference. As rock said channel 1's multiplier is 0 so it will just skip the while loop and all channels will go into the same zone ID for recording.

The getZoneID function I was using was similar to what lisa added to the bot but I haven't updated it since I made this. Since then I've changed getZoneID to do a RoMScript because I got tired of updating the address manually. Because lisa has a permanent addition to the bot it would be best to change it to getZoneId() and be done with it (I did).

The real question now is if it properly records the nodes in the files as intended.

Re: Automatically created waypointfiles

Posted: Sat Feb 04, 2012 7:43 pm
by lisa
I can probably have a closer look at the bits in the address, there may just be a bit that changes for channels. Again though no maps with other channels, might have to make a char on another server just to test it.

Re: Automatically created waypointfiles

Posted: Sun Feb 05, 2012 10:28 am
by trias
I did some test and recorder seems to work now.
I've travelled from Varanas to Silverfall and recorder has made two separate waypoinfiles.
Silverspring.xml and Aslan.xml