PDA

View Full Version : Can't figure this out


Forgotten1
01-28-2010, 08:03 PM
I'm trying to build a quest template i'll use for a weapon NPC. The part I can't get to work is the class checks on the items. It seems like he's not doing them at all. I removed warrior as a class, then tried a turn in after reloading quests and he still gave me all of the items. This is a problem since the actual items he gives will be class specific!

I've been trying to figure out what I have wrong for 2 hours now, but alas I'm still stuck. Any help would be appreciated..I'm new to this.

sub EVENT_SAY
{
my $locate = quest::saylink("What do you need me to find?", 0, "locate");

if($text=~/hail/i && $qglobals{startweap} == 0)
{
quest::say("Hrm, Zilgru sent another one of ya to me huh? Alright, here's yer weapon. It was clean, lucky for you. Speak to me again and maybe we can work on getting you something with a little more bang...");
quest::setglobal("startweap","1","0","F");
quest::summonitem("1079");
quest::summonitem("1096");
}

if ($text=~/hail/i && $qglobals{startweap} == 1)
{
quest::say("What's that? Ah right, I said I would help you make a better weapon. Well you see, I may be a Master Weaponsmith, but that does not mean I can make a weapon out of this carpet under my feet! You will need to [$locate] certain items for me.");
}
if ($text=~/find/i && $qglobals{startweap} == 1)
{
quest::setglobal("startweap","2","0","F");
quest::say("Well let me think will ya? You can't gather the right stuff to make anything too powerful yet, no no yer much too young to be able to gather those materials. Ahah, yes that's the one! Okay, $name, in order to create your weapon I will need two Forgotten Rat Tails and Fang of a Forgotten Snake. Bring me those items, and I shall create yer first true weapon.");
}

if ($text=~/hail/i && $qglobals{startweap} == 2)
{
quest::say("What are ye waitin' for? Go gather those items! Bring me those two Forgotten Rat Tails and that Fang of a Forgotten Snake. That slithering bugger, he's a tough one to catch..");
}
}


sub EVENT_ITEM
{
if(($itemcount{1333} == 2) && ($itemcount{1340} == 1) && ($qglobals{startweap} == 2) && ($class == "Ranger, Beastlord"))
{
quest::say("Not bad, maybe you're not as feable as I thought you were. Next time I will have a task that's much more challenging..");
quest::summonitem("1192");
quest::summonitem("25716");
quest::summonitem("25719");
quest::summonitem("25723");
quest::summonitem("1266");
quest::summonitem("1267");
quest::summonitem("1270");
}
elsif(($itemcount{1333} == 2) && ($itemcount{1340} == 1) && ($qglobals{startweap} == 2) && ($class == "Monk"))
{
quest::say("Not bad, maybe you're not as feable as I thought you were. Next time I will have a task that's much more challenging..");
quest::summonitem("1192");
quest::summonitem("25716");
quest::summonitem("25719");
quest::summonitem("25723");
quest::summonitem("1266");
quest::summonitem("1267");
quest::summonitem("1270");
}
elsif(($itemcount{1333} == 2) && ($itemcount{1340} == 1) && ($qglobals{startweap} == 2) && ($class == "Warrior, Bard, Ranger"))
{
quest::say("Not bad, maybe you're not as feable as I thought you were. Next time I will have a task that's much more challenging..");
quest::summonitem("1192");
quest::summonitem("25716");
quest::summonitem("25719");
quest::summonitem("25723");
quest::summonitem("1266");
quest::summonitem("1267");
quest::summonitem("1270");
}
elsif(($itemcount{1333} == 2) && ($itemcount{1340} == 1) && ($qglobals{startweap} == 2) && ($class == "Cleric, Druid, Shaman"))
{
quest::say("Not bad, maybe you're not as feable as I thought you were. Next time I will have a task that's much more challenging..");
quest::summonitem("1192");
quest::summonitem("25716");
quest::summonitem("25719");
quest::summonitem("25723");
quest::summonitem("1266");
quest::summonitem("1267");
quest::summonitem("1270");
}
elsif(($itemcount{1333} == 2) && ($itemcount{1340} == 1) && ($qglobals{startweap} == 2) && ($class == "Necromancer, Wizard, Magician, Enchanter"))
{
quest::say("Not bad, maybe you're not as feable as I thought you were. Next time I will have a task that's much more challenging..");
quest::summonitem("1192");
quest::summonitem("25716");
quest::summonitem("25719");
quest::summonitem("25723");
quest::summonitem("1266");
quest::summonitem("1267");
quest::summonitem("1270");
}
elsif(($itemcount{1333} == 2) && ($itemcount{1340} == 1) && ($qglobals{startweap} == 2) && ($class == "Berserker, Shadowknight, Paladin"))
{
quest::say("Not bad, maybe you're not as feable as I thought you were. Next time I will have a task that's much more challenging..");
quest::summonitem("1192");
quest::summonitem("25716");
quest::summonitem("25719");
quest::summonitem("25723");
quest::summonitem("1266");
quest::summonitem("1267");
quest::summonitem("1270");
}
else {
quest::say("Sorry, your class does not get an epic on this server.");
quest::summonitem(1387);
}
}
else {
quest::say("I do not need this.");
plugin::return_items(\%itemcount);
}
}

