• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Adding Roaming Monsters

Homeslice

-anoyn/Rage the Mage
Joined
May 9, 2010
Messages
112
Solutions
2
Reaction score
66
Location
Canada
I'm planning creating functionality for roaming (pathing) monsters. monsters with roaming data would walk through a series of positions attacking any players seen during their trek.

I have not spent much time working on OTs so I am not familiar what/where/when to use specific functions.

Would this be possible to write in Lua alone or with limited source modifications?

Any tips on what functions may come in handy?

I understand this could get pretty laggy if there are too many roaming monsters. Nevertheless I haven't seen a server with this before and It would be a cool addition to OTs.
 
Last edited:
Worked a little on this.
I've got hardcoded lua, going to a position working by adding this creature:moveTo and changing the MAX_NODES in the built in a* pathfinding.

The plan so far is to store path IDs in the spawnevents in each raid xml file which will be stored in the creature in c++. I will try to add an CreatureOnSpawn through C++.

In the lua onSpawnEvent when creatures are spawned I will only need to check if the monster has a pathID, then use addEvents to control moving to the next position in path, despawning at end of path and etc.

So far my only question is how I can make onSpawnCreature get called for all monsters without needing to add the script callback/event to every monster file.
 
What distro are you using?
I believe onSpawn exists in TFS 0.4
Have you considered onStartup(), in globalevents?
 
I plopped that in

Monster::Monster(MonsterType* mtype) :

Now onSpawn is called without specifying script for every creature xml

Thanks for your help
 
ySEgg8H.gif


So i managed to finish this idea with most of the code in lua.

The majority of C++ changes were for adding luascript functions: getFirstPath, removeFirstPath, moveTo, onSpawn and isMapWalking
ySEgg8H.mp4
 
I made A* path-finding to monsters about almost 2 years ago only using a Lua.
However the c++ version is way better, because source can overwrite the lua commands, which cause weird monster movements.

What does your luascript functions return or do?
What are your monsters looking for or you can specify it? positions, monsters, items, players?
 
This is amazing, would be a huge contribute to community if released and easy to configurate to fit what ever you like it to.
i would be interested in a code like this for sure.
 
QjeCf63.gif


I made A* path-finding to monsters about almost 2 years ago only using a Lua.
However the c++ version is way better, because source can overwrite the lua commands, which cause weird monster movements.

What does your luascript functions return or do?
What are your monsters looking for or you can specify it? positions, monsters, items, players?

Lua functions:
number creature:getFirstPath() - returns creatures first path
creature:removeFirstPath() - removes first path from the creatures path list
creature:moveTo() - pulled from here
bool creature:isMapWalking() - c++ return listWalkDir.empty() == false;
onSpawn is a creature event, where i check whether the monster has a path to run

I had to modify logic in c++ aswell so attacking and lua pathing work together. Such as:
If creature has pathID but cannot get to target then do not reset listWalkDir (It previously always reset listWalkDir if creature has a target)

"What are the monsters looking for?"
In c++, Well they go to a position.
if a monster comes on screen and the creature can get a path to him to attack he paths to the monster instead of the path position. Once the monster is dealt with or unreachable they continue going to the path position.

Its simpler in lua, if they aren't map walking to anything and aren't beside their target then move to path again. (This should take into account ranged creatures but it dosen't atm, currently they switch between going to attack spot to pathing)

This is amazing, would be a huge contribute to community if released and easy to configurate to fit what ever you like it to.
i would be interested in a code like this for sure.

This is how the config looks:
raid xml file
Code:
    <!--South Spawn Green-->
    <areaspawn delay="2000" fromx="1056" fromy="1106" fromz="7" tox="1072" toy="1118" toz="7" pathids="1,8,9,3">
        <monster name="Bug" amount="2" />
    </areaspawn>

    <!--East Spawn Gray-->
    <areaspawn delay="2000" fromx="1074" fromy="1084" fromz="7" tox="1090" toy="1097" toz="7" pathids="26,20,21,27">
        <monster name="Slime" amount="2" />
    </areaspawn>

pathing.lua
Lua:
paths = {
    [1] = { --intiri_wolf_raid - SW of intiri to intiri south gate
        positions = {
            [1] = { from = {x = 943, y = 1112, z = 7}, to = {x = 952, y = 1120, z = 7} },
            [2] = { from = {x = 954, y = 1100, z = 7}, to = {x = 969, y = 1106, z = 7} },
            [3] = { from = {x = 969, y = 1082, z = 7}, to = {x = 982, y = 1092, z = 7} },
            [4] = { from = {x = 986, y = 1075, z = 7}, to = {x = 996, y = 1079, z = 7} },
        },
        floor = 7,
        despawnAfter = false,
    },
    [2] = { -- intiri_wolf_raid - intiri south gate to SW of intiri
        backwardsPathID = 1,
        despawnAfter = true,
    },
}

I'm thinking of adding callback functions for paths, so when a creature reaches the end of a path you can do things like broadcast "They have entered the town" etc.

I don't have plans to make a tutorial (time). But if my server flops or I give up on it, I will give out the git repository for my server where you can see all my changes.
 
Last edited:
No longer working on OT's, but yeah also solved the weird behavior by changing the way sourcecode a bit
 
Back
Top