Poison spitting creature 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: Poison spitting creature script
Shock Trooper
Member # 4180
Profile #0
There are probably some optimizations that can be made to this (I'm an Avernumscript noob), but it should be pretty safe and generic. Enjoy! :)

// cpoisonspit.txt
// Much like basicnpc, but creature spits poison every other round at anyone in the
// party in an adjacent and visible location. Also includes logic for granting an optional
// special item after a number of these cretures specified in Memory Cell 4 have died.
// Memory Cells:
// Cell 0 - How creature moves.
// 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. Otherwise when each of these dies,
// flag is incremented.
// Cell 3 - Dialogue node to start with if talked to. if left at 0, this
// character doesn't talk.
// Cell 4 - Number of these things to die before a special item is granted. If 0, no
// special item is granted.
// Cell 5 - Special item to grant on death.
// Cell 6 - Number of dice for poison damage
// Cell 7 - Size of dice for poison damage

begincreaturescript;

variables;

short i, target, last_abil_time, distance, max;

body;

beginstate INIT_STATE;
if (get_memory_cell(0) == 2)
set_mobility(ME, 0);
last_abil_time = get_current_tick(); // uesd to determine when to spit poison
break;

beginstate DEAD_STATE;
// Increment the appropriate stuff done flag for this character being dead
if ((get_memory_cell(1) != 0) || (get_memory_cell(2) != 0)) {
inc_flag(get_memory_cell(1), get_memory_cell(2), 1);

if (get_memory_cell(4) != 0 && (get_memory_cell(4) ==
get_flag(get_memory_cell(1), get_memory_cell(2)))) {
// only want to do this after specified number of these die
// give the special item
change_spec_item(get_memory_cell(5), 1);

// make it more obvious to the player that a special item was found
play_sound(0); // high beep
message_dialog("Your message here...",
"(You have gained a special item. Check the Character Info screen to examine it.)");
}
}
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);
}

// Otherwise, 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);
}

// 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);

// time to spit more poison?
if (tick_difference(last_abil_time, get_current_tick()) > 1) {
max = party_size();
i = 0;
while (i < max) { // loop through party
distance = char_dist_to_loc(i, my_loc_x(), my_loc_y()); // how close is this char?
if (distance == 1 && (can_see_char(i) == TRUE)) {
print_named_str(ME, " spits poison!");
play_sound(42); // acid spray -- close enough for poison, I reckon ;)
damage_char(i, get_ran(get_memory_cell(6), 1, get_memory_cell(7)), 2);
}
i = i + 1;
}
last_abil_time = get_current_tick();
}

do_attack();
break;

beginstate TALKING_STATE;
if (get_memory_cell(3) == 0) {
print_str("Talking: It doesn't respond.");
end();
}
begin_talk_mode(get_memory_cell(3));
break;
-spyderbytes

[ Monday, April 05, 2004 22:09: Message edited by: spyderbytes ]

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