Thanks.

trevius
01-28-2010, 08:23 PM
I think your line here:
($class == "Ranger, Beastlord")

should be:

($class eq 'Ranger' || $class eq 'Beastlord')

And your other class checks should be in a similar format.

Forgotten1
01-28-2010, 08:36 PM
Nope, now he just eats the items and doesn't say anything ><. I also tried normal quotes around the class, still nothing.

trevius
01-28-2010, 10:18 PM
Sorry, try this format instead:

($class eq "Ranger" || $class eq "Beastlord")

When comparing strings using "eq", they need to have double quotes, not single quotes.

You should also be able to do it this way:

($class == 'Ranger' || $class == 'Beastlord')

The single quotes should allow "==" to work.

Forgotten1
01-28-2010, 10:33 PM
That's what I meant, I tried double quotes and it didn't work. I'll try reverting back to using == and see if that works. Thanks for the help.

edit: nope...still not working! argh >< this is going to drive me mental. Could you give me an example test template maybe? One that's similiar, that way I can just modify it?

trevius
01-29-2010, 12:30 AM
When having problems with complex scripts, there are 2 things to do to help figure them out as quickly as possible:

1. Break your script down into separate parts to make sure you have each piece working individually. Since you think your issue is related to the class checks, try something like this:

sub EVENT_ITEM {

if($class eq "Ranger" || $class eq "Beastlord") {
quest::say("The Class Check worked!");
quest::summonitem("1192");
quest::say("Take this item!");
}
else {
quest::say("The Class Check failed, or you are not a Ranger or Beastlord!");
}

}

When working with something I am not 100% sure on how to use, I always simplify the script as far as possible to work with testing how to do just that 1 particular thing. Then, work the rest out from there.

2. Use debugging text in your scripts if they are giving you problems. What I mean by this is to basically put an quest::say message after almost every line of the script, so you can see the exact steps that the NPC made it to. Here is an example of debugging a portion of a version of your script:

sub EVENT_ITEM {

if($class eq "Ranger" || $class eq "Beastlord") {
quest::say("The Class Check worked! You are a Ranger or Beastlord.");
if(defined($qglobals{startweap}) && $qglobals{startweap} == 2) {
quest::say("You passed the qglobal check!");
if (plugin::check_handin(\%itemcount, 1192 => 1)) {
quest::say("You turned in the correct item!");
quest::summonitem("1192");
quest::say("Rewarded you with item 1192!");
}
else {
quest::say("You turned in the wrong item!");
plugin::return_items(\%itemcount);
}
}
else {
quest::say("You do not have the required Qglobal, or my npc qglobal flag is not set to 1!");
plugin::return_items(\%itemcount);
}
}
else {
quest::say("The Class Check failed, or you are not a Ranger or Beastlord!");
plugin::return_items(\%itemcount);
}

}

This way, you can see exactly what the NPC is thinking when you turn the item in. It really helps to break down the script and isolate the exact cause of the problem. This is especially useful on long complex scripts. Then, once you are done testing, you can always leave the debug say messages in and just comment them out in case you ever need them later.

joligario
01-29-2010, 04:44 AM
Looks like this is a work in progress for you as there are duplicates, etc. So you can try this and work with it more:

