Thread: undef
View Single Post
  #5  
Old 07-29-2009, 06:54 PM
AndMetal
Developer
 
Join Date: Mar 2007
Location: Ohio
Posts: 648
Default

Unless you need other scripts to be able to access your variables, you should consider using my for all of your defined variables. This will cause them to be erased from memory once the script is done running (read: mob is dead).

You may actually need to declare them out of the subs so that you can access them throughout the script, but it doesn't bleed over into other scripts (potentially leaking memory). Example:

Code:
#####################################################################

### NPC ID :  2700489

### NPC NAME: Overlord_Mata_Muram

### Anguish Boss: Level 17

#####################################################################

my($BaseNumber, $Additional, $wavenum, $gap, $percent, $nextwave); #from EVENT_SPAWN

sub EVENT_SPAWN

{

  $BaseNumber = 3;                                 ### Minimin number of times to pop NPCs waves

  $Additional = 0;                                 ### and additional number for max pop NPCs waves

  $wavenum = int (rand($Additional)) + $BaseNumber + 1;  ###(3 to 3)                          

  $gap = 100;

  $gap /= int $wavenum;                            ### percentage of gap between spawns  

  $gap = int $gap;                                 ### Remove Decimal Point

  $percent = int (rand($gap));                     ### Random number in that percentage  

  $nextwave = ($gap * $wavenum) - $percent;        ### percentage - (random percentage)

  quest::setnexthpevent("$nextwave");              ### set next wave                     

} # end EVENT_SPAWN


sub EVENT_HP  

{ 

   if($hpevent == "$nextwave") {                      ### when the current HP == setnexthpevent

      if($wavenum > 0) {                              ### If waves left > 0

         $wavenum -= 1;                               ### deincrement number (-1) of waves 

         $percent = int (rand($gap));                 ### Random number in that percentage     

         $nextwave = ($gap * $wavenum) - $percent;    ### percentage - (random percentage)

         quest::say("Help!");
         my $a = 2700505;                     ### ID of Add to spawn 2 (an_ikaav_Mastermind) 2.0 Trash

         my $x = $npc->GetX();                ### Get Trash mob X

         my $y = $npc->GetY();                ### Get Trash mob Y

         my $z = $npc->GetZ();                ### Get Trash mob Z

         my $h = $npc->GetHeading();          ### Get Trash mob H

         quest::spawn2($a,0,0,$x,$y,$z,$h);   ### Spawn Add
         quest::spawn2($a,0,0,$x,$y,$z,$h);   ### Spawn Add
         quest::spawn2($a,0,0,$x,$y,$z,$h);   ### Spawn Add
         quest::spawn2($a,0,0,$x,$y,$z,$h);   ### Spawn Add
         $npc->WipeHateList();
         if($nextwave >= 0) {  

            quest::setnexthpevent("$nextwave");

            } # end $nextwave >= 0

         else {                                       ### Last wave will have a negative number

            quest::setnexthpevent(0);

            } # end else

         } # end $wavenum > 0

      } # end $hpevent == $nextwave

   } # end EVENT_HP


