Wrote this to help somebody out who was requesting this feature in Discord. Figured should post for anyone else in the future.
Script to simulate how live used to allow item quests to be completed by multiple players. At the time known as "multiquesting".
I.e Quest requires 1 bat wing 1 Wolf Pelt 1 Bear Skin
If Player A turns in 1 bat wing only, and then Player B turns in the wolf pelt
and the bear skin, Player B will receive the reward for completing the quest.
This script is probably not the be all end all way to do this, but it works.
If you were to use this extensively probably should be converted to a plugin.
Code:
#Title: Mulitquest Item Turn in script
#Author: Kayen 4-25-18
#PERL
sub EVENT_ITEM {
my @item_array = ($item1, $item2, $item3, $item4);
if (MultiQuestTurnIn(\@item_array, 3822,3823,3824)) #An example using different sonic wolf pelts.
{
#Turn in success!
return;
}
}
sub MultiQuestTurnIn
{
my @items_turnedin = @{$_[0]};
my $Qitem1 = $_[1];
my $Qitem2 = $_[2];
my $Qitem3 = $_[3];
my $Qitem4 = $_[4];
my @items_quest = ($Qitem1 , $Qitem2, $Qitem3 , $Qitem4);
@items_turnedin = grep {$_} @items_turnedin;
@items_quest = grep {$_} @items_quest;
my %original = ();
my @items_matched = ();
map { $original{$_} = 1 } @items_turnedin;
@items_matched = grep { $original{$_} } @items_quest; #List of items that match quest requirements.
my $item_count = @items_quest;
my $count = 0;
my @items_stored_mq = ();
if (@items_matched)
{
foreach $i_quest (@items_quest)
{
my $found = 0;
foreach $i_match (@items_matched)
{
if (!$found)
{
if ($i_match == $i_quest)
{
$count++;
$found = 1;
}
}
}
if (!$found)#Check MQ
{
if ($npc->EntityVariableExists($i_quest) && $npc->GetEntityVariable($i_quest))
{
$count++;
push(@items_stored_mq, $i_quest);
}
}
}
}
#If all items required turned in OR items turned + MQ saved items found. Then complete the quest.
if ($count == $item_count)
{
#adjust saved item ent variables if completed.
foreach $items_stored (@items_stored_mq)
{
if ($items_stored)
{
if ($npc->EntityVariableExists($items_stored) && $npc->GetEntityVariable($items_stored) > 0)
{
$npc->SetEntityVariable($items_stored, ($npc->GetEntityVariable($items_stored) - 1));
}
else
{
$npc->SetEntityVariable($items_stored, 0)
}
}
}
return 1; #success MQ
}
#If you don't have a successful MQ then store the items into entity variables.
foreach $i_matched (@items_matched)
{
if ($i_matched)
{
if ($npc->EntityVariableExists($i_matched))
{
$npc->SetEntityVariable($i_matched, ($npc->GetEntityVariable($i_matched) + 1));
}
else
{
$npc->SetEntityVariable($i_matched, 1);
}
}
}
return 0;
}