Instead of having to redefine the entire special attack string every time
you want to make a change this will allow on the fly changes without worrying
about having to account for what the npc's current settings are.
#Usage: plugin::ModSpecialAttack("$Mod", "Ability");
#Add or remove one or more special attacks to an NPC.
#Where "$Mod" is either "Add" or "Remove";
#Where "Ability" is a special ATK value ie "A" or "AB" or "ABH" ect
#Example: ModSpecialAttack("Add", "ABH");
#If NPC as special ATK values set as "Qf" already, and you want to make it immune, this
#plugin will add ABH making your final value "QfABH"
#Returns the current special attack values ie would return "QfABH";
#Kayen [GM Storm Haven] 12/09/10
Code:
sub ModSpecialAttack {
sub remove_duplicates {
my($array, $new_array)=@_;
my %entries=();
foreach (@$array) {
next if exists $entries{$_};
$entries{$_}=1}
foreach (@$array) {
if($entries{$_}){
push @$new_array,$_;
$entries{$_}=0;
}}}
my $npc = plugin::val('npc');
my $Mod = $_[0];
my $Ability = $_[1];
my $SATK_A = $npc->HasNPCSpecialAtk("A"); if ($SATK_A) { $SATK_A = "A"; }
my $SATK_B = $npc->HasNPCSpecialAtk("B"); if ($SATK_B) { $SATK_B = "B"; }
my $SATK_H = $npc->HasNPCSpecialAtk("H"); if ($SATK_H) { $SATK_H = "H"; }
my $SATK_S = $npc->HasNPCSpecialAtk("S"); if ($SATK_S) { $SATK_S = "S"; }
my $SATK_E = $npc->HasNPCSpecialAtk("E"); if ($SATK_E) { $SATK_E = "E"; }
my $SATK_R = $npc->HasNPCSpecialAtk("R"); if ($SATK_R) { $SATK_R = "R"; }
my $SATK_r = $npc->HasNPCSpecialAtk("r"); if ($SATK_r) { $SATK_r = "r"; }
my $SATK_T = $npc->HasNPCSpecialAtk("T"); if ($SATK_T) { $SATK_T = "T"; }
my $SATK_Q = $npc->HasNPCSpecialAtk("Q"); if ($SATK_Q) { $SATK_Q = "Q"; }
my $SATK_U = $npc->HasNPCSpecialAtk("U"); if ($SATK_U) { $SATK_U = "U"; }
my $SATK_M = $npc->HasNPCSpecialAtk("M"); if ($SATK_M) { $SATK_M = "M"; }
my $SATK_C = $npc->HasNPCSpecialAtk("C"); if ($SATK_C) { $SATK_C = "C"; }
my $SATK_N = $npc->HasNPCSpecialAtk("N"); if ($SATK_N) { $SATK_N = "N"; }
my $SATK_I = $npc->HasNPCSpecialAtk("I"); if ($SATK_I) { $SATK_I = "I"; }
my $SATK_D = $npc->HasNPCSpecialAtk("D"); if ($SATK_D) { $SATK_D = "D"; }
my $SATK_f = $npc->HasNPCSpecialAtk("f"); if ($SATK_f) { $SATK_f = "f"; }
my $SATK_O = $npc->HasNPCSpecialAtk("O"); if ($SATK_O) { $SATK_O = "O"; }
my $SATK_W = $npc->HasNPCSpecialAtk("W"); if ($SATK_W) { $SATK_W = "W"; }
my $SATK_g = $npc->HasNPCSpecialAtk("g"); if ($SATK_g) { $SATK_g = "g"; } #Must be close to land spells
my $SATK_d = $npc->HasNPCSpecialAtk("d"); if ($SATK_d) { $SATK_d = "d"; } #Immune to FD
if ($Mod eq "Remove") {
@charas = split(//, $Ability);
foreach $letter (@charas) {
if ($letter eq "A") { undef $SATK_A; }
if ($letter eq "B") { undef $SATK_B; }
if ($letter eq "H") { undef $SATK_H; }
if ($letter eq "S") { undef $SATK_S; }
if ($letter eq "E") { undef $SATK_E; }
if ($letter eq "R") { undef $SATK_R; }
if ($letter eq "r") { undef $SATK_r; }
if ($letter eq "T") { undef $SATK_T; }
if ($letter eq "Q") { undef $SATK_Q; }
if ($letter eq "U") { undef $SATK_U; }
if ($letter eq "M") { undef $SATK_M; }
if ($letter eq "C") { undef $SATK_C; }
if ($letter eq "N") { undef $SATK_N; }
if ($letter eq "I") { undef $SATK_I; }
if ($letter eq "D") { undef $SATK_D; }
if ($letter eq "f") { undef $SATK_f; }
if ($letter eq "O") { undef $SATK_O; }
if ($letter eq "W") { undef $SATK_W; }
if ($letter eq "g") { undef $SATK_g; } #Must be close to land spells
if ($letter eq "d") { undef $SATK_d; } #Immune to FD
}
}
my $SpecialATK_Var = "$SATK_A$SATK_B$SATK_H$SATK_S$SATK_E$SATK_R$SATK_r$SATK_T$SATK_Q$SATK_U$SATK_M$SATK_C$SATK_N$SATK_I$SATK_D$SATK_f$SATK_O$SATK_W$SATK_g$SATK_d";
my $Final_Value;
if ($Mod eq "Add") {
my $SpecialATK_Var_New = "$SpecialATK_Var$Ability";
@charas = split(//, $SpecialATK_Var_New);
my $array=[@charas];
my $new_array=[];
remove_duplicates($array, $new_array);
$npc->NPCSpecialAttacks(@$new_array, 0);
$Final_Value = @$new_array;
#plugin::Debug("Special Abilities: ADD [@$new_array]");
}
if ($Mod eq "Remove") {
$npc->NPCSpecialAttacks($SpecialATK_Var, 0);
$Final_Value = $SpecialATK_Var;
#plugin::Debug("Special Abilities: Removed [$SpecialATK_Var]");
}
return $Final_Value;
}