Garrulous Glaahk spyderbytes Posted April 7, 2004 Share Posted April 7, 2004 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. Code: // 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 messengerbreak;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. Link to comment Share on other sites More sharing options...
Garrulous Glaahk Isaac Posted April 7, 2004 Share Posted April 7, 2004 Depending on the circumstance, you might want the messenger to start a conversation without the player's initiative. For example, instead of this: Code: 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: Code: // 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)); } } Link to comment Share on other sites More sharing options...
Garrulous Glaahk spyderbytes Posted April 7, 2004 Author Share Posted April 7, 2004 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 Link to comment Share on other sites More sharing options...
Garrulous Glaahk Isaac Posted April 7, 2004 Share Posted April 7, 2004 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. Link to comment Share on other sites More sharing options...
Garrulous Glaahk spyderbytes Posted April 7, 2004 Author Share Posted April 7, 2004 Yes, I definitely found Kharl irritating, to say the least. 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 Link to comment Share on other sites More sharing options...
Recommended Posts