Automatically created waypointfiles

Additional botting resources. Addons may be either for the game itself or for the RoM bot.
Forum rules
Only post additional bot resources here. Please do not ask unrelated questions.
Message
Author
trias
Posts: 13
Joined: Sun Jan 15, 2012 6:21 am

Automatically created waypointfiles

#1 Post by trias » Thu Feb 02, 2012 4:43 am

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!
-Keep up good work, I wouldn't be playing RoM if there is no Rom Bot-

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Automatically created waypointfiles

#2 Post by rock5 » Thu Feb 02, 2012 4:52 am

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.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

trias
Posts: 13
Joined: Sun Jan 15, 2012 6:21 am

Re: Automatically created waypointfiles

#3 Post by trias » Thu Feb 02, 2012 6:38 am

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 ;)
-Keep up good work, I wouldn't be playing RoM if there is no Rom Bot-

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Automatically created waypointfiles

#4 Post by rock5 » Thu Feb 02, 2012 9:01 am

One problem is we are running out of keypad numbers. lol
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: Automatically created waypointfiles

#5 Post by lisa » Thu Feb 02, 2012 9:29 am

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.
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

Pushing40
Posts: 3
Joined: Wed Feb 01, 2012 9:37 pm

Re: Automatically created waypointfiles

#6 Post by Pushing40 » Thu Feb 02, 2012 9:44 am

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.

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Automatically created waypointfiles

#7 Post by rock5 » Thu Feb 02, 2012 10:17 am

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.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: Automatically created waypointfiles

#8 Post by lisa » Thu Feb 02, 2012 10:35 am

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.
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

trias
Posts: 13
Joined: Sun Jan 15, 2012 6:21 am

Re: Automatically created waypointfiles

#9 Post by trias » Thu Feb 02, 2012 12:02 pm

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.
-Keep up good work, I wouldn't be playing RoM if there is no Rom Bot-

User avatar
MiesterMan
Posts: 543
Joined: Tue Jul 06, 2010 9:15 pm
Location: Between the Second and Third Circles of Hell

Re: Automatically created waypointfiles

#10 Post by MiesterMan » Fri Feb 03, 2012 11:06 pm

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.

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: Automatically created waypointfiles

#11 Post by lisa » Fri Feb 03, 2012 11:40 pm

I can have a look at the code for you if you want, been doing a lot of file and table manipulation lately.
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

User avatar
MiesterMan
Posts: 543
Joined: Tue Jul 06, 2010 9:15 pm
Location: Between the Second and Third Circles of Hell

Re: Automatically created waypointfiles

#12 Post by MiesterMan » Fri Feb 03, 2012 11:53 pm

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>

trias
Posts: 13
Joined: Sun Jan 15, 2012 6:21 am

Re: Automatically created waypointfiles

#13 Post by trias » Sat Feb 04, 2012 3:54 am

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.
-Keep up good work, I wouldn't be playing RoM if there is no Rom Bot-

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: Automatically created waypointfiles

#14 Post by lisa » Sat Feb 04, 2012 4:22 am

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.
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

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Automatically created waypointfiles

#15 Post by rock5 » Sat Feb 04, 2012 6:22 am

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.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: Automatically created waypointfiles

#16 Post by lisa » Sat Feb 04, 2012 6:29 am

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.
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

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Automatically created waypointfiles

#17 Post by rock5 » Sat Feb 04, 2012 6:48 am

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
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

User avatar
MiesterMan
Posts: 543
Joined: Tue Jul 06, 2010 9:15 pm
Location: Between the Second and Third Circles of Hell

Re: Automatically created waypointfiles

#18 Post by MiesterMan » Sat Feb 04, 2012 10:48 am

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.

User avatar
lisa
Posts: 8332
Joined: Tue Nov 09, 2010 11:46 pm
Location: Australia

Re: Automatically created waypointfiles

#19 Post by lisa » Sat Feb 04, 2012 7:43 pm

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.
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

trias
Posts: 13
Joined: Sun Jan 15, 2012 6:21 am

Re: Automatically created waypointfiles

#20 Post by trias » Sun Feb 05, 2012 10:28 am

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
-Keep up good work, I wouldn't be playing RoM if there is no Rom Bot-

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests