mob/player
Move(loc, dir = 0)
if(busy)
return // Prevent movement (player is busy).
if(..(loc, dir))
if(pet)
// Add current position to queue.
movement_queue += list(x, y, z)
if(movement_queue.len > 10) // Limit the queue length.
movement_queue.Cut(1, 1)
// Call follow_path if not following.
if(!pet.following)
pet.following = TRUE
spawn() pet.follow_path()
// Proc to follow the player's path
mob/pet
proc/follow_path()
if(owner.movement_queue.len > 0)
var/list/coords = owner.movement_queue[1] // Get the oldest set of coordinates.
owner << "Processing coords: [coords]" //Debug output
owner.movement_queue.Cut(1, 1) // Remove the first set from the queue.
if(islist(coords) && coords.len == 3) // Ensure the coordinates list has the correct length.
var/x = coords[1]
var/y = coords[2]
var/z = coords[3]
if(src.loc != locate(x, y, z))
owner << "Pet moving to: ([x], [y], [z])" //Debug output
step_to(src, locate(x, y, z))
spawn(2) follow_path() // Call the proc again after a delay.
else
owner << "Invalid coords length or not a list: [coords]" //Debug output
following = FALSE
return
else
owner << "Finished processing movement queue" //Debug output
Problem description:
The debug messages are output:
Finished processing movement queue
Processing coords: 3
Invalid coords length or not a list: 3
The problem is that the pet does not follow the player. I am positive I have mangled the code at this point. The goal was to make the pet follow the owner's exact path of movement.
Example: If the owner if moving EAST 1 tile and decides to move NORTH 1; The pet should still move EAST 1 tile in order to remain behind the owner. It's a way of mimicking the owner's steps.
I don't expect a 100% fix from anyone, but pointing me in the right direction would be greatly appreciated.
This isn't doing what you think it is. This is actually adding 3 items to the movement_queue. Adding list b to list a adds all the items in list b to the end of list a instead of the list itself.
What you want is:
So the other issue is essentially that you are trying to move the monster to the position the player just moved to, instead of the position the player just moved from. You want to cache their x,y,z before the movement, and then append it to the queue.
Honestly, if you want a proper teardown of this whole thing, it's pretty overcomplicated. What we're gonna do is add a global ticker to handle the follower logic and build it into the root /mob type using reference ids so that garbage collection can still happen like it should and so we don't pollute any savefiles on accident.