Log in

View Full Version : itemchecking difficulties


LordAdakos
10-15-2011, 01:36 PM
here's my custom pet summoning code. the problem is, if you hand the guy the gem he requests, he summons your pet, and then attempts to hand the gem back to you. However, if you hand him the wrong gem at the wrong level, he doesn't summon a pet and _STILL_ doesn't return the gem.

What am I doing wrong?


sub EVENT_SAY {
my $test = quest::saylink ("test",1);



if ($text =~/Hail/i)
{
quest::say("Hey, $name. I think I figured out how to enslave creatures to do my bidding, just like an enchanter. I need some help, would you be willing to [$test] it for me...? ");
}


if(($text=~/test/i) && ($ulevel<8))
{
quest::say("I'm sorry, you are much too inexperienced to command such a servant. Come back when you are more experienced!");
}

if(($text=~/test/i) && ($ulevel>=8) && ($ulevel<16))
{
quest::say("I can attempt to create a servant for you, but it will require one piece of amber.");
}

if(($text=~/test/i) && ($ulevel>=16) && ($ulevel<23))
{
quest::say("I can attempt to create a servant for you, but it will require one peridot.");
}
if(($text=~/test/i) && ($ulevel>=23) && ($ulevel<30))
{
quest::say("I can attempt to create a servant for you, but it will require one fire opal.");
}
if(($text=~/test/i) && ($ulevel>=30) && ($ulevel<37))
{
quest::say("I can attempt to create a servant for you, but it will require one fire emerald.");
}
if(($text=~/test/i) && ($ulevel>=37) && ($ulevel<44))
{
quest::say("I can attempt to create a servant for you, but it will require one sapphire.");
}
if(($text=~/test/i) && ($ulevel>=44) && ($ulevel<51))
{
quest::say("I can attempt to create a servant for you, but it will require one ruby.");
}
if(($text=~/test/i) && ($ulevel>51))
{
quest::say("I can attempt to create a servant for you, but it will require one diamond...");
if($ulevel>=55){plugin::Whisper("Pssttt. Rumor has it that there may be a way to use a BLUE Diamond...");
}

}



}

sub EVENT_ITEM
{
#Hand in event AMBER & level check
if ((plugin::check_handin(\%itemcount, 10022 => 1)) && ($ulevel>=8))
{
quest::say("Ah, $name, this is perfect! thanks.. now let me get to work");
quest::emote("cups the gem in his hands as he begins to chant...");
plugin::Whisper("There you go, $name. I think that's what you wanted, right? If not, You can dismiss that one and try again with another gem, Come back when you are a more experienced for a more powerful companion!");
quest::selfcast(quest::ChooseRandom(315,316,317)); #r2
}
#Hand in event PERIDOT & level check

if ((plugin::check_handin(\%itemcount, 10028 => 1)) && ($ulevel>=16))
{
quest::say("Ah, $name, this is perfect! thanks.. now let me get to work");
quest::emote("cups the gem in his hands as he begins to chant...");
plugin::Whisper("There you go, $name. I think that's what you wanted, right? If not, You can dismiss that one and try again with another gem, Come back when you are a more experienced for a more powerful companion!");
quest::selfcast(quest::ChooseRandom(397,398,399,40 0)); #r3
}
#Hand in event fire opal & level check

if ((plugin::check_handin(\%itemcount, 10031 => 1)) && ($ulevel>=23))
{
quest::say("Ah, $name, this is perfect! thanks.. now let me get to work");
quest::emote("cups the gem in his hands as he begins to chant...");
plugin::Whisper("There you go, $name. I think that's what you wanted, right? If not, You can dismiss that one and try again with another gem, Come back when you are a more experienced for a more powerful companion!");
quest::selfcast(quest::ChooseRandom(396,396)); #r5
}
#Hand in event fire emerald & level check

if ((plugin::check_handin(\%itemcount, 10033 => 1)) && ($ulevel>=30))
{
quest::say("Ah, $name, this is perfect! thanks.. now let me get to work");
quest::emote("cups the gem in his hands as he begins to chant...");
plugin::Whisper("There you go, $name. I think that's what you wanted, right? If not, You can dismiss that one and try again with another gem, Come back when you are a more experienced for a more powerful companion!");
quest::selfcast(quest::ChooseRandom(570,571,572)); #r7
}
#Hand in event sapphire & level check

if ((plugin::check_handin(\%itemcount, 10034 => 1)) && ($ulevel>=37))
{
quest::say("Ah, $name, this is perfect! thanks.. now let me get to work");
quest::emote("cups the gem in his hands as he begins to chant...");
plugin::Whisper("There you go, $name. I think that's what you wanted, right? If not, You can dismiss that one and try again with another gem, Come back when you are a more experienced for a more powerful companion!");
quest::selfcast(quest::ChooseRandom(573,574,575,57 6)); #r8
}
#Hand in event ruby & level check

if ((plugin::check_handin(\%itemcount, 10035 => 1)) && ($ulevel>=44))
{
quest::say("Ah, $name, this is perfect! thanks.. now let me get to work");
quest::emote("cups the gem in his hands as he begins to chant...");
plugin::Whisper("There you go, $name. I think that's what you wanted, right? If not, You can dismiss that one and try again with another gem, Come back when you are a more experienced for a more powerful companion!");
quest::selfcast(quest::ChooseRandom(8184,8185)); #r9
}
#Hand in event diamond & level check

if ((plugin::check_handin(\%itemcount, 10037 => 1)) && ($ulevel>=51))
{
quest::say("Ah, $name, this is perfect! thanks.. now let me get to work");
quest::emote("cups the gem in his hands as he begins to chant...");
plugin::Whisper("There you go, $name. I think that's what you wanted, right? If not, You can dismiss that one and try again with another gem, Come back when you are a more experienced for a more powerful companion!");
quest::selfcast(quest::ChooseRandom(628,629,630,63 1)); #r11
}
#Hand in event blue diamond & level check

if ((plugin::check_handin(\%itemcount, 22503 => 1)) && ($ulevel>=55))
{
quest::say("Ah, $name, this is perfect! thanks.. now let me get to work");
quest::emote("cups the gem in his hands as he begins to chant...");
plugin::Whisper("There you go, $name. I think that's what you wanted, right? If not, You can dismiss that one and try again with another gem. You have reached the most powerful companion I can summon.");
quest::selfcast(quest::ChooseRandom(632,633,634,63 5)); #r12
}

else {
quest::say("What Am I suppsoed to do with this...thing? This isn't what I need at all. Take it back!");
plugin::return_items(\%itemcount);
}


}

blackdragonsdg
10-15-2011, 02:52 PM
I believe you are using else wrong for what you are trying to do. All but the first if should be elsif otherwise you would have to have the else statement after each if in order for the hand in to be returned properly.

sub EVENT_ITEM
{
#Hand in event AMBER & level check
if ((plugin::check_handin(\%itemcount, 10022 => 1)) && ($ulevel>=8))
{
quest::say("Ah, $name, this is perfect! thanks.. now let me get to work");
quest::emote("cups the gem in his hands as he begins to chant...");
plugin::Whisper("There you go, $name. I think that's what you wanted, right? If not, You can dismiss that one and try again with another gem, Come back when you are a more experienced for a more powerful companion!");
quest::selfcast(quest::ChooseRandom(315,316,317)); #r2
}
#Hand in event PERIDOT & level check

elsif ((plugin::check_handin(\%itemcount, 10028 => 1)) && ($ulevel>=16))
{
quest::say("Ah, $name, this is perfect! thanks.. now let me get to work");
quest::emote("cups the gem in his hands as he begins to chant...");
plugin::Whisper("There you go, $name. I think that's what you wanted, right? If not, You can dismiss that one and try again with another gem, Come back when you are a more experienced for a more powerful companion!");
quest::selfcast(quest::ChooseRandom(397,398,399,40 0)); #r3
}
#Hand in event fire opal & level check

elsif ((plugin::check_handin(\%itemcount, 10031 => 1)) && ($ulevel>=23))
{
quest::say("Ah, $name, this is perfect! thanks.. now let me get to work");
quest::emote("cups the gem in his hands as he begins to chant...");
plugin::Whisper("There you go, $name. I think that's what you wanted, right? If not, You can dismiss that one and try again with another gem, Come back when you are a more experienced for a more powerful companion!");
quest::selfcast(quest::ChooseRandom(396,396)); #r5
}
#Hand in event fire emerald & level check

elsif ((plugin::check_handin(\%itemcount, 10033 => 1)) && ($ulevel>=30))
{
quest::say("Ah, $name, this is perfect! thanks.. now let me get to work");
quest::emote("cups the gem in his hands as he begins to chant...");
plugin::Whisper("There you go, $name. I think that's what you wanted, right? If not, You can dismiss that one and try again with another gem, Come back when you are a more experienced for a more powerful companion!");
quest::selfcast(quest::ChooseRandom(570,571,572)); #r7
}
#Hand in event sapphire & level check

elsif ((plugin::check_handin(\%itemcount, 10034 => 1)) && ($ulevel>=37))
{
quest::say("Ah, $name, this is perfect! thanks.. now let me get to work");
quest::emote("cups the gem in his hands as he begins to chant...");
plugin::Whisper("There you go, $name. I think that's what you wanted, right? If not, You can dismiss that one and try again with another gem, Come back when you are a more experienced for a more powerful companion!");
quest::selfcast(quest::ChooseRandom(573,574,575,57 6)); #r8
}
#Hand in event ruby & level check

elsif ((plugin::check_handin(\%itemcount, 10035 => 1)) && ($ulevel>=44))
{
quest::say("Ah, $name, this is perfect! thanks.. now let me get to work");
quest::emote("cups the gem in his hands as he begins to chant...");
plugin::Whisper("There you go, $name. I think that's what you wanted, right? If not, You can dismiss that one and try again with another gem, Come back when you are a more experienced for a more powerful companion!");
quest::selfcast(quest::ChooseRandom(8184,8185)); #r9
}
#Hand in event diamond & level check

elsif ((plugin::check_handin(\%itemcount, 10037 => 1)) && ($ulevel>=51))
{
quest::say("Ah, $name, this is perfect! thanks.. now let me get to work");
quest::emote("cups the gem in his hands as he begins to chant...");
plugin::Whisper("There you go, $name. I think that's what you wanted, right? If not, You can dismiss that one and try again with another gem, Come back when you are a more experienced for a more powerful companion!");
quest::selfcast(quest::ChooseRandom(628,629,630,63 1)); #r11
}
#Hand in event blue diamond & level check

elsif ((plugin::check_handin(\%itemcount, 22503 => 1)) && ($ulevel>=55))
{
quest::say("Ah, $name, this is perfect! thanks.. now let me get to work");
quest::emote("cups the gem in his hands as he begins to chant...");
plugin::Whisper("There you go, $name. I think that's what you wanted, right? If not, You can dismiss that one and try again with another gem. You have reached the most powerful companion I can summon.");
quest::selfcast(quest::ChooseRandom(632,633,634,63 5)); #r12
}

else {
quest::say("What Am I suppsoed to do with this...thing? This isn't what I need at all. Take it back!");
plugin::return_items(\%itemcount);
}

}

