Advertisement
Guest User

Untitled

a guest
Oct 12th, 2019
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 9.71 KB | None | 0 0
  1. # Name: Race Modeler
  2. # Date: October 12, 2019
  3. # Author: Kinglykrab
  4.  
  5. # NPC Code
  6. my @npc_ids = (2000911..2000960); # Must contain 50 Model NPC IDs in sequential order
  7. my $first_npc_id = $npc_ids[0]; # First Model NPC ID
  8. my %race_viewer_options = ( # Option Choice => 50 Race ID Array
  9.     0 => [1..50],
  10.     1 => [51..100],
  11.     2 => [101..150],
  12.     3 => [151..200],
  13.     4 => [201..250],
  14.     5 => [251..300],
  15.     6 => [301..350],
  16.     7 => [351..400],
  17.     8 => [401..450],
  18.     9 => [451..500],
  19.     10 => [501..550],
  20.     11 => [551..600],
  21.     12 => [601..650],
  22.     13 => [651..700],
  23.     14 => [701..732]
  24. );
  25. my @texture_options = (0..16); # Texture Options Array
  26. my @gender_options = (0..2); # Gender Options Array
  27. my @weapon_options = (0..4, 100..201, 228..310, 350, 351); # Weapon Options Array
  28. sub EVENT_SAY {
  29.     if ($text=~/Hail/i) {
  30.         if (!$entity_list->GetNPCByNPCTypeID($first_npc_id)) { # Check the entity list for the first Model NPC by NPC ID
  31.             plugin::Whisper("Hail $name, would you like to " . quest::saylink("spawn", 1) . " the model NPCs?");
  32.         } else { # Send the Modeler Options
  33.             plugin::Message("Modeler Options");
  34.             plugin::Message(quest::saylink("View $_", 1, "$_")) for ("Race", "Texture", "Gender", "Weapon");
  35.         }
  36.     } elsif ($text=~/^View Race$/i) { # View Race Option Choices
  37.         plugin::Message("------------------------- Race Options -------------------------");
  38.         foreach my $race_option (sort {$a <=> $b} keys %race_viewer_options) {
  39.             my @races = @{$race_viewer_options{$race_option}};
  40.             plugin::Message("[Races $races[0] to $races[$#races]] " . quest::saylink("option r $race_option", 0, "Race Option $race_option"));
  41.         }
  42.         plugin::Message("------------------------- Race Options -------------------------");
  43.     } elsif ($text=~/^View Gender$/i) { # View Gender Option Choices
  44.         plugin::Message("------------------------- Gender Options -------------------------");
  45.         foreach my $gender_option (@gender_options) {
  46.             plugin::Message(quest::saylink("option g $gender_option", 0, "Gender Option $gender_option"));
  47.         }
  48.         plugin::Message("------------------------- Gender Options -------------------------");
  49.     } elsif ($text=~/^View Texture$/i) { # View Texture Option Choices
  50.         plugin::Message("------------------------- Texture Options -------------------------");
  51.         foreach my $texture_option (@texture_options) {
  52.             plugin::Message(quest::saylink("option t $texture_option", 0, "Texture Option $texture_option"));
  53.         }
  54.         plugin::Message("------------------------- Texture Options -------------------------");
  55.     } elsif ($text=~/^View Weapon$/i) { # View Weapon Option Choices
  56.         plugin::Message("------------------------- Weapon Options -------------------------");
  57.         foreach my $weapon_option (@weapon_options) {
  58.             my $min_model = plugin::commify(($weapon_option * 100) + 1);
  59.             my $max_model = plugin::commify(($weapon_option * 100) + 100);
  60.             plugin::Message("[Models $min_model to $max_model] " . quest::saylink("option w $weapon_option", 0, "Weapon Option $weapon_option"));
  61.         }
  62.         plugin::Message("------------------------- Weapon Options -------------------------");
  63.     } elsif ($text=~/^Spawn$/i) { # Spawn Model NPCs
  64.         SpawnNPCs();
  65.         plugin::Message("Modeler Options"); # Send the Modeler Options
  66.         plugin::Message(quest::saylink("View $_", 1, "$_")) for ("Race", "Texture", "Gender", "Weapon");
  67.     } elsif ($text=~/^Option/i) {
  68.         if (!$entity_list->GetNPCByNPCTypeID($first_npc_id)) { # Check the entity list for the first Model NPC by NPC ID
  69.             plugin::Message("Must spawn NPCs using Spawn Option first.");
  70.             return;
  71.         }
  72.        
  73.         if (length(substr($text, 7)) > 0) { # Check if player has specified a Modeler Option
  74.             my ($option_type, $option_choice) = split(/ /, substr($text, 7));
  75.             if ($option_type ~~ ["r", "g", "t", "w"] && $option_choice >= 0) { # Check if the option type matches accurate types and if the option choice is valid
  76.                 ModelNPCs($option_type, $option_choice);
  77.             }
  78.         }
  79.     }
  80. }
  81.  
  82. # SpawnNPCs(); - Spawns the Model NPCs
  83. sub SpawnNPCs {
  84.     if ($entity_list->GetNPCByNPCTypeID($first_npc_id)) { # Check the entity list for the first Model NPC by NPC ID
  85.         plugin::Message("NPCs are already spawned.");
  86.         return;
  87.     }
  88.     my $column = 0;
  89.     my $row = 0;
  90.     foreach my $npc_id (@npc_ids) { # Loop through each Model NPC ID in the 50 Model NPC ID array
  91.         if ($column == 10) { # Number of Columns Wide
  92.             $column = 0; # Assign the Model NPC Entity's Column to 0
  93.             $row++; # Increase the Model NPC Entity's Row by 1
  94.         }
  95.         my $npc_x = ($npc->GetX() + (($column - 4.5) * -20)); # Aligns the Model NPC based on its column position
  96.         my $npc_y = ($npc->GetY() + (($row + 1.5) * 20)); # Aligns the Model NPC based on its row position
  97.         my $npc_z = ($npc->GetZ() + 10); # Aligns the Model NPC slightly in the air for bigger races
  98.         quest::spawn2($npc_id, 0, 0, $npc_x, $npc_y, $npc_z, 264); # Spawns the Model NPC
  99.         my $npc_entity = $entity_list->GetNPCByNPCTypeID($npc_id); # Find the Model NPC Entity by NPC ID
  100.         my $npc_race = 1; # Assigns Model NPC Entity's Race to 1 (Human)
  101.         $npc_entity->SetRace($npc_race); # Set Model NPC Entity's race to 1 (Human)
  102.         $npc_entity->TempName(""); # Set Model NPC Entity's Name to ""
  103.         $column++; # Increase the Model NPC Entity's Column by 1
  104.     }
  105. }
  106.  
  107. # ModelNPCs(option_type, option_choice); - Model NPCs based on Option Type and Option Choice
  108. # Option Types: "r" => Race, "g" => Gender, "t" => Texture, "w" => Weapon
  109. sub ModelNPCs {
  110.     my ($option_type, $option_choice) = (shift, shift); # Assign $option_type and $option_choice to the values supplied to ModelNPCs(option_type, option_choice);
  111.     my ($npc_name, $npc_last_name) = ("", ""); # Assign $npc_name and $npc_last_name to ""
  112.     my ($npc_race, $npc_gender, $npc_texture, $npc_primary, $npc_secondary) = (0, 0, 0, 0, 0); # Assign $npc_race, $npc_gender, $npc_texture, $npc_primary, and $npc_secondary to 0
  113.     my $race_index = 0; # Assign the Race Index to 0
  114.     foreach my $npc_id (@npc_ids) { # Loop through each Model NPC ID in the 50 Model NPC ID array
  115.         my $npc_entity = $entity_list->GetNPCByNPCTypeID($npc_id); # Find the Model NPC Entity by NPC ID
  116.         $npc_race = $npc_entity->GetRace(); # Assigns Model NPC Entity's Race to the Model NPC Entity's Race
  117.         $npc_texture = $npc_entity->GetTexture(); # Get the Model NPC Entity's Texture
  118.         if ($option_type eq "r") { # Check if the Option Type is "r" (Race)
  119.             my @races;
  120.             if (defined $race_viewer_options{$option_choice}) { # Check if the option choice is a defined option type
  121.                 @races = @{$race_viewer_options{$option_choice}}; # Assign the Races array to the 50 Race ID Array from %race_viewer_options
  122.             } else {
  123.                 @races = @{$race_viewer_options{0}}; # Assign the Races array to the 50 Race ID Array from %race_viewer_options for Option Type 0
  124.             }          
  125.             $npc_race = defined $races[$race_index] ? $races[$race_index] : 1; # Check if the current Race Index is defined in the 50 Race ID Array and set it to that value, if not set the Model NPC Race to 1
  126.         } elsif ($option_type eq "g") { # Check if the Option Type is "g" (Gender)
  127.             $npc_gender = $option_choice; # Assign the Model NPC Entity's Gender to the Option Choice
  128.         } elsif ($option_type eq "t") { # Check if the Option Type is "t" (Texture)
  129.             $npc_texture = $option_choice; # Assign the Model NPC Entity's Texture to the Option Choice
  130.         } elsif ($option_type eq "w") { # Check if the Option Type is "w" (Weapon)
  131.             if ($npc_primary == 0) { # Check if the Model NPC Entity's Primary Model is equal to 0
  132.                 $npc_primary = (($option_choice * 100) + 1); # Example: Choice 0's Primary Model is "1", Choice 10's Primary Model is "1001"
  133.                 $npc_secondary = (($option_choice * 100) + 2); # Example: Choice 0's Secondary Model is "2", Choice 10's Secondary Model is "1002"
  134.             }
  135.            
  136.             $npc_race = 127; # Assign the Model NPC Entity's Race to 127 (Invisible Man)
  137.             $npc_gender = 0; # Assign the Model NPC Entity's Gender to 0 (Male)
  138.             $npc_texture = 0; # Assign the Model NPC Entity's Texture to 0
  139.             $npc_name = ""; # Assign the Model NPC Entity's Name to ""
  140.         }
  141.        
  142.         if ($npc_primary != 0) { # Check if the Model NPC Entity's Primary Model is not equal to 0
  143.             $npc_primary = ($npc_primary + 1); # Increase the Model NPC Entity's Primary Model by 1
  144.             $npc_secondary = ($npc_primary + 1); # Increase the Model NPC Entity's Secondary Model by 2
  145.         }
  146.        
  147.         $npc_entity->SetRace($npc_race); # Sets the Model NPC Entity's Race to the value of $npc_race
  148.         if ($option_type ~~ ["r", "t"]) { # Check if the Option Type is "r" (Race)
  149.             $npc_gender = $npc_entity->GetGender(); # Assign the Model NPC Entity's Gender to the Model NPC Entity's Current Gender
  150.         }
  151.         $npc_entity->SendIllusion($npc_race, $npc_gender, $npc_texture); # Sets Model NPC Entity's Race, Gender, and Texture to their respective values
  152.         if ($option_type ne "w") {
  153.             $npc_name = plugin::Race($npc_race); # Return the Model NPC Entity's Race Name
  154.         }
  155.         if ($option_type ~~ ["r", "g", "t"]) { # Checks if the Option Type is "r" (Race), "g" (Gender), or "t" (Texture)
  156.             $npc_last_name = "| R$npc_race | T$npc_texture | G$npc_gender |"; # Assigns the Model NPC Entity's Lastname to "| R$npc_race | T$npc_texture | G$npc_gender |"
  157.             $npc_entity->WearChange($_, 0) for (7, 8); # Sets the Model NPC Entity's Primary and Secondary Models to 0
  158.         } else {
  159.             $npc_last_name = "| P$npc_primary | S$npc_secondary |"; # Assigns the Model NPC Entity's Lastname to "| P$npc_primary | S$npc_secondary |"
  160.             $npc_entity->WearChange(7, $npc_primary); # Sets the Model NPC Entity's Primary Model to $npc_primary
  161.             $npc_entity->WearChange(8, $npc_secondary); # Sets the Model NPC Entity's Secondary Model to $npc_secondary
  162.         }
  163.         $npc_entity->TempName($npc_name); # Sets the Model NPC Entity's Name to $npc_name
  164.         $npc_entity->ChangeLastName($npc_last_name); # Sets the Model NPC Entity's Lastmame to $npc_last_name
  165.         $race_index++; # Increase the Race Index by 1
  166.     }
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement