This is an unfinished example of how you can easily add a lot of flavor to any generic NPC with scripting alone. I wrote it years ago and never did much with it, so I thought I'd share to maybe help spark some creativity.
(a_cave_rat.pl @ tutorialb)
Code:
my %instance = ();
sub AI_YellForHelp
{
my $npc_num = substr($npc->GetName(),-3);
my $signal = scalar 911 . scalar 0 . scalar $instance{$npc_num} . scalar 0 . scalar $npc_num;
# tell a_cave_rat which variant is yelling for help.
quest::signalwith(189453,$signal);
}
sub EVENT_SPAWN
{
# ==== HIDDEN (GENDER) NPC VARIATION ==== #
# 0 = female
# 1 = male
# 2 = adolescent
my $variant = int(rand(3));
my $npc_num = substr($npc->GetName(),-3);
$instance{$npc_num} = $variant;
# ==== VISIBLE (SIZE) NPC VARIATION ==== #
my $SizeMult = sub { .01 * ( $_[0] + int rand $_[1] - $_[0] ) };
# randomly changes size by percentage mutiples in range provided
# (example below is between 75% to 125% of original size)
$npc->ChangeSize( $npc->GetSize() * $SizeMult->(75, 125) );
}
sub EVENT_ATTACK
{
$client->Message(7, "You have a strange feeling this might not end well...");
quest::setnexthpevent(50);
}
sub EVENT_HP
{
if($hpevent == 50)
{
# 25% chance to call for help
if(int(rand(100) >= 75)
{
quest::emote("squeaks loudly.");
AI_YellForHelp();
}
}
}
sub EVENT_SIGNAL
{
my $strSignal = scalar $signal;
if (length $strSignal == 9 && substr($strSignal, 0, 3) == 911)
{
my $otherType = int(substr($strSignal, 4, 1));
my $otherNumber = substr($strSignal, 6, 3);
my $myNumber = substr($npc->GetName(),-3);
my $myType = $instance{$myNumber};
# TO DO: implement range/LOS check.
if($npc->IsEngaged())
{
quest::shout("DEBUG: $myNumber is busy and can't help $");
}
# we got a request for help from variant 0 (female)
elsif($otherType == 0 && $myType == 1)
{
# TO DO: assist if male (%75).
quest::shout("DEBUG: $myNumber is thinking about helping (0->1 @ 75%)");
}
# we got a request for help from variant 1 (male)
elsif($otherType == 1 && $myType == 1)
{
# TO DO: assist if male (50%).
quest::shout("DEBUG: $myNumber is thinking about helping (1->1 @ 50%)");
}
# we got a request for help from variant 2 (adolescent)
elsif($otherType == 2)
{
if($myType == 0)
{
# TO DO: assist if female (100%).
quest::shout("DEBUG: $myNumber is thinking about helping (2->0 @ 100%)");
}
elsif($myType == 2)
{
# TO DO: assist if adolescent (25%).
quest::shout("DEBUG: $myNumber is thinking about helping (2->2 @ 25%)");
}
}
}
}
sub EVENT_DEATH
{
# delete dead rat's instance data
my $npc_num = substr($npc->GetName(),-3);
delete($instance{$npc_num});
}