sub EVENT_ATTACK 
{
  my $anguish_boss_one = $entity_list->GetMobByNpcTypeID(2700469); # 1
  my $anguish_boss_two = $entity_list->GetMobByNpcTypeID(2700471); # 2
  my $anguish_boss_three = $entity_list->GetMobByNpcTypeID(2700468); # 3
  my $anguish_boss_four = $entity_list->GetMobByNpcTypeID(2700467); # 4
  my $anguish_boss_five = $entity_list->GetMobByNpcTypeID(2700464); # 5
  my $anguish_boss_six = $entity_list->GetMobByNpcTypeID(2700474); # 6
  my $anguish_boss_seven = $entity_list->GetMobByNpcTypeID(2700472); # 7
  my $anguish_boss_eight = $entity_list->GetMobByNpcTypeID(2700473); # 8
  my $anguish_boss_nine = $entity_list->GetMobByNpcTypeID(2700470); # 9
  my $anguish_boss_ten = $entity_list->GetMobByNpcTypeID(2700463); # 10
  my $anguish_boss_eleven = $entity_list->GetMobByNpcTypeID(2700466); # 11
  my $anguish_boss_twelve = $entity_list->GetMobByNpcTypeID(2700465); # 12
  my $anguish_boss_thirteen = $entity_list->GetMobByNpcTypeID(2700462); # 13
  my $anguish_boss_fourteen = $entity_list->GetMobByNpcTypeID(2700461); # 14
  my $anguish_boss_fifteen = $entity_list->GetMobByNpcTypeID(2700460); # 15
  my $anguish_boss_sixteen = $entity_list->GetMobByNpcTypeID(2700488); # 16


  if ($anguish_boss_one) { # 1
    my $hate_anguish_boss_one = $anguish_boss_one->CastToNPC();
    $hate_anguish_boss_one->AddToHateList($client, 1); }

  if ($anguish_boss_two) { # 2
    my $hate_anguish_boss_two = $anguish_boss_two->CastToNPC();
    $hate_anguish_boss_two->AddToHateList($client, 1); }

  if ($anguish_boss_three) { # 3
    my $hate_anguish_boss_three = $anguish_boss_three->CastToNPC();
    $hate_anguish_boss_three->AddToHateList($client, 1); }

  if ($anguish_boss_four) { # 4
    my $hate_anguish_boss_four = $anguish_boss_four->CastToNPC();
    $hate_anguish_boss_four->AddToHateList($client, 1); }

  if ($anguish_boss_five) { # 5
    my $hate_anguish_boss_five = $anguish_boss_five->CastToNPC();
    $hate_anguish_boss_five->AddToHateList($client, 1); }

  if ($anguish_boss_six) { # 6
    my $hate_anguish_boss_six = $anguish_boss_six->CastToNPC();
    $hate_anguish_boss_six->AddToHateList($client, 1); }
    
  if ($anguish_boss_seven) { # 7
    my $hate_anguish_boss_seven = $anguish_boss_seven->CastToNPC();
    $hate_anguish_boss_seven->AddToHateList($client, 1); }

  if ($anguish_boss_eight) { # 8
    my $hate_anguish_boss_eight = $anguish_boss_eight->CastToNPC();
    $hate_anguish_boss_eight->AddToHateList($client, 1); }

  if ($anguish_boss_nine) { # 9 
    my $hate_anguish_boss_nine = $anguish_boss_nine->CastToNPC();
    $hate_anguish_boss_nine->AddToHateList($client, 1); }

  if ($anguish_boss_ten) { # 10
    my $hate_anguish_boss_ten = $anguish_boss_ten->CastToNPC();
    $hate_anguish_boss_ten->AddToHateList($client, 1); }

  if ($anguish_boss_eleven) { # 11
    my $hate_anguish_boss_eleven = $anguish_boss_eleven->CastToNPC();
    $hate_anguish_boss_eleven->AddToHateList($client, 1); }

  if ($anguish_boss_twelve) { # 12
    my $hate_anguish_boss_twelve = $anguish_boss_twelve->CastToNPC();
    $hate_anguish_boss_twelve->AddToHateList($client, 1); }

  if ($anguish_boss_thirteen) { # 13
    my $hate_anguish_boss_thirteen = $anguish_boss_thirteen->CastToNPC();
    $hate_anguish_boss_thirteen->AddToHateList($client, 1); }

  if ($anguish_boss_fourteen) { # 14
    my $hate_anguish_boss_fourteen = $anguish_boss_fourteen->CastToNPC();
    $hate_anguish_boss_fourteen->AddToHateList($client, 1); }

  if ($anguish_boss_fifteen) { # 15
    my $hate_anguish_boss_fifteen = $anguish_boss_fifteen->CastToNPC();
    $hate_anguish_boss_fifteen->AddToHateList($client, 1); }

  if ($anguish_boss_sixteen) { # 16
    my $hate_anguish_boss_sixteen = $anguish_boss_sixteen->CastToNPC();
    $hate_anguish_boss_sixteen->AddToHateList($client, 1); }

} # End EVENT_ATTACK


sub EVENT_DEATH {

   quest::spawn2(2700493,0,0,504,4921,296,0);   ### Spawn Chest
   quest::spawn2(2700520,0,0,512,5012,297,0);   ### Spawn Chest
   quest::spawn2(2700521,0,0,543,4967,298,0);   ### Spawn Chest
   quest::spawn2(2700522,0,0,468,4971,299,0);   ### Spawn Chest
   quest::spawn2(2700523,0,0,505,4972,300,0);   ### Spawn Chest

   my $npc_name = $npc->GetCleanName();
   my $datetime = localtime();

   quest::write("Anguish_Boss_Kills.txt","$datetime -- $name killed Level 17 $npc_name.");
   quest::setglobal("killed_overlord_mata_muram","$datetime","7","F");

   #$datetime=undef; #we don't need this
   #$killed_overlord_mata_muram=undef; #we don't need this either since we don't call $killed_overlord_mata_muram anywhere



} # End EVENT_DEATH
Code:
#####################################################################

### NPC ID :  

### NPC NAME: 

### Anguish Trash 1.0

#####################################################################



sub EVENT_SPAWN {

}

sub EVENT_AGGRO {

my $Phrase1 = "For Mata Muram! Now you die!";

my $Phrase2 = "I shall rid Anguish of another infamous villain.";

my $Phrase3 = "Your foul deeds have earned my contempt.";

my $Phrase4 = "${class}s like you are better left dead than alive.";

my $Phrase5 = "It's ${races}s like you who have ruined your own lands, You'll not Anguish!";

my $Phrase6 = "Heathen! Unbeliever! Anguish must be cleansed!";

my $Phrase7 = "Your beliefs are an insult to us all!";

my $Phrase8 = "Your actions force me to kill you.";

my $Phrase9 = "Your intolerable reputation insults all in Anguish.";

my $Phrase10 = "It's time for you to take your blasphemy into the next realm.";

my $Phrase11 = "${race}s like you are better left dead than alive.";
my $Phrase12 = "No loots for you! Go away!";

my $Phrase = quest::ChooseRandom($Phrase1,$Phrase2,$Phrase3,$Phrase4,$Phrase5,$Phrase6,$Phrase7,$Phrase8,$Phrase9,$Phrase10,$Phrase11,$Phrase12);

quest::say("$Phrase");

}

sub EVENT_ATTACK {
}



sub EVENT_HP {

} 



sub EVENT_DEATH {

my $random_one = int (rand(100));                ### random_one 100 for a 3% chance
if($random_one > 96) {                         ### 3% chance spawn on death
   my $x = $npc->GetX();

   my $y = $npc->GetY();

   my $z = $npc->GetZ();

   my $random_two = int (rand(100));             ### random_two 100 for 1%, 33%, and 66% chances
   if($random_two > 33) {                     ### 66% chance spawn Chest 2700496

      quest::spawn2(2700496,0,0,$x,$y,$z,0);  ### Spawn Chest 2700496
      quest::say("Don't touch my treasures!");
      } # end if random_two
   elsif ($random_two < 1) {                  ### 1% chance spawn Rare Chest 2700491
      quest::spawn2(2700491,0,0,$x,$y,$z,0);  ### Spawn Rare Chest 2700491
      quest::say("You found my rare loot! Don't steal it!");
      } # end elsif random_two
   else {                                     ### else 33% chance spawn Named
      my $namednpc = quest::ChooseRandom(2700507,  # Shalvo
                                         2700508,  # Ofanso
                                         2700509,  # Novara
                                         2700510,  # Jansio
                                         2700511,  # Arisisi
                                         2700512,  # Laveng
                                         2700513,  # Vonaasha
                                         2700514,  # Yhinra
                                         2700515); # Uchti
      quest::spawn2($namednpc,0,0,$x,$y,$z+5,0);  ### Spawn named npc (5 higher Z)
      quest::say("My friend will avenge my death!");
      } # end else random_two
   } # end if random_one
} # End EVENT_DEATH
Try that out and see if it helps.

On a somewhat unrelated note, you may want to consider changing the sub EVENT_ATTACK section for the Overlord to use arrays & for loops to make it simpler since you're doing the same thing for each of them (like maybe 8 lines total for n number of mobs?)
__________________
GM-Impossible of 'A work in progress'
A non-legit PEQ DB server
How to create your own non-legit server

My Contributions to the Wiki
Reply With Quote