Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Q&A

Quests::Q&A This is the quest support section

Reply
 
Thread Tools Display Modes
  #1  
Old 02-06-2013, 12:24 AM
Randymarsh9
Dragon
 
Join Date: Dec 2007
Posts: 658
Default Array Problems

I am hoping to be able to do some sort of system where I can have an array of quest rewards for each class. This is a very simple example of what I am trying to do.

Code:
sub EVENT_SAY
{
	@Shadowknight = (1001,1002,1003);
	@itemArray = "@$class";
	my $summon = quest::saylink("summon");
	if ($text =~/hail/i)
	{
		quest::say("Do you want me to $summon you something?");
	}
	elsif ($text =~/summon/i)
	{
		quest::say("$class");
		quest::say("@itemArray");
		quest::summonitem($itemArray[1]);
	}
}
Ideally, if someone completes the quest, I could just have it choose their reward from their class's array. The problem I have already seen though, is that getting any array element other than the one at the 0 location returns a 0. So in the script I copied above, it will correctly state the character's class, then (since I am a Shadowknight) it will list all of the elements in the shadowknight array. The problem comes with retrieving individual elements. When I do summonitem($itemArray[0]), it summons an item; however, if I do quest::summonitem($itemArray[1]), it says there is no item with ID = 0. Does anyone know why perl is only recognizing the first element of the array?
Reply With Quote
  #2  
Old 02-06-2013, 12:40 AM
c0ncrete's Avatar
c0ncrete
Dragon
 
Join Date: Dec 2009
Posts: 719
Default

you probably would be better off using a hash of arrays.

Code:
my $reward = {
    Shadowknight => [1001, 1002, 1003],
    Druid        => [1004, 1005, 1006],
    # etc
};

quest::say($class);
quest::summonitem($reward->{$class}->[1]);
assuming you want it to choose a random element from the array, you'd use
Code:
quest::summonitem( quest::ChooseRandom( @{ $reward->{$class} } ) );
or
Code:
quest::summonitem( $reward->{$class}->[ rand int @{ $reward->{$class} } ] );
__________________
I muck about @ The Forge.
say(rand 99>49?'try '.('0x'.join '',map{unpack 'H*',chr rand 256}1..2):'incoherent nonsense')while our $Noport=1;

Last edited by c0ncrete; 02-06-2013 at 01:00 AM.. Reason: capitalization fix
Reply With Quote
  #3  
Old 02-06-2013, 12:40 AM
Dunge0nMastr
Hill Giant
 
Join Date: Oct 2002
Location: Rockville, MD
Posts: 124
Default

This is what i use to reward based on class:

Code:
my %Reward = ("Warrior" => '132639', "Rogue" => '132667', "Monk" => '132672', "Berserker" => '132671', "Shadowknight" => '132670', "Paladin" => '132669', "Ranger" => '132662', "Bard" => '132668', "Beastlord" => '132673', "Cleric" => '132640', "Druid" => '132650', "Shaman" => '132651', "Wizard" => '132663', "Magician" => '132664', "Enchanter" => '132666', "Necromancer" => '132665');
then:

Code:
quest::summonitem($Reward{$class});
obviously ignore the IDs i have in place :P
__________________
Bront -Server Admin/Owner and Lead Quest Dev for Kildrukaun's Prophecy
http://kpemu.com/
Reply With Quote
  #4  
Old 02-06-2013, 01:21 AM
Randymarsh9
Dragon
 
Join Date: Dec 2007
Posts: 658
Default

Thanks for the quick responses. I like both of those methods a lot, so I'll bookmark this page haha.
Reply With Quote
  #5  
Old 02-06-2013, 01:29 AM
c0ncrete's Avatar
c0ncrete
Dragon
 
Join Date: Dec 2009
Posts: 719
Default

you rarely ever want to use variables in variable names, even if you really think you do. it's generally not worth the headache.

http://perl.plover.com/varvarname.html
__________________
I muck about @ The Forge.
say(rand 99>49?'try '.('0x'.join '',map{unpack 'H*',chr rand 256}1..2):'incoherent nonsense')while our $Noport=1;
Reply With Quote
Reply

Thread Tools
Display Modes

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 04:40 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 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3