EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Quests::Q&A (https://www.eqemulator.org/forums/forumdisplay.php?f=599)
-   -   simple perl help, please! (https://www.eqemulator.org/forums/showthread.php?t=41773)

lctucker2999 02-18-2018 02:14 PM

simple perl help, please!
 
Hello everyone. I am trying to teach myself some basic script by copying code from existing quests and the perl lexicon, and tweaking it a little at a time, trying to add more and make things more complex as I go. I'm having trouble with the below code where the NPC just eats any items. Before I tried adding the armor code, it was working fine with turning in a water flask and getting a gem back. I'm guessing it's just some basic syntax errors that I don't understand. Thanks for the help!

Code:


sub EVENT_SAY
{
        if($text=~/hail/i)
                {
                        quest::say("Hail, mortal.");
                }
}#END OF SAY

sub EVENT_ITEM
{
        if($itemcount{13006} == 1) #Water flask
                {
                        quest::say("Thank you, $name.");#Text made up
                        quest::summonitem(quest::ChooseRandom(10028, 10037, 22503, 15981));#Random gem: Peridot, Diamond, Blue Diamond, Raw Diamond
                }
       
        if($itemcount{13006} == 1) #Water flask
        if($itemcount{68223} == 1) #Muramite glove armor
                {
                        quest::say("Thank you, $name.");#Text made up
                        quest::summonitem(68862);#Trimdet gloves
                }
               
        if($itemcount{13006} == 1) #Water flask
        if($itemcount{68221} == 1) #Muramite sleeve armor
                {
                        quest::say("Thank you, $name.");#Text made up
                        quest::summonitem(68861);#Trimded Arms
                }
        else
                {
                        quest::say("I do not need this, fool. $name, bah!");#Text made up
                        quest::summonitem($item1) if($item1);
                        quest::summonitem($item2) if($item2);
                        quest::summonitem($item3) if($item3);
                        quest::summonitem($item4) if($item4);
                }       
}#END of FILE Zone:poknowledge  ID:______ -- Defender of Frost


nilbog 02-18-2018 02:48 PM

You are missing several curly brackets. I recommend using a text editor which has highlighting for the language you are writing - I like notepad++ or sublime personally.

Kingly_Krab 02-18-2018 03:00 PM

Try this:
Code:

sub EVENT_SAY {
    if($text=~/hail/i) {
        quest::say("Hail, mortal.");
    }
}

sub EVENT_ITEM {
    if(plugin::check_handin(\%itemcount, 13006 => 1, 68223 => 1)) {
        quest::say("Thank you, $name.");
        quest::summonitem(68862);
    } elsif(plugin::check_handin(\%itemcount, 13006 => 1, 68221 => 1)) {
        quest::say("Thank you, $name.");
        quest::summonitem(68861);
    } elsif(plugin::check_handin(\%itemcount, 13006 => 1)) {
        quest::say("Thank you, $name.");
        quest::summonitem(quest::ChooseRandom(10028, 10037, 22503, 15981));
    }
    plugin::return_items();
}


lctucker2999 02-18-2018 07:28 PM

Thanks that condensed code looks so much better. As soon as I get home I'll try it out.

Another question, is there either a) a limit to the amount of elseif lines or b) a point where one npc is doing too much? My ultimate goal is to still have quest armor be a thing, but to simplify it (mold + class specific token that i havent decided how im going to implement yet) and then have one NPC per expansion to do quest armor turn ins e.g. Defender of Frost would allow you to turn in Thurg, SS and Kael armor... so however many classes there are, 15? Multiplied by 3 sets of armor, times 7 pieces per set, plus if I add mischief items that's around 400 different possible turn in combinations.

I'm having fun with the possibilities on how to tweak things. thanks again the help!

ghanja 02-18-2018 10:54 PM

Quote:

Originally Posted by lctucker2999 (Post 257667)
Thanks that condensed code looks so much better. As soon as I get home I'll try it out.

Another question, is there either a) a limit to the amount of elseif lines or b) a point where one npc is doing too much? My ultimate goal is to still have quest armor be a thing, but to simplify it (mold + class specific token that i havent decided how im going to implement yet) and then have one NPC per expansion to do quest armor turn ins e.g. Defender of Frost would allow you to turn in Thurg, SS and Kael armor... so however many classes there are, 15? Multiplied by 3 sets of armor, times 7 pieces per set, plus if I add mischief items that's around 400 different possible turn in combinations.

I'm having fun with the possibilities on how to tweak things. thanks again the help!


a. No limit (that I'm aware of, but remember if the last conditional is the one that applies, it will still iterate through all the prior ones and will check all if none apply)

b. You could take a look at quests in Kael for some leads. However, you may want to consider checking class for applicable exchanges, so nested if's/elsif's to a point. It's one way (of a few). You could also consider going the route of creating recipes, where combining said items result in some other, etc, etc. The straight answer (thus code) will rely highly on precisely what your game plan is in detail.

joligario 02-19-2018 12:38 AM

Quote:

Originally Posted by ghanja (Post 257670)
a. No limit

There shouldn’t be, but there is. We ran into that a few years ago with 50ish elsif statements. I never really dug in to find out if it was a Perl limitation or what.

c0ncrete 02-19-2018 11:45 AM

re: conditional statement limitations.
 
I posted an example on how to take a script with multiple chained conditionals and replace it with a single conditional loop a while back (5 years ago?! wow...). It's sort of like separating the data (item numbers and NPC spam) from the logic (conditionals, function calls, etc).

Thread can be found here. The example I'm referring to is the last post in the thread.


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

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