EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Quests::Q&A (https://www.eqemulator.org/forums/forumdisplay.php?f=599)
-   -   Help with quest turn in code. (https://www.eqemulator.org/forums/showthread.php?t=39308)

utbbop 02-03-2015 03:32 PM

Help with quest turn in code.
 
Hi All,
I am writing some quests for class specific armors.

Without going into much detail I am running into an issue trying to make my quest code re-usable.

I want to be able to copy/paste the code with as few needed modifications as possible for other classes.

Here are the following elements of code I am working with:


Code 1. The following code doesn't seem to work, the NPC returns the items and says he has no need for them:
Code:

if (plugin::check_handin(\%itemcount, $T1Chestpatternitemid => 1, $T1armorscrapsitemid => 1, $T1gemitemid => 1, $T1essenceitemid => 1))
Code 2. The following code works and the NPC accepts the items and provides the reward:
Code:

if (plugin::check_handin(\%itemcount, 2422 => 1, 1656 => 1, 1375 => 1, 1266 => 1,))
Code 3. In relation to Code 1, I have the following items defined in my code:
Code:

my $T1armorscrapsitemid = 1656;
my $T1gemitemid = 1375;
my $T1essenceitemid = 1266;
my $T1Chestpatternitemid = 2422;


If I could get the items in Code 3 to work with Code 1 it would allow me to copy and paste my entire code from NPC to NPC and I would only need to adjust the items in the "my" section of the code rather then adjusting EACH "plugin::check_handin" line with the correct item id's.


Hope this makes sense and hope someone can assist!

Thanks!

utbbop 02-03-2015 04:09 PM

It appears that moving the following items out of my Event_Say and putting them outside of an Event in general has solved my problem:
Code:

my $T1armorscrapsitemid = 1656;
my $T1gemitemid = 1375;
my $T1essenceitemid = 1266;
my $T1Chestpatternitemid = 2422;

Can anyone advise what exactly I achieved? If these items aren't in an Event and they are just in the "nether" of my code, what is this area referred to as?

Thanks...

Kingly_Krab 02-03-2015 05:10 PM

If you define a variable the way you did in the EVENT_SAY subroutine and try to use it in the EVENT_ITEM subroutine it will not work, what you did was move it to a global definition, allowing it to be used in any subroutine.

utbbop 02-03-2015 05:27 PM

Quote:

Originally Posted by Kingly_Krab (Post 237404)
If you define a variable the way you did in the EVENT_SAY subroutine and try to use it in the EVENT_ITEM subroutine it will not work, what you did was move it to a global definition, allowing it to be used in any subroutine.

Thank King, makes sense.

Appreciate the intel...

Kingly_Krab 02-03-2015 06:10 PM

You're welcome, I'm glad your issue has been resolved.

chrsschb 02-05-2015 10:47 AM

There's a few really good examples in the Custom Quests forum for reusable quest scripts using variables and arrays.

utbbop 02-09-2015 07:21 PM

Hi Everyone,
Back with another turn in related question/troubleshoot.

For some reason, the following code isn't working as I want it to.

In practice, as a warrior, if I turn in item 2995 it should return item 1563 to me. However, it is returning BOTH items 1563 and item 1568 from the second block of code. Really, It should only return item 1568 if I turn in say item 2296...

I am sure something is wrong with my logic but have spent all day putzing with it and am only making it worse. If anyone can review and provide feedback it is much appreciated...


Code:

sub EVENT_ITEM
{
if ($class == 'Warrior' || $class == 'Rogue' || $class == 'Monk' || $class == 'Berserker' || $class == 'Shadowkight' || $class == 'Paladin' || $class == 'Ranger' || $class == 'Bard' || $class == 'Beastlord' || $class == 'Cleric' || $class == 'Druid' || $class == 'Shaman' || $class == 'Wizard' || $class == 'Mage' || $class == 'Enchanter' || $class == 'Necromancer')
###################################################################################################################################################################################################################################
        {               
                if (plugin::check_handin(\%itemcount, 2995 => 1 or 3137 => 1 or 3226 => 1 or 3235 => 1 or 3295 => 1 or 3484 => 1 or 2835 => 1 or 2868 => 1 or 2958 => 1 or 2845 => 1 or 2886 => 1 or 2861 => 1 or 1591 => 1 or 3540 => 1 or 3680 => 1 or 3854 => 1)) 
                        {
                                my %rewards = ("Mage" => 2278, "Necromancer" => 2381, "Wizard" => 2422, "Cleric" => 1803, "Druid" => 2434, "Shaman" => 2665, "Berserker" => 2684, "Monk" => 2444, "Ranger" => 2493, "Rogue" => 2828, "Paladin" => 1810, "Shadowknight" => 1819, "Warrior" => 1563, "Bard" => 1846, "Beastlord" => 2562, "Enchanter" => 2561);                                               
                                if(defined($rewards{$class}))
                                        {
                                                quest::summonitem($rewards{$class});
                                                quest::emote("Works to make a piece of armor from the instructions you provided to him." );
                                                quest::say ("Here you go $name.");
                                        }
                        }
        else
                {
                        plugin::return_items(\%itemcount);
                }               
        }
###################################################################################################################################################################################################################################
        {               
                if (plugin::check_handin(\%itemcount, 2996 => 1 or 3174 => 1 or 3227 => 1 or 3236 => 1 or 3404 => 1 or 3485 => 1 or 2836 => 1 or 2871 => 1 or 2964 => 1 or 2846 => 1 or 3397 => 1 or 2863 => 1 or 2095 => 1 or 3541 => 1 or 3682 => 1 or 3855 => 1)) 
                        {
                                my %rewards = ("Mage" => 2298, "Necromancer" => 2382, "Wizard" => 2423, "Cleric" => 1806, "Druid" => 2435, "Shaman" => 2666, "Berserker" => 2685, "Monk" => 2445, "Ranger" => 2494, "Rogue" => 2829, "Paladin" => 1811, "Shadowknight" => 1823, "Warrior" => 1568, "Bard" => 1847, "Beastlord" => 2564, "Enchanter" => 2656);                                               
                                if(defined($rewards{$class}))                                                                                                                       
                                        {
                                                quest::summonitem($rewards{$class});
                                                quest::emote("Works to make a piece of armor from the instructions you provided to him." );
                                                quest::say ("Here you go $name.");
                                        }
                        }
        else
                {
                        plugin::return_items(\%itemcount);
                }               
        }       
}


NatedogEZ 02-09-2015 08:04 PM

Wait a second.. why do you check for every class? lol.. but in the middle there is missing code.. just random brackets for no reason

utbbop 02-09-2015 08:39 PM

Hi Nate,
I was checking for every class as the armor is class specific.

This specific quest allows say a warrior to trade in a piece of wizard gear for the warrior pattern that makes the slot of wizard gear that was turned in.

I am a warrior.
I made the Wizard Robe, because I had the regents...

This quest should allow me to turn in the Wizard Robe for the Warrior Breastplate pattern.

utbbop 02-09-2015 09:23 PM

Also, it appears that its not checking the turn in item... I am able to turn in anything and get the rewards...

:(

utbbop 02-10-2015 11:11 AM

Changed to an array per some feedback but still cant get it to work.
The following code doesnt accept the item and doesnt provide a reward. The NPC returns the item stating they have no need for it...

Code:

sub EVENT_ITEM
{
my @t1chestarmor = [2995,3137,3226,3235,3295,3484,2835,2868,2958,2845,2886,2861,1591,3540,3680,3854];
my @t1legarmor = [2996,3174,3227,3236,3404,3485,2836,2871,2964,2846,3397,2863,2095,3541,3682,3855];
       
        if ($class == 'Mage' || $class == 'Necromance' || $class == 'Wizard' || $class == 'Cleric' || $class == 'Druid' || $class == 'Shaman' || $class == 'Berserker' || $class == 'Monk' || $class == 'Ranger' || $class == 'Rogue' || $class == 'Paladin' || $class == 'Shadowknight' || $class == 'Warrior' || $class == 'Bard' || $class == 'Beastlord' || $class == 'Enchanter')
        {
                if (($item1 ~~ @t1chestarmor))
                        {
                        my %rewards = (        "Mage" => 2278, "Necromancer" => 2381, "Wizard" => 2422, "Cleric" => 1803, "Druid" => 2434, "Shaman" => 2665, "Berserker" => 2684, "Monk" => 2444, "Ranger" => 2493, "Rogue" => 2828, "Paladin" => 1810, "Shadowknight" => 1819, "Warrior" => 1563, "Bard" => 1846, "Beastlord" => 2562, "Enchanter" => 2561);
                        }
                elsif (($item1 = @t1legarmor))
                        {
                        my %rewards = (        "Mage" => 2298, "Necromancer" => 2382, "Wizard" => 2423, "Cleric" => 1806, "Druid" => 2435, "Shaman" => 2666, "Berserker" => 2685, "Monk" => 2445, "Ranger" => 2494, "Rogue" => 2829, "Paladin" => 1811, "Shadowknight" => 1823, "Warrior" => 1568, "Bard" => 1847, "Beastlord" => 2564, "Enchanter" => 2656);
                        }
                if(defined($rewards{$class}))
                        {
                        quest::summonitem($rewards{$class});
                        quest::emote("Works to make a piece of armor from the instructions you provided to him." );
                        quest::say ("Here you go $name.");
                        }
                else       
                {
                plugin::return_items(\%itemcount);
                }
        }               
}


trevius 02-10-2015 12:08 PM

This is a much cleaner way of doing it via hashes:

Note that I only updated the first hash with your item IDs and the second one was just a copy/paste of the first one because I was too lazy to copy your item IDs all over for it. So, you will need to update the second hash (HandInHash2). Also, note that I am not sure what class order you had for your arrays @t1chestarmor or @t1legarmor, so please make sure to review the Turn-In column of the hash and ensure it is the correct one for each class.

Code:

sub EVENT_ITEM {

        my $RewardReceived = 0;
       
        # t1chestarmor
        # Class => [ Turn-In, Reward ],
        my %HandInHash = (
                "Warrior"                => [ 1591, 1563 ],
                "Rogue"                        => [ 2845, 2828 ],
                "Monk"                        => [ 2868, 2444 ],
                "Berserker"                => [ 2835, 2684 ],
                "Shadowknight"        => [ 2861, 1819 ],
                "Paladin"                => [ 2886, 1810 ],
                "Ranger"                => [ 2958, 2493 ],
                "Bard"                        => [ 3540, 1846 ],
                "Beastlord"                => [ 3680, 2562 ],
                "Cleric"                => [ 3235, 1803 ],
                "Druid"                        => [ 3295, 2434 ],
                "Shaman"                => [ 3484, 2665 ],
                "Wizard"                => [ 3226, 2422 ],
                "Magician"                => [ 2995, 2278 ],
                "Enchanter"                => [ 3854, 2561 ],
                "Necromancer"        => [ 3137, 2381 ]
        );
       
        # t1legarmor (Note that this is just a copy of the above array - Make sure you update the IDs!)
        # Class => [ Turn-In, Reward ],
        my %HandInHash2 = (
                "Warrior"                => [ 1591, 1563 ],
                "Rogue"                        => [ 2845, 2828 ],
                "Monk"                        => [ 2868, 2444 ],
                "Berserker"                => [ 2835, 2684 ],
                "Shadowknight"        => [ 2861, 1819 ],
                "Paladin"                => [ 2886, 1810 ],
                "Ranger"                => [ 2958, 2493 ],
                "Bard"                        => [ 3540, 1846 ],
                "Beastlord"                => [ 3680, 2562 ],
                "Cleric"                => [ 3235, 1803 ],
                "Druid"                        => [ 3295, 2434 ],
                "Shaman"                => [ 3484, 2665 ],
                "Wizard"                => [ 3226, 2422 ],
                "Magician"                => [ 2995, 2278 ],
                "Enchanter"                => [ 3854, 2561 ],
                "Necromancer"        => [ 3137, 2381 ]
        );

        if($HandInHash{$class})
        {
                # $HandInHash{$class}[0]; # Item Turned In
                # $HandInHash{$class}[1]; # Reward
       
                if (plugin::check_handin(\%itemcount, $HandInHash{$class}[0] => 1))
                {
                        quest::summonitem($HandInHash{$class}[1]);
                        quest::emote("Works to make a piece of armor from the instructions you provided to him." );
                        quest::say ("Here you go $name.");
                        # Example for below: Percent Experience (5), Max Level to give full exp percentage (level 45)
                        $client->AddLevelBasedExp(5, 45);
                        quest::ding();
                        $RewardReceived = 1;
                }
        }
       
        if ($HandInHash2{$class})
        {
                # $HandInHash2{$class}[0]; # Item Turned In
                # $HandInHash2{$class}[1]; # Reward
       
                if (plugin::check_handin(\%itemcount, $HandInHash2{$class}[0] => 1))
                {
                        quest::summonitem($HandInHash2{$class}[1]);
                        quest::emote("Works to make a piece of armor from the instructions you provided to him." );
                        quest::say ("Here you go $name.");
                        # Example for below: Percent Experience (5), Max Level to give full exp percentage (level 45)
                        $client->AddLevelBasedExp(5, 45);
                        quest::ding();
                        $RewardReceived = 1;
                }
        }
       
        if ($RewardReceived == 0)
        {
                quest::say ("Sorry, $name, but I cannot accept that.");
        }
       
        plugin::return_items(\%itemcount);
}


utbbop 02-10-2015 01:06 PM

Quote:

Originally Posted by trevius (Post 237693)
This is a much cleaner way of doing it via hashes:

Note that I only updated the first hash with your item IDs and the second one was just a copy/paste of the first one because I was too lazy to copy your item IDs all over for it. So, you will need to update the second hash (HandInHash2). Also, note that I am not sure what class order you had for your arrays @t1chestarmor or @t1legarmor, so please make sure to review the Turn-In column of the hash and ensure it is the correct one for each class.

Code:

sub EVENT_ITEM {

        my $RewardReceived = 0;
       
        # t1chestarmor
        # Class => [ Turn-In, Reward ],
        my %HandInHash = (
                "Warrior"                => [ 1591, 1563 ],
                "Rogue"                        => [ 2845, 2828 ],
                "Monk"                        => [ 2868, 2444 ],
                "Berserker"                => [ 2835, 2684 ],
                "Shadowknight"        => [ 2861, 1819 ],
                "Paladin"                => [ 2886, 1810 ],
                "Ranger"                => [ 2958, 2493 ],
                "Bard"                        => [ 3540, 1846 ],
                "Beastlord"                => [ 3680, 2562 ],
                "Cleric"                => [ 3235, 1803 ],
                "Druid"                        => [ 3295, 2434 ],
                "Shaman"                => [ 3484, 2665 ],
                "Wizard"                => [ 3226, 2422 ],
                "Magician"                => [ 2995, 2278 ],
                "Enchanter"                => [ 3854, 2561 ],
                "Necromancer"        => [ 3137, 2381 ]
        );
       
        # t1legarmor (Note that this is just a copy of the above array - Make sure you update the IDs!)
        # Class => [ Turn-In, Reward ],
        my %HandInHash2 = (
                "Warrior"                => [ 1591, 1563 ],
                "Rogue"                        => [ 2845, 2828 ],
                "Monk"                        => [ 2868, 2444 ],
                "Berserker"                => [ 2835, 2684 ],
                "Shadowknight"        => [ 2861, 1819 ],
                "Paladin"                => [ 2886, 1810 ],
                "Ranger"                => [ 2958, 2493 ],
                "Bard"                        => [ 3540, 1846 ],
                "Beastlord"                => [ 3680, 2562 ],
                "Cleric"                => [ 3235, 1803 ],
                "Druid"                        => [ 3295, 2434 ],
                "Shaman"                => [ 3484, 2665 ],
                "Wizard"                => [ 3226, 2422 ],
                "Magician"                => [ 2995, 2278 ],
                "Enchanter"                => [ 3854, 2561 ],
                "Necromancer"        => [ 3137, 2381 ]
        );

        if($HandInHash{$class})
        {
                # $HandInHash{$class}[0]; # Item Turned In
                # $HandInHash{$class}[1]; # Reward
       
                if (plugin::check_handin(\%itemcount, $HandInHash{$class}[0] => 1))
                {
                        quest::summonitem($HandInHash{$class}[1]);
                        quest::emote("Works to make a piece of armor from the instructions you provided to him." );
                        quest::say ("Here you go $name.");
                        # Example for below: Percent Experience (5), Max Level to give full exp percentage (level 45)
                        $client->AddLevelBasedExp(5, 45);
                        quest::ding();
                        $RewardReceived = 1;
                }
        }
       
        if ($HandInHash2{$class})
        {
                # $HandInHash2{$class}[0]; # Item Turned In
                # $HandInHash2{$class}[1]; # Reward
       
                if (plugin::check_handin(\%itemcount, $HandInHash2{$class}[0] => 1))
                {
                        quest::summonitem($HandInHash2{$class}[1]);
                        quest::emote("Works to make a piece of armor from the instructions you provided to him." );
                        quest::say ("Here you go $name.");
                        # Example for below: Percent Experience (5), Max Level to give full exp percentage (level 45)
                        $client->AddLevelBasedExp(5, 45);
                        quest::ding();
                        $RewardReceived = 1;
                }
        }
       
        if ($RewardReceived == 0)
        {
                quest::say ("Sorry, $name, but I cannot accept that.");
        }
       
        plugin::return_items(\%itemcount);
}


Going to work with this now, will let you know the results!
Thanks Trev.

utbbop 02-10-2015 01:17 PM

Okay, got a question for ya Trev.

Code:

        # t1chestarmor
        # Class => [ Turn-In, Reward ],
        my %HandInHash = (
                "Warrior"                => [ 1591, 1563 ],
                "Rogue"                        => [ 2845, 2828 ],
                "Monk"                        => [ 2868, 2444 ],
                "Berserker"                => [ 2835, 2684 ],
                "Shadowknight"        => [ 2861, 1819 ],
                "Paladin"                => [ 2886, 1810 ],
                "Ranger"                => [ 2958, 2493 ],
                "Bard"                        => [ 3540, 1846 ],
                "Beastlord"                => [ 3680, 2562 ],
                "Cleric"                => [ 3235, 1803 ],
                "Druid"                        => [ 3295, 2434 ],
                "Shaman"                => [ 3484, 2665 ],
                "Wizard"                => [ 3226, 2422 ],
                "Magician"                => [ 2995, 2278 ],
                "Enchanter"                => [ 3854, 2561 ],
                "Necromancer"        => [ 3137, 2381 ]

If the format is [ Turn-in, Reward ], how do I handle multiple potential turn-in's for the same reward?

Example:
I am a Warrior.
I have item 1234 which is a Wizard Leg Item.
I want to turn in item 1234 for the Warrior Leg Item which is item number 12345.

Alternatively, I may have created item 123 which is a Druid Leg Item.
I want to be able to then turn in item 123 and receive the Warrior Leg Item which again is item 12345.


Edit:
Might have stumbled onto something that seems to have worked initially...

Code:

my $RewardReceived = 0;
       
        # t1chestarmor
        # Class => [ Turn-In, Reward ],
        my %HandInHash = (
                "Warrior"                => [ 1591, 2995, 1563 ],

if($HandInHash{$class})
        {
                # $HandInHash{$class}[0]; # Item Turned In 1
                # $HandInHash{$class}[1]; # Item Turned In 2
                # $HandInHash{$class}[2]; # Reward
       
                if (plugin::check_handin(\%itemcount, $HandInHash{$class}[0,1] => 1))
                {
                        quest::summonitem($HandInHash{$class}[2]);
                        quest::emote("Works to make a piece of armor from the instructions you provided to him." );
                        quest::say ("Here you go $name.");
                        # Example for below: Percent Experience (5), Max Level to give full exp percentage (level 45)
                        $client->AddLevelBasedExp(5, 45);
                        quest::ding();
                        $RewardReceived = 1;
                }
        }

Any feedback on this?

Thanks for the help...

ghanja 02-10-2015 03:02 PM

You're in need of a multidimensional hash.

For any of us to begin working on this to produce the results you want, you need to provide all item id numbers, though in such a manner.

Magician Head - 2500
Enchanter Head - 2501
Rogue Head - 2502

etc.

Magician Head - 2600
Enchanter Head - 2601
etc.

As you can see, which I try to tactfully suggest, if you had/have control over the item ids and know you want to do this sort of thing from the get go (which I assume so many things are in place by now that -your- best method is through a MD hash), make an item numbering convention. Too late for that now, so, time for code. :)

Though we will need to know the item id's of all gear, preferably listed in the manner shown above.


All times are GMT -4. The time now is 04:44 AM.

Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.