Also look at your level checks in sub EVENT_ITEM. If the character doing the hand in is above level 8 the first check will always be true which will likely cause it to stop right there.

LordAdakos
10-15-2011, 03:08 PM
so do i need to put quantifiers on the level checks, such as:

if ((plugin::check_handin(\%itemcount, xxxx => 1)) && ($ulevel>=8) && ($ulevel<16))


to check max level for the hand in?

what if i wanted someone to be able to hand in the current level gem or a lower level gem ?
Should I:

if plugin handin item = xxxx && level is > 55
do something for lvl 55+
elseif
if plugin handin item = xxxx && level is > 50
do something for lvl 50+
elseif
if plugin handin item = xxxx && level is > 55
do something for lvl 55+
elseif
if plugin handin item = xxxx && level is > 40
do something for lvl 40+
elseif
return the stuff


would that work?


Also, it shouldnt stop after the first check becuase " the item = 10022 "AND the "level is greater than 8", right? it has to BOTH be true with an AND statement. The level may be >8 but the item isnt true, so that would invalidate the AND statement.


Replacing the IF's with ELSEIF's makes the NPC eat the items in all cases.

blackdragonsdg
10-15-2011, 03:22 PM
Oh shit i misread the item id's sorry. Everything is looking the same to me today. Your level check was right.

LordAdakos
10-15-2011, 03:49 PM
WE all have those days. I just want to figure this out because im sure its a stupid error on my part, but i just can't see it. the problem is, he will give the message, but wont return the gem, in any case...
Id rather not write a final IF statement with tons of conditional statements, can someone please help

trevius
10-16-2011, 03:01 AM
FYI, you should ALWAYS make your turn in check last in your if statements:

if ((plugin::check_handin(\%itemcount, xxxx => 1)) && ($ulevel>=8) && ($ulevel<16))

The above example from you will result in the NPC eating the turned in item and failing to trigger the desired result for the player if they don't meet the level criteria.

Here is a better way:

if ($ulevel >= 8 && $ulevel < 16 && plugin::check_handin(\%itemcount, xxxx => 1))

This way, if they fail the level checks (or any checks that you want to do along with an item turn-in), the item is not lost. You can still use the return items plugin and give back any items that were not taken by the NPC.

Also, since any items that get taken by the NPC will be removed from the list of items to return, you can use the return plugin at the end of the EVENT_ITEMS sub without having it inside an else or any other statement.

plugin::return_items(\%itemcount);

Just put that before the last bracket of EVENT_ITEM and you will always return any unused items.