Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Custom

Quests::Custom Custom Quests here

Reply
 
Thread Tools Display Modes
  #1  
Old 04-26-2018, 11:06 AM
Kayen
Developer
 
Join Date: Mar 2009
Location: -
Posts: 228
Default Item Multiquest Turn in Script

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;
}
Reply With Quote
  #2  
Old 04-26-2018, 04:45 PM
GRUMPY
Discordant
 
Join Date: Oct 2016
Posts: 445
Default

Quote:
Originally Posted by Kayen View Post
Script to simulate how live used to allow item quests to be completed by multiple players. At the time known as "multiquesting".
This is great. I wondered in the past, if this was ever doable,
especially on a global basis. Thanks Kayen
Reply With Quote
  #3  
Old 04-26-2018, 05:33 PM
Kingly_Krab
Administrator
 
Join Date: May 2013
Location: United States
Posts: 1,594
Default

I think we've had something like this before, I remember there being a mq_handin or something in the handin plugin somewhere. The only problem I see with a script like this is that entity variables reset when a zone reboots, so if Player 1 hands in item X and then zones out and Player 2 zones in to hand in item Y, the NPC won't remember that it received item X.
Reply With Quote
  #4  
Old 04-26-2018, 07:14 PM
GRUMPY
Discordant
 
Join Date: Oct 2016
Posts: 445
Default

These are in the check handin plugin. Didn't notice before.
Code:
sub mq_process_items {
	my $hashref = shift;
	my $npc = plugin::val('$npc');
	my $trade = undef;
	
	if($npc->EntityVariableExists("_mq_trade")) {
		$trade = decode_eqemu_item_hash($npc->GetEntityVariable("_mq_trade")); 
	} else {
		$trade = {};
	}
	
	foreach my $k (keys(%{$hashref})) {
		next if($k == 0);
		
		if(defined $trade->{$k}) {
			$trade->{$k} = $trade->{$k} + $hashref->{$k};
		} else {
			$trade->{$k} = $hashref->{$k};
		}
	}
	
	my $str = encode_eqemu_item_hash($trade);
	$npc->SetEntityVariable("_mq_trade", $str);
}

sub check_mq_handin {
	my %required = @_;
	my $npc = plugin::val('$npc');
	my $trade = undef;
	
	if($npc->EntityVariableExists("_mq_trade")) {
		$trade = decode_eqemu_item_hash($npc->GetEntityVariable("_mq_trade"));
	} else {
		return 0;
	}
	
	foreach my $req (keys %required) {
		if((!defined $trade->{$req}) || ($trade->{$req} < $required{$req})) {
				return 0;
		}
	}
	
	foreach my $req (keys %required) {
		if ($required{$req} < $trade->{$req}) {
			$trade->{$req} -= $required{$req};
		} else {
			delete $trade->{$req};
		}
	}
	
	$npc->SetEntityVariable("_mq_trade", encode_eqemu_item_hash($trade));
	return 1;
}

sub clear_mq_handin {
	my $npc = plugin::val('$npc');
	$npc->SetEntityVariable("_mq_trade", "");
}
Reply With Quote
  #5  
Old 04-26-2018, 07:49 PM
Kayen
Developer
 
Join Date: Mar 2009
Location: -
Posts: 228
Default

Well that is what i get for not having an up to date plugins folder!

Kingly, if you really wanted it to be zone reset proof, you could exchange the entityvars for npc specific qglobals.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 03:06 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3