sub EVENT_SAY {
my $locate = quest::saylink("What do you need me to find?", 0, "locate");

if($text=~/hail/i) {
if(!defined($qglobals{startweap})) { #PC has not started the quest
quest::say("Hrm, Zilgru sent another one of ya to me huh? Alright, here's yer weapon. It was clean, lucky for you. Speak to me again and maybe we can work on getting you something with a little more bang...");
quest::setglobal("startweap",1,0,"F");
quest::summonitem(1079);
quest::summonitem(1096);
}
elsif($qglobals{startweap} == 1) { #PC has received items but needs instructions
quest::say("What's that? Ah right, I said I would help you make a better weapon. Well you see, I may be a Master Weaponsmith, but that does not mean I can make a weapon out of this carpet under my feet! You will need to [$locate] certain items for me.");
}
elsif($qglobals{startweap} == 2) { #PC has received items and instructions
quest::say("What are ye waitin' for? Go gather those items! Bring me those two Forgotten Rat Tails and that Fang of a Forgotten Snake. That slithering bugger, he's a tough one to catch..");
}
}
if($text=~/find/i && (defined($qglobals{startweap}) && ($qglobals{startweap} == 1)) { #PC has items and will get instructions
quest::setglobal("startweap",2,0,"F");
quest::say("Well let me think will ya? You can't gather the right stuff to make anything too powerful yet, no no yer much too young to be able to gather those materials. Ahah, yes that's the one! Okay, $name, in order to create your weapon I will need two Forgotten Rat Tails and Fang of a Forgotten Snake. Bring me those items, and I shall create yer first true weapon.");
}
}


sub EVENT_ITEM {
if(plugin::check_handin(\%itemcount, 1333 => 2, 1340 => 1)) {
if(defined($qglobals{startweap}) && ($qglobals{startweap} == 2)) {
if($class eq "Ranger" || $class eq "Beastlord") {
quest::say("Not bad, maybe you're not as feable as I thought you were. Next time I will have a task that's much more challenging..");
quest::summonitem(1192);
quest::summonitem(25716);
quest::summonitem(25719);
quest::summonitem(25723);
quest::summonitem(1266);
quest::summonitem(1267);
quest::summonitem(1270);
}
elsif($class eq "Monk") {
quest::say("Not bad, maybe you're not as feable as I thought you were. Next time I will have a task that's much more challenging..");
quest::summonitem(1192);
quest::summonitem(25716);
quest::summonitem(25719);
quest::summonitem(25723);
quest::summonitem(1266);
quest::summonitem(1267);
quest::summonitem(1270);
}
elsif($class eq "Warrior" || $class eq "Bard" || $class eq "Ranger") {
quest::say("Not bad, maybe you're not as feable as I thought you were. Next time I will have a task that's much more challenging..");
quest::summonitem(1192);
quest::summonitem(25716);
quest::summonitem(25719);
quest::summonitem(25723);
quest::summonitem(1266);
quest::summonitem(1267);
quest::summonitem(1270);
}
elsif($class eq "Cleric" || $class eq "Druid" || $class eq "Shaman") {
quest::say("Not bad, maybe you're not as feable as I thought you were. Next time I will have a task that's much more challenging..");
quest::summonitem(1192);
quest::summonitem(25716);
quest::summonitem(25719);
quest::summonitem(25723);
quest::summonitem(1266);
quest::summonitem(1267);
quest::summonitem(1270);
}
elsif($class eq "Necromancer" || $class eq "Wizard" || $class eq "Magician" || $class eq "Enchanter") {
quest::say("Not bad, maybe you're not as feable as I thought you were. Next time I will have a task that's much more challenging..");
quest::summonitem(1192);
quest::summonitem(25716);
quest::summonitem(25719);
quest::summonitem(25723);
quest::summonitem(1266);
quest::summonitem(1267);
quest::summonitem(1270);
}
elsif($class eq "Berserker" || $class eq "Shadowknight" || $class eq "Paladin") {
quest::say("Not bad, maybe you're not as feable as I thought you were. Next time I will have a task that's much more challenging..");
quest::summonitem(1192);
quest::summonitem(25716);
quest::summonitem(25719);
quest::summonitem(25723);
quest::summonitem(1266);
quest::summonitem(1267);
quest::summonitem(1270);
}

else { #Catch any class not covered
quest::say("Sorry, your class does not get an epic on this server.");
quest::summonitem(1333);
quest::summonitem(1333);
quest::summonitem(1340);
}
}
else { #PC has not finished proper dialogue
quest::say("Why did you bring me these?");
quest::summonitem(1333);
quest::summonitem(1333);
quest::summonitem(1340);
}
}
else { #PC did not give proper items
quest::say("I do not need this.");
plugin::return_items(\%itemcount);
}
}

Lillu
01-29-2010, 04:45 AM
Try to do the item check last: Qglobal check -> class check -> item check

For some reason if you do an item + qglobal check (in this order), if you don't have the proper qglobal but you turn in the proper item, the npc will still eat it. Changing the check order should solve this issue.

trevius
01-29-2010, 04:55 AM
Try to do the item check last: Qglobal check -> class check -> item check

For some reason if you do an item + qglobal check (in this order), if you don't have the proper qglobal but you turn in the proper item, the npc will still eat it. Changing the check order should solve this issue.

That happens because the IF is checked from left to right. If it finds any of them to be false, it stops before checking any of the others to the right of the false one. So, if you do the item check anywhere before last spot, and one of the checks to the right of the item check fails, you don't get the reward, and you don't get your items returned, because it already confirmed you turned in the correct item.

Lillu
01-29-2010, 04:57 AM
yep, to save some headache for serverops, always do the itemcheck last ;)

Forgotten1
01-29-2010, 02:40 PM
Thanks for all the help, joligario's code worked. I kept my event_say because the one he put didn't work for some reason, but the event_item is now fixed. =)