-
Notifications
You must be signed in to change notification settings - Fork 221
Pathfind fix for NPC/MOB and poor old Novalmauge #548
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General question: I assume that setting speed to 0 actually does cease movement and doesn't cause sliding? I remember that being a question in #319
• Addition of npcBasicPath to pathfind.lua, this pathfind function requires paths to be set in a linear fashion like this example local path = { [1] = {1.000, 2.000, 3.000}, [2] = {2.000, 2.000, 3.000}, [3] = {3.000, 2.000, 3.000}, [4] = {2.000, 2.000, 3.000} } This way the path returns to the origin from the last path point to the first, i.e a circle. the npcBasicPath will keep track of what path point the npc is on by the newly added m_pathPoint in npcentity. • As stated above i have added a m_pathPoint to npcentity and given the the entity a getter and setter to help keep track of the npc's path. • Adjusted Novalmauge's script to reflect the changes. Changed setPathPoint to use uint16 rather than uint8 Stupid tabs Pathing adjustments • Added the ability to pass rotations • Moved m_pathPoint to baseEntity
• Addition of npcBasicPath to pathfind.lua, this pathfind function requires paths to be set in a linear fashion like this example local path = { [1] = {1.000, 2.000, 3.000}, [2] = {2.000, 2.000, 3.000}, [3] = {3.000, 2.000, 3.000}, [4] = {2.000, 2.000, 3.000} } This way the path returns to the origin from the last path point to the first, i.e a circle. the npcBasicPath will keep track of what path point the npc is on by the newly added m_pathPoint in npcentity. • As stated above i have added a m_pathPoint to npcentity and given the the entity a getter and setter to help keep track of the npc's path. • Adjusted Novalmauge's script to reflect the changes.
• Added the ability to pass rotations • Moved m_pathPoint to baseEntity
Added new pathing options for entity's First up: pathfind.lua, probly quicker to look at the commenting than me explain that, changed amost npc's that use pathing to use either basicPath or advancedPath, the advancedPath is the one that stands out as this allows the entity to pass id text and npc id's to automatically look at or speak at a a point in the path, and each point can have a delay. Added random pathing for the bunnies in Khazam, as they just sat there. I kept everything the same where i could, but i did have to redo some paths, but that let me cut down on path points also.
• Added a new binding rotateToAngle(), rotates an entity to a given angle, NOTE: must not be moving. • added the ability to add extra params to a path point when using tpz.path.general, example: basic point {x,y,z} point with a delay {x,y,z {delay = 10}} point with delay and rotation {x,y,z, {rot = 35, delay = 10} point with a rotation only {x,y,z {rot = 120}}, in this case a small delay will automatically be set so the rotation can be applied. • Updated all npc's that now use the new lua path functions and tested them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, it all looks good. There are some styling things I'd like to see fixed and in an ideal world, this would have been much easier to go through and review if you had split out the commits to be logic changes, whitespace/semicolon changes, tabling changes etc.
Sick work 👍
local path = | ||
{ | ||
20.6, 0, -23, | ||
46, 0, -19, | ||
53.5, -1.8, -19, | ||
61, -1.1, -18.6, | ||
67.3, -1.5, -18.6, | ||
90, -0.5, -19 | ||
}; | ||
{20.600, -0.343, -23.000, {delay = 5}}, | ||
{35.431, -0.045, -20.227}, | ||
{51.795, -1.790, -18.843}, | ||
{58.037, -0.957, -18.724}, | ||
{65.919, -1.722, -18.767}, | ||
{92.143, -0.451, -16.231, {delay = 5}}, | ||
{65.919, -1.722, -18.767}, | ||
{58.037, -0.957, -18.724}, | ||
{51.795, -1.790, -18.843}, | ||
{35.431, -0.045, -20.227}, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section really nicely highlights the benefits of this PR!
|
||
function onPath(npc) | ||
tpz.path.general(npc, path, tpz.path.flag.WALLHACK, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this "in the wild", I wonder if general
is really the right name for the default, regular, general call?
Now that I say the other options, I guess it's as good as all the others 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe refactor to tpz.pathing.path()
, I don't know how much work that would be?
{44.000, -11.000, -176.000}, | ||
{47.000, -11.000, -179.500}, | ||
{44.000, -11.000, -177.000}, | ||
{40.500, -11.000, -179.500}, | ||
{39.500, -11.000, -176.500}, | ||
{41.300, -11.000, -172.300}, | ||
{45.000, -11.000, -171.300}, | ||
{46.000, -11.000, -173.600}, | ||
{42.700, -11.000, -174.300}, | ||
{44.000, -11.000, -179.800}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope you were able to automate this process and didn't have to manage all these tables by hand...
int32 pathThrough(lua_State* L); // walk at normal speed through the given points | ||
int32 isFollowingPath(lua_State* L); // checks if the entity is following a path | ||
int32 isFollowingPath(lua_State* L); | ||
int32 rotateToAngle(lua_State* L); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Theres some borked tab indents around here
I think you've taken care of all semicolons and random things in Lua, but if you could take a merge of release just to be sure that would be grand |
{ | ||
auto PNpc = static_cast<CNpcEntity*>(m_PBaseEntity); | ||
uint32 npcID = PNpc->id; | ||
const char* NPCQuery = "SELECT speed FROM npc_list WHERE npcid = %u"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not store the original speed in a localVar instead of re-querying the database?
You can actually get and set localVars from the C++ side too, not just in lua.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For NPCs we could try having the event code itself stop and restart NPC movement. since m_event.target
is the NPC entity itself. Mobs we'd still need a script command for stop/start.
TPZ_DEBUG_BREAK_IF(m_PBaseEntity == nullptr); | ||
TPZ_DEBUG_BREAK_IF(m_PBaseEntity->objtype == TYPE_PC); | ||
|
||
CBattleEntity* PBattle = (CBattleEntity*)m_PBaseEntity; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
m_PBaseEntity->speed = 0;
actually does work, no need to recast as a battleentity for either mobs or npc's (or players). Which makes this entire function in its current form a duplicate of speed()
Lets improve it by having this function also store the entities current speed to a localVar prior to setting it zero. Then resume path can read that value instead of querying the database every time.
m_PBaseEntity->SetLocalVar(lua_tostring(L, 1), (uint64_t)lua_tointeger(L, 2));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want to place all these in an issue or ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not particularly no. I'd rather see it be changed here and its such a small correction to make instead of unnecessarily adding more iops of our inefficient db connection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think @Wiggo32 had some things to say about this, putting on hold until they can chime in
• Addition of npcBasicPath to pathfind.lua, this pathfind function requires paths to be set in a linear fashion like this example
local path =
{
[1] = {1.000, 2.000, 3.000},
[2] = {2.000, 2.000, 3.000},
[3] = {3.000, 2.000, 3.000},
[4] = {2.000, 2.000, 3.000}
}
This way the path returns to the origin from the last path point to the first, i.e a circle.
the npcBasicPath will keep track of what path point the npc is on by the newly added m_pathPoint in npcentity.
• As stated above i have added a m_pathPoint to npcentity and given the the entity a getter and setter to help keep track of the npc's path.
• Adjusted Novalmauge's script to reflect the changes.
He's walk animation still seems a bit buggy but its about as good as i could get it.
But atleast it shouldn't crash the server anymore.
This should fix the following bug
Novalmauge causes server crash due to pathing. #493
I affirm: