Simple messenger script

Error message

Deprecated function: implode(): Passing glue string after array is deprecated. Swap the parameters in drupal_get_feeds() (line 394 of /var/www/pied-piper.ermarian.net/includes/common.inc).
AuthorTopic: Simple messenger script
Shock Trooper
Member # 4180
Profile #0
Here's a script for a simple messenger NPC. This NPC will follow the party, at a distance specified in memory cell 4, and occasionally put up a text bubble saying "Psst! I want to talk to you!". If/when the party speaks to the NPC, a flag specified in memory cells 1 and 2 is set and the NPC reverts to standard behavior (as per basicnpc).

Pretty basic stuff, but someone who doesn't know how to script might find it useful. :)

// cmessenger.txt
// A simple creature that follows the party until his message is delivered.
// After that, his behavior is identical to basicnpc.
// Memory Cells:
// Cell 0 - How creature moves after delivering his message.
// 0 - If 0, wander randomly.
// 1 - Stands still until a target appears.
// 2 - Completely immobile, even if target appears.
// Cell 1,2 - Stuff done flag. If both 0, nothing (and messenger will continue
// following the party forever). Otherwise when the message
// is deliverd this is set to 1. (Example: If cell 1 is 3 and cell 2 is 5, when
// message is delivered, sets SDF(3,5) to 1.)
// Cell 3 - Dialogue node to start with if talked to. If left at 0, this
// character doesn't talk, and will just follow the party forever.
// Cell 4 - How closely to follow party.
// Cell 5 - Messenger behavior. If 0, messenger follows and politely waits for the
// player to initiate dialog. If 1, messenger initiates dialog as soon as he is
// within the range specified in Cell 4.

begincreaturescript;

variables;

short i,target,near;

body;

beginstate INIT_STATE;
// our creature is always mobile to start with, so remove mobility check present
// in basicnpc
break;

beginstate DEAD_STATE;
// by default, nothing to do here for a messenger
break;

beginstate START_STATE;
// if I have a target for some reason, go attack it
if (target_ok()) {
if (dist_to_char(get_target()) <= 16)
set_state(3);
else set_target(ME,-1);
}

// Look for a target, attack it if visible
if (select_target(ME,8,0)) {
do_attack();
set_state(3);
}

// Have I been hit? Strike back!
if (who_hit_me() >= 0) {
set_target(ME,who_hit_me());
do_attack();
set_state(3);
}

if ((get_memory_cell(1) != 0 || get_memory_cell(2) != 0) && (get_flag(get_memory_cell(1),
get_memory_cell(2)) == 1)) { // message already delivered
// Just peacefully move around. Go back to start, if I'm too far
// from where I started.
if ((my_dist_from_start() >= 6) || ((my_dist_from_start() > 0) &&
(get_memory_cell(0) > 0))) {
if (get_ran(1,1,100) < 40)
return_to_start(ME,1);
}
else if (get_memory_cell(0) == 0) {
fidget(ME,25);
}
} else {
// just follow party. If we're within range, either fidget or put up a text bubble
near = maintain_dist_to_char(ME, 0, get_memory_cell(4));
if (near == TRUE) { // already within range, didn't need to move
if (get_memory_cell(5) == 1) { // initiate dialog as soon as we're within range
if (get_memory_cell(1) != 0 || get_memory_cell(2) !=0)
set_flag(get_memory_cell(1), get_memory_cell(2), 1);
begin_talk_mode(get_memory_cell(3));
} else { // politely wait for the player to initiate dialog
if (get_ran(1,1,100) < 60) {
text_bubble_on_char(ME, "Psst! I want to talk to you!");
} else {
fidget(ME,10);
}
}
}
}

// if we're in combat and the above didn't give me anything to do, just
// stop now. Otherwise, game will keep running script, and that eats up CPU time.
if (am_i_doing_action() == FALSE)
end_combat_turn();
break;

beginstate 3; // attacking
if (target_ok() == FALSE)
set_state(START_STATE);
do_attack();
break;

beginstate TALKING_STATE;
if (get_memory_cell(3) == 0) {
print_str("Talking: It doesn't respond.");
end();
}
// talking, so we can deliver our message... set the flag
if (get_memory_cell(5) != 1 && (get_memory_cell(1) != 0 || get_memory_cell(2) !=0))
set_flag(get_memory_cell(1), get_memory_cell(2), 1);
begin_talk_mode(get_memory_cell(3));
break;
-spdyerbytes

EDIT: Changed script to affect messenger behavior, as suggested by Isaac, depending on the value of memory cell 5. If Cell 5 is 0, the messenger follows and waits politely for the player to initiate dialog. If Cell 5 is 1, the messenger will initiate dialog as soon as he is within the distance specified in Cell 4.

[ Wednesday, April 07, 2004 01:58: Message edited by: spyderbytes ]

--------------------
-spyderbytes
Posts: 200 | Registered: Wednesday, March 31 2004 08:00
Warrior
Member # 4202
Profile Homepage #1
Depending on the circumstance, you might want the messenger to start a conversation without the player's initiative. For example, instead of this:
if (get_ran(1,1,100) < 60) {
text_bubble_on_char(ME, "Psst! I want to talk to you!");
} else {
fidget(ME,10);
}
use this:
// talking, so we can deliver our message... set the flag
if (get_memory_cell(1) != 0 || get_memory_cell(2) !=0) {
if(get_flag(get_memory_cell(1), get_memory_cell(2) == 0) {
set_flag(get_memory_cell(1), get_memory_cell(2), 1);
begin_talk_mode(get_memory_cell(3));
}
}


[ Wednesday, April 07, 2004 01:00: Message edited by: Isaac ]

--------------------
Creator of the 3D Blades of Avernum Editor for Mac. Get it at Ingenious Isaac's Illusion, my web page. Better yet, get Battle for Wesnoth, a wonderful free TBS game.
Posts: 192 | Registered: Sunday, April 4 2004 08:00
Shock Trooper
Member # 4180
Profile #2
Sure, that'd work. :) I just (personally) tend to hate having initiative taken away from me, as a player, unless there's a DURN good reason for it. ;) Still, I could see circumstances where there just might be a durn good reason for it. :)

When I get a few spare moments, maybe I'll code an alternative that either waits politely or interrupts, based on the value of a memory cell, and replace the script in the first post with it.

-spyderbytes

--------------------
-spyderbytes
Posts: 200 | Registered: Wednesday, March 31 2004 08:00
Warrior
Member # 4202
Profile Homepage #3
As an intermediate approach, Kharl in Sweetgrove starts a conversation with you, saying only that he wants you to come and talk to him. Unfortunately, since he does this every time I enter town, it's quite annoying. My approach at least takes care of that.

--------------------
Creator of the 3D Blades of Avernum Editor for Mac. Get it at Ingenious Isaac's Illusion, my web page. Better yet, get Battle for Wesnoth, a wonderful free TBS game.
Posts: 192 | Registered: Sunday, April 4 2004 08:00
Shock Trooper
Member # 4180
Profile #4
Yes, I definitely found Kharl irritating, to say the least. :D

I made your suggested change, Isaac, as an alternative behavior based on the value of memory cell 5, and edited the first post with it.

-spyderbytes

--------------------
-spyderbytes
Posts: 200 | Registered: Wednesday, March 31 2004 08:00