Sign in to follow this  
Viking

LUA RoTu Astar

Recommended Posts

Hey guys, hey @leiizko

 

i had a look into the lua plugin + scripts for the rotu mod.

Within the waypoints.gsc there was and after the changes for the lua plugin still is this part:

loadWaypoints()
{
	[...]
	bla bla
	[...]

	level.waypointCount = int( tableLookup(fileName, 0, 0, 1) );
	for( i=0; i<level.waypointCount; i++ )
	{
		waypoint = spawnStruct();
		origin = TableLookup(fileName, 0, i+1, 1);
		orgToks = strtok( origin, " " );
		waypoint.origin = ( float(orgToks[0]), float(orgToks[1]), float(orgToks[2]));
		
		level.waypoints[i] = waypoint;
	}

	for( i=0; i<level.waypointCount; i++ )
	{
		waypoint = level.waypoints[i]; 
		
		strLnk = TableLookup(fileName, 0, i+1, 2);
		tokens = strtok(strLnk, " ");
		
		waypoint.childCount = tokens.size;
		
		for( j=0; j<tokens.size; j++ )
			waypoint.children[j] = int(tokens[j]);
	}
      [...]
	bla bla
	[...]
}

 

Am i right, that the array of they waypoints (level.waypoins) is still created and stored in gsc?

Is there any way to create and store the waypoint array in lua too?


I am asking because i am working on a project that currently has about 1.000 waypoints and that ends in a variable overflow.

To keep the movement nice and smooth i would like to stick to my waypoints, i could not reduce them much anyways because the map is giant.

 

Thanks

Viking

Share this post


Link to post
Share on other sites

Waypoints are still stored in gsc as they're referenced all over the place and I didn't want to bother changing it all. You can store all waypoints in lua without any issue, you just need some fetch function and are ready to go.

example:

Ranktable -> Fetch -> GSC function

 

Share this post


Link to post
Share on other sites
49 minutes ago, Viking said:

That's great to hear. 😊

To be honest i never worked with lua before, but i give it a try.

Thank you

just a question for Viking

Is what your trying to do have anything to do with usemaps? I would love to see the bot system waypoints work with usermaps

since I was unable to find any waypoints for usermaps and there are so many different usermaps available for download.

Just a hopeful question!

Share this post


Link to post
Share on other sites

No, it's just for the map in am working on.

But you can create your own waypoints for the usermaps you want to run.

It's a pain and takes a lot of time but it's possible. Just check the devtools of the latest pezbot release.

You have to run through the map and place/connect the waypoints manually.

Once you are done you can save them and do an exportiert to the console log.

 

This one is a tutorial for a different mod, but except the controls it looks like the System of pezbot and basically every bot System that requires waypointy.

https://www.moddb.com/mods/bot-warfare/tutorials/creating-modifying-and-installation-of-waypoints

Share this post


Link to post
Share on other sites

i am stuck a bit and need a helping hand to guid me into the right direction.

 

in gsc i have

	level.waypoints[curEntry] = spawnStruct();
	level.waypoints[curEntry].wpIdx = curEntry;
	level.waypoints[curEntry].nghbr = [];

 

how can i achieve this in lua?

i always get an error "attempt to index a nil value" at

waypoints[curEntry].wpIdx = curEntry

but waypoints is gloabally defined as table {} and curEntry is an integer (checked with a print).

So I guess lua can not handle the var dot subvar

 

any advice would be great :)

Share this post


Link to post
Share on other sites
waypoints[curEntry] = {}
waypoints[curEntry].wpIdx = curEntry

The dot in lua is table( waypoints[curEntry] == waypoints.curEntry )

Share this post


Link to post
Share on other sites

That was an easy one, thanks.

 

I ran into a new problem now and can't think of a better solution.

 

This is the background:

I do not use waypoints that have predefined children.

What i did was creating a "simplyfied" navmesh in radiant where a lot of small rectangles are next to each other.

Now i would like the code to check if two of these rectangles are next to each other.

If so they are defined as neighbours (children in the current waypoint codes)

 

Now the problem:

Right now the map has 9705 of this rectangles (map not even fully covered yet).

The loop is checking every rectangle against the other rectangles before it moves over to the next rectangle and again checks this one against all other existing rectangles.

 

The whole procedure takes about 15 minutes.

This is not very smart and i can't imagine the players would stay on the server when every map start takes that amount of time.

 

This is the gsc snippet i have

	//create neighbours
	for(i=0;i<level.vertex.size;i++)
	{
		for(j=0;j<level.vertex.size;j++)
		{
			if(j == i)
				continue;
	
			sharedEdges = 0;
			for(k=0;k<level.vertex[j].edges.size;k++)
			{
				for(l=0;l<level.vertex[i].edges.size;l++)
				{
					if(Distance(level.vertex[i].edges[l], level.vertex[j].edges[k]) < 2)
					{
						sharedEdges++;
		
						//if they share two edges then they are neighbours
						if(sharedEdges >= 2)
						{
							level.vertex[i].nghbr[level.vertex[i].nghbr.size] = level.vertex[j];
							break;
						}
					}
				}
			}
		}
	}

 

Share this post


Link to post
Share on other sites

I don't really remember how this pathfinding works as it was quite some time ago but i guess the simplest solution is to just dump it to file and load it from there. 

Share this post


Link to post
Share on other sites

I tweaked the loop a bit and was able to reduce the time a bit, but not very much.
Your solution with the dump is perfect.

My dump now looks like the default waypoint.csv rotu is looking for.

Howevery, i don't get the rotu.lua and astar.lua to work.

Following the readme on your github page i put the files into:
cod4xserver/lua_scripts

And load rotu.lua from server.cfg with:

loadplugin lua
// script is located in fs_homepath/lua_scripts
//lua_loadscript "lua_scripts/astar.lua"
lua_loadscript "lua_scripts/rotu.lua"
lua_loadscript "lua_scripts/lua_navmesh_import.lua"

But the server returns an error when starting:

Plugin lua loaded successfully. Server is currently running 1 plugins.
****************** Lua Error: ******************

lua_scripts/rotu.lua:1: module 'astar' not found:
	no field package.preload['astar']
	no file './astar.lua'
	no file '/usr/local/share/luajit-2.1.0-beta3/astar.lua'
	no file '/usr/local/share/lua/5.1/astar.lua'
	no file '/usr/local/share/lua/5.1/astar/init.lua'
	no file './astar.so'
	no file '/usr/local/lib/lua/5.1/astar.so'
	no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
	[C]: in function 'require'
	lua_scripts/rotu.lua:1: in main chunk

************************************************
Adding a plugin script function for plugin 0, command name: lua_createNavMeshFile.
Adding a plugin script function for plugin 0, command name: lua_loadWaypoints.
lua_loadscript: Successfully started lua script lua_scripts/lua_navmesh_import.lua

 

I have no clue why it does not find the astar.lua because it's in the same dir as rotu.lua

Uncommenting the scriptload of astar.lue in cfg ends in the same error.

 

 

edit: solved

problem was that lua was looking for the file in "./" which is the cod4xserver root folder.

i use now, which works.

Quote

local astar = require ( "lua_scripts.astar" )

 

Edited by Viking

Share this post


Link to post
Share on other sites

@leiizko

Do you have an idea how i could debug the path finding?

 

I modified the rotu.lua and astar.lua a bit so they return the full path as well, not the next step only.

That way i am able to check the path calculation which works correct.

 

However, during the movement of the bots they get stuck every now and then and shuttle between the same two waypoints.

I have no idea why they (randomly?) return to a previous waypoint - i mean... a previous waypoint can not have a lower f value, can it?

 

I am really lost here :D

Edited by Viking

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this