Difference between revisions of "Manual:DIL Manual/follow()"
Jump to navigation
Jump to search
(checked against the compiler and the interpreter; example compiles) |
|||
| (2 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
| − | = follow()= | + | = follow() = |
| + | '''Procedure.''' Makes one character follow another, or stop following. | ||
| − | follow( | + | follow(ch : unitptr, leader : unitptr) |
| − | |||
| − | |||
| − | + | Makes <code>ch</code> follow <code>leader</code> at once, whatever state either is in: asleep, | |
| + | fighting, wounded. If <code>ch</code> was following someone else, that ends first. With | ||
| + | <code>leader</code> null, <code>ch</code> stops following. It is what the <code>follow</code> | ||
| + | command in commands.zon uses, and how the deputies in midgaard.zon lead a cuffed prisoner away. | ||
| + | |||
| + | == Parameters == | ||
| + | {| class="wikitable" | ||
| + | ! Name !! Type !! Meaning | ||
| + | |- | ||
| + | | ch || unitptr || The character who follows. | ||
| + | |- | ||
| + | | leader || unitptr || The character to follow, or null to stop following. | ||
| + | |} | ||
| + | |||
| + | == Notes == | ||
| + | * '''Stop following only someone who follows.''' <code>follow(ch, null)</code> when | ||
| + | <code>ch</code> has no master (or is not a character) stops the server. Test | ||
| + | <code>ch.master != null</code> first. A failed <code>leader</code> (a field of null) counts | ||
| + | as null. | ||
| + | * When both are characters, <code>ch</code> loses the group flag (<code>CHAR_GROUP</code>) and | ||
| + | gets the <code>dilfollow@basemove</code> program, which tells it "You now follow ..." and | ||
| + | walks it after the leader. An <code>SFB_DONE</code> "follow" event is sent with | ||
| + | <code>ch</code> as activator and the leader as target. The leader is told nothing. | ||
| + | * When <code>leader</code> is given but either of them is not a character, nothing happens. | ||
| + | * There is no check for circles: don't make a leader follow their own follower. | ||
| + | |||
| + | == Example == | ||
| + | <pre> | ||
| + | dilbegin lead_away(prisoner : unitptr); | ||
| + | code | ||
| + | { | ||
| + | if (prisoner.type != UNIT_ST_PC) | ||
| + | quit; | ||
| + | act("$1n takes $3n by the arm.", A_SOMEONE, self, null, prisoner, TO_NOTVICT); | ||
| + | act("$1n takes you by the arm.", A_SOMEONE, self, null, prisoner, TO_VICT); | ||
| + | follow(prisoner, self); | ||
| + | quit; | ||
| + | } | ||
| + | dilend | ||
| + | |||
| + | dilbegin let_go(prisoner : unitptr); | ||
| + | code | ||
| + | { | ||
| + | if (prisoner.master != null) | ||
| + | follow(prisoner, null); | ||
| + | quit; | ||
| + | } | ||
| + | dilend | ||
| + | </pre> | ||
| + | A guard makes a prisoner follow him, and later lets go only if the prisoner still follows | ||
| + | someone. | ||
| + | |||
| + | == See also == | ||
| + | * [[Manual:DIL Manual/master|master]] | ||
| + | * [[Manual:DIL Manual/follower|follower]] | ||
| + | * [[Manual:DIL Manual/getfollower()|getfollower()]] | ||
| + | * [[Manual:DIL Manual/followercount|followercount]] | ||
Latest revision as of 23:21, 14 November 2026
follow()
Procedure. Makes one character follow another, or stop following.
follow(ch : unitptr, leader : unitptr)
Makes ch follow leader at once, whatever state either is in: asleep,
fighting, wounded. If ch was following someone else, that ends first. With
leader null, ch stops following. It is what the follow
command in commands.zon uses, and how the deputies in midgaard.zon lead a cuffed prisoner away.
Parameters
| Name | Type | Meaning |
|---|---|---|
| ch | unitptr | The character who follows. |
| leader | unitptr | The character to follow, or null to stop following. |
Notes
- Stop following only someone who follows.
follow(ch, null)when
chhas no master (or is not a character) stops the server. Testch.master != nullfirst. A failedleader(a field of null) counts as null.
- When both are characters,
chloses the group flag (CHAR_GROUP) and
gets thedilfollow@basemoveprogram, which tells it "You now follow ..." and walks it after the leader. AnSFB_DONE"follow" event is sent withchas activator and the leader as target. The leader is told nothing.
- When
leaderis given but either of them is not a character, nothing happens. - There is no check for circles: don't make a leader follow their own follower.
Example
dilbegin lead_away(prisoner : unitptr);
code
{
if (prisoner.type != UNIT_ST_PC)
quit;
act("$1n takes $3n by the arm.", A_SOMEONE, self, null, prisoner, TO_NOTVICT);
act("$1n takes you by the arm.", A_SOMEONE, self, null, prisoner, TO_VICT);
follow(prisoner, self);
quit;
}
dilend
dilbegin let_go(prisoner : unitptr);
code
{
if (prisoner.master != null)
follow(prisoner, null);
quit;
}
dilend
A guard makes a prisoner follow him, and later lets go only if the prisoner still follows someone.