|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Quests::Custom Custom Quests here |
|
|
|
02-10-2017, 01:34 PM
|
Fire Beetle
|
|
Join Date: Aug 2009
Location: Czech Republic
Posts: 6
|
|
Trade and Item to NPC
Here is my script I have worked a few hours one and cannot seem to get it to work. The NPC will not respond to 'Refuse' nor will he give an item when selected. The potions; however, work fine. Any help would be much appreciated.
Code:
sub EVENT_SAY
{
if ($text =~/hail/i)
{
plugin::DiaWind("How are ya friend? I can tell by yer backbone several have been fell at yer feet. Well what I be missing in size I make up for wit dese here swords. Ya see me is looking for [planar essence] to combine wit mah swords to become the most famous dwarf in all Kaladim.");
}
elsif(plugin::check_hasitem($client,132540) && $text=~/planar essence/i)
{
plugin::DiaWind("It appears you have ventured into the terrible planes and killed a few of those creatures. Would you be willing to [trade] for a few items I have collected from all over the place? +grovel+");
}
elsif($text=~/planar essence/i)
{
plugin::DiaWind("I am sorry $name but I cannot sense any essence coming from your bags. Please come back to me when you have collected some.");
}
elsif(plugin::check_hasitem($client,132540) && $text=~/trade/i)
{
plugin::DiaWind("Wonderful. Here is a list of items that I have and would be willing to trade. [Frosty Marble] [Firey Marble] [Norrath Soldier] [Undead Potions] [ Dulsehound Potions] [ Grave Dust Potions] [Soldier of Norrath Dust]. =1= +point+");
}
elsif($text=~/Frosty Marble/i)
{
plugin::DiaWind("So you would like to trade your {gold} essence of the planes~ for my {lb}frosty marble sphere~. Click [Frosty Marble Sphere] to trade or [Refuse] to refuse the deal.");
}
elsif (plugin::check_hasitem($client,132541) && $text =~/Frosty Marble Sphere/i)
{
plugin::Whisper("Sorry but it appears you alrady possess this item $name.");
}
elsif ($text =~/Frosty Marble Sphere/i)
{
$client->NukeItem(132540);
quest::summonitem(132541);
plugin::DiaWind("Thank you $name. I knew that we both benefit from this trade.");
}
elsif($text=~/Firey Marble/i)
{
plugin::DiaWind("So you would like to trade your {gold} essence of the planes~ for my {lb}firey marble sphere~. Click [Firey Marble Sphere] to trade or [Refuse] to refuse the deal.");
}
elsif (plugin::check_hasitem($client,132542) && $text =~/Firey Marble Sphere/i)
{
plugin::Whisper("Sorry but it appears you alrady possess this item $name.");
}
elsif ($text =~/Firey Marble Sphere/i)
{
$client->NukeItem(132540);
quest::summonitem(132542);
plugin::DiaWind("Thank you $name. I knew that we both benefit from this trade.");
}
elsif($text=~/Norrath Soldier/i)
{
plugin::DiaWind("So you would like to trade your {gold} essence of the planes~ for my {lb}forgotten Norrath soldier~. Click [Forgotten Norrath Soldier] to trade or [Refuse] to refuse the deal. ");
}
elsif (plugin::check_hasitem($client,132543) && $text =~/Forgotten Norrath Soldier/i)
{
plugin::Whisper("Sorry but it appears you alrady possess this item $name.");
}
elsif ($text =~/Forgotton Norrath Soldier/i)
{
$client->NukeItem(132540);
quest::summonitem(132543);
plugin::DiaWind("Thank you $name. I knew that we both benefit from this trade.");
}
elsif($text=~/Undead Potions/i)
{
plugin::DiaWind("So you would like to trade your {gold} essence of the planes~ for my {lb}Undead Recourse Potion~. Click [Undead Potion] to trade or [Refuse] to refuse the deal.");
}
elsif ($text =~/Undead Potion/i)
{
$client->NukeItem(132540);
quest::summonitem(14180);
plugin::DiaWind("Thank you $name. I knew that we both benefit from this trade.");
}
elsif($text=~/Dulsehound Potions/i)
{
plugin::DiaWind("So you would like to trade your {gold} essence of the planes~ for my {lb}Duslehound Potion~. Click [Dulsehound Potion] to trade or [Refuse] to refuse the deal.");
}
elsif ($text =~/Dulsehound Potion/i)
{
$client->NukeItem(132540);
quest::summonitem(14188);
plugin::DiaWind("Thank you $name. I knew that we both benefit from this trade.");
}
elsif($text=~/Grave Dust Potions/i)
{
plugin::DiaWind("So you would like to trade your {gold} essence of the planes~ for my {lb}Grave Dust Potion~. Click [Grave Dust Potion] to trade or [Refuse] to refuse the deal.");
}
elsif ($text =~/Grave Dust Potion/i)
{
$client->NukeItem(132540);
quest::summonitem(14194);
plugin::DiaWind("Thank you $name. I knew that we both benefit from this trade.");
}
elsif($text=~/Soldier of Norrath Dust/i)
{
plugin::DiaWind("So you would like to trade your {gold} essence of the planes~ for my {lb}Soldier of Norrath Dust~. Click [Soldier of Norrath] to trade or [Refuse] to refuse the deal.");
}
elsif ($text =~/Soldier of Norrath/i)
{
$client->NukeItem(132540);
quest::summonitem(132544);
plugin::DiaWind("Thank you $name. I knew that we both benefit from this trade.");
}
elsif ($text =~/Refuse/i)
{
plugin::Diawind("Sorry we could not reach a [trade]. Would you like to see my items again?");
}
}
|
|
|
|
|
|
|
02-11-2017, 12:07 AM
|
|
Dragon
|
|
Join Date: Aug 2012
Location: Hershey, PA
Posts: 499
|
|
This post really did a number on my phone (ever since width was changed on the site). Anyway.
Your formatting is tricking you I believe. All those elsif's belong to the original if.
That said.
Let's assume that:
Code:
$text = "Your format looks a little off"
and if we were to say:
Code:
if ($text =~ /look/i) {
quest::say ("Yep! I found look!");
}
The =~ is a equals match operator, thus the opposite is !~ or does NOT match operator.
/look/ is the pattern (NOT string) that it's looking for. So even though our text variable was "looks" the pattern "look" is still there. The lowercase i after the match operator tells us to "i"gnore case.
Interesting test for you:
Assuming $text equals potions.
Code:
sub EVENT_SAY {
if ($text =~ /potion/i) {
quest::say ("I found potion!");
}
elsif ($text =~ /potions/i) {
quest::say ("I found potions!");
}
}
Now test:
Code:
sub EVENT_SAY {
if ($text =~ /\potion\b/i) {
quest::say ("I found potion!");
}
elsif ($text =~ /\potions\b/i) {
quest::say ("I found potions!");
}
}
Read up on Perl RegEx (Regular Expressions). There is also index, but, stick with regex.
I had a hell of time knowing where I was in my post above. And I dont suspect reviewing it will be any easier. I'm sure someone will come along and correct me if I'm off somewhere, I hope they do anyway.
|
|
|
|
02-11-2017, 01:08 PM
|
Fire Beetle
|
|
Join Date: Aug 2009
Location: Czech Republic
Posts: 6
|
|
Thank you for the response Ghanja. I was told elsif would help to prevent memory leaks which is why I use them constantly; I have been scripting for may be 2 months. I will look into the perl regular expressions and see if I cannot clean the script up somewhat.
|
|
|
|
02-11-2017, 04:04 PM
|
Administrator
|
|
Join Date: May 2013
Location: United States
Posts: 1,595
|
|
Untested, but should do what you want it to:
Code:
sub EVENT_SAY {
my %trade = (0 => ["Undead Potions", "undead", 14180],
1 => ["Dulsehound Potions", "dulsehound", 14188],
2 => ["Grave Dust Potions", "grave dust", 14194],
3 => ["Frosty Marble", "frosty", 132541],
4 => ["Firey Marble", "firey", 132542],
5 => ["Norrath Soldier", "norrath", 132543],
6 => ["Soldier of Norrath Dust", "soldier dust", 132544]);
if ($text =~/Hail/i) {
plugin::Whisper("How are ya friend? I can tell by yer backbone several have been fell at yer feet. Well what I be missing in size I make up for wit dese here swords. Ya see me is looking for " . quest::saylink("Planar Essence", 1) . " to combine wit mah swords to become the most famous dwarf in all Kaladim.");
} elsif($text=~/Planar Essence/i && plugin::check_hasitem($client, 132540)) {
plugin::Whisper("It appears you have ventured into the terrible planes and killed a few of those creatures. Would you be willing to " . quest::saylink("bargain", 1) . " for a few items I have collected from all over the place?");
} elsif($text=~/Bargain/i && plugin::check_hasitem($client, 132540)) {
plugin::Whisper("Wonderful. Here is a list of items that I have and would be willing to trade.");
foreach my $item (keys %trade) {
plugin::Whisper(quest::saylink("link $trade{$item}[1]", 1, $trade{$item}[0]));
}
} elsif ($text=~/^Link/i) {
if (length(substr($text, 5)) > 0) {
foreach my $key (sort {$trade{$a}[0] cmp $trade{$b}[0]} keys %trade) {
if (substr($text, 5) eq $trade{$key}[1]) {
if (plugin::check_hasitem($client, $trade{$key}[2])) {
plugin::Whisper("Sorry, but it appears you already possess a " . quest::varlink($trade{$key}[2]) . ", $name.");
} else {
plugin::Whisper("So you would like to " . quest::saylink("trade $trade{$key}[1]", 1, "trade") . " your " . quest::varlink(132540) . " for my " . quest::varlink($trade{$key}[2]) . "?");
}
}
}
}
} elsif ($text =~/^Trade/i && plugin::check_hasitem($client, 132540)) {
if (length(substr($text, 6)) > 0) {
foreach my $key (keys %trade) {
if (substr($text, 6) eq $trade{$key}[1]) {
if (!plugin::check_hasitem($client, $trade{$key}[2])) {
$client->NukeItem(132540);
quest::summonitem($trade{$key}[2]);
plugin::Whisper("Enjoy your " . quest::varlink($trade{$key}[2]) . ", $name!");
}
}
}
}
}
}
Last edited by Kingly_Krab; 02-11-2017 at 09:17 PM..
Reason: Adding sorting by name alphabetically.
|
|
|
|
|
|
|
02-11-2017, 11:33 PM
|
|
Dragon
|
|
Join Date: Aug 2012
Location: Hershey, PA
Posts: 499
|
|
Quote:
Originally Posted by Dharrk
Thank you for the response Ghanja. I was told elsif would help to prevent memory leaks which is why I use them constantly; I have been scripting for may be 2 months. I will look into the perl regular expressions and see if I cannot clean the script up somewhat.
|
It was nothing against your efforts, rather, the expanding or widening of the site forums itself (something Akka did a year or so ago). I really must ask what browser he uses, so that I no longer have to scroll horizontally.
"if" is a conditional, and as such will be checked each time
"elsif" is also a conditional that if the originating if was not true, will be checked/considered, stopping upon the first met condition of that if/elsif nesting.
The use of them is a bit much, yes, though the problem was in your regex, not the large number of elsif's. Krab has provided a hash / iteration method, also using length, substr, new regex operator, etc. Plenty to digest, but, beneficial as you'll hopefully learn from it.
|
|
|
|
02-11-2017, 11:44 PM
|
Discordant
|
|
Join Date: Oct 2016
Posts: 445
|
|
Quote:
Originally Posted by ghanja
I really must ask what browser he uses, so that I no longer have to scroll horizontally.
|
I use "view" > zoom out :P
|
02-12-2017, 10:23 AM
|
Fire Beetle
|
|
Join Date: Aug 2009
Location: Czech Republic
Posts: 6
|
|
That works beautifully Kingly thank you for the rework. Thank you Ghanja for pointing me to regular expressions. I had meant not ill will towards you by saying I had only been scripting 2 months just letting you know the extent of my ability. With your mention of expressions and Kinglys example I do have a lot to digest. Thank you both.
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 07:59 PM.
|
|
|
|
|
|
|
|
|
|
|
|
|