ID:179119
 
The idea was to have a bodyguard non-PC mob follow a single, certain PC from area to area in a text-based format, but not follow others who they are not intended to protect. Is it possible to have a mob follow a PC to another area?

At first I tried to make the bodyguards follow a mob with a certain name. However, that failed. So, I instead have the PC pick up an object (a medallion) which the bodyguard mobs are SUPPOSED to follow. But that doesn't work, either.

Anyhoo, here's the code...

The object to be followed:

obj/med_medal
Move()
. = ..()
for(var/mob/bodyguard/M in view())
walk_to(M,src:loc)

The mob who does the following:

proc/Object(O)
return

mob/bodyguard
contents = newlist (/obj/pistol, /obj/specs)
Object(O)
if (istype(O, /obj/med_medal))
walk_to(O, src:loc)



There are no errors that show up, however. The bodyguard mobs simply sit in the area that the PC just left and do not follow as they should. If you think there's an easier way to do this (as there must be!)please tell me!

Thanks in advance.
The reason why this doesn't work is that objects in a mob's inventory (contents) are actually at 0,0,0 so your telling your mob to follow something at 0,0,0 which it cannot do.

The easiest way to do this would be to do this:

mob
verb
Follow_Me()
for(var/mob/bodyguard/M in oview())
walk_to(src,M,0,1)

I'd use oview with this because you don't want the player to try following himself, oview excludes the center.

Then, putting the 0 in there means that the bodyguard will walk to the player until the distance between them is 0. This will never happen unless the players density is zero which means the bodyguard will follow the player until you tell it to stop.
Another problem, aside from the one mentioned below, is that the walk_to (and other movement procs) are designed to work within BYOND's map (graphical/tile) environment... your use of the words "area" and "text" leads me to believe that you're making some kind of room/node based MUD? If so, abandon all hope of using the default movement procs. In an abstract text environment, any movement is going to have to be handled using your own customized procedures for your own customized environment.
In response to Lesbian Assassin
Oh oops, I didn't notice that, good point.

In a text base environment all that stuff I said is really mute.
In response to Lesbian Assassin
Thanks for the helpful push in the right direction! Now if I can only keep going! hehe

You said that custom procs are the way to go, however, it's probably no surprise, but I'm incredibly new at this. (Probably stupid that I'm tackling such a complex dilemma so quickly, too!) Here's the proc I got...it has the same effect as the original attempt; except that it has this error: Blah.dm:62:error:mun.loc:bad var

Here's the text:

proc/Follow(mun as mob in view(0))
src.Move(mun.loc)

mob/bodyguard
contents = newlist (/obj/pistol, /obj/specs)
name = "Bodyguard"
desc = "Blah"
Follow()

This would obviously not work, but is it a step in the right direction?
In response to FattyPants

This would obviously not work, but is it a step in the right direction?

It has a couple of problems.

proc/Follow(mun as mob in view(0))

"as mob in view(0)" isn't going to have any effect on a proc... that's instructions to the client for verbs, telling it what to accept as input. The server ignores it completely... what it sees is proc/Follow(mun)

The compiler knows this, and so it tells you that there's no such thing as a mun.loc, or rather, that mun doesn't necessarily have a loc. (Blah.dm:62:error:mun.loc:bad var) The way to tell the compiler and the server that mun is a mob is to type it, like so:

proc/Follow(mob/mun)

The other problem is that this procedure, Follow(), is called exactly once. If it did work, it would move the bodyguard to mun.loc. Once. Then, there it would stay. mun may come or mun may go, but the bodyguard would remain at the spot that was mun.loc when the proc was called. You need a proc that gets called again and again, at whatever interval you want the bodyguard to notice that mun is wandering off. Having Follow() spawn() a call to itself would be the cheap way to do that.
In response to Lesbian Assassin
In the room with the bodyguard there's a verb in which mob/player can instruct all mob/bodyguard to follow him/her; but this doesn't work, either. Also, this is hopefully going to be a multi-player environment, with two to four players (a kind of interactive, semi-automatic role play realm, if you will.)

Here's the code, from proc to mob to verbs, in that order.

I used the ideas you gave, but it had the same effect on the bodyguard mob (i.e., mob/bodyguard did not move from his original, starting area).

proc/Follow(mob/player)
src.Move(locate (player.loc))
spawn()
Follow()

mob/bodyguard
contents = newlist (/obj/pistol, /obj/specs)
name = "Bodyguard"
desc = "A bodyguard."
Follow()

verb/protect()
bodyguard:Follow()
src << "You are now under bodyguard protection."

verb/S()
src << "You go south."
usr.Move(locate (/area/Newbies/Spaceport))
oview() << "[usr] exits the area, going south."

Also, of lesser importance, would this work in a multi-user condition? In other words, if another usr left the room, would the player still sitting in the room see his own name leaving?