View Full Version : (another) quest global question
Pandaman
09-10-2009, 04:23 PM
Is it possible to set a quest global upon turning in an item?
Looked through forum post after forum post, as well as the wiki. And if there is, I am just not finding it. ;S
Lillu
09-10-2009, 04:31 PM
Not sure if you meant this, but setting a qglobal in sub EVENT_ITEM is working the same way as in sub EVENT_SAY.
like:
sub EVENT_ITEM {
if (plugin::check_handin(\%itemcount,itemID => 1)) {
quest::summonitem(itemID);
quest::setglobal("$globalname",3,5,"F");
}
else {
$client->Message(6, "$npcname looks confused." );
plugin::return_items(\%itemcount);
}
}
Pandaman
09-10-2009, 04:37 PM
That's exactly what I was looking for. For some reason, I can't seem to get my NPC to use the global when I hand him an item, and since it's a two-part quest.. it's bothersome.
Lillu
09-10-2009, 04:45 PM
Check if the NPC's qglobal flag is set to 1. I tend to forget about that. :)
Pandaman
09-10-2009, 07:09 PM
Hmm, seems to be something wrong.
If you still could assist me, i would greatly appreciate it. I just need to figure out globals, and then maybe it wont be such a pain in the ass.
Thanks
Basically, I want the texts that do not require the quest global to go out as normal, but if you hail him after you turn in the item, he would respond with the same thing he does after you turn in the item, and keep on going from there. the only problem is, it all works great, he won't do the second part once I turn it in, but as soon as I turn it in, everyone is able to do the second conversation.
sub EVENT_SAY
{
if($text=~/Hail/i)
{
quest::emote("jumps at your voice, and begins breathing heavily...");
$client->Message(5, "Oh, it's just you. I bet [you think I'm crazy] too, huh? Everyone thinks I'm crazy!");
}
elsif($text=~/Hail/i && rin_quest == 0)
{
$client->Message(5, ("Rin Distlmore whispers - I am so sorry! I should never have sent you to that place! Can you ever [forgive me]?");
}
if($text=~/you're not crazy/i)
{
quest::emote("nods while looking at you...");
$client->Message(5, "Rin Distlmore whispers - Before I hit rock bottom I was a successful merchant right here in Freeport. I made my living crafting marvelous gems. One night, while I was closing up shop, I was approached by a strange [man].");
}
if($text=~/what man?/i)
{
$client->Message(5, "Rin Distlmore whispers - He never gave me a name. He handed me a list of [instructions], written in a strange language. They described in extraordinary detail how to gather materials for and craft the most remarkable of gems.");
}
if($text=~/What instructions?/i)
{
$client->Message(5, "Rin Distlmore whispers - I told him it would take countless platinum to make what he asked, and he walked away in a scuff. He told me where he got them, though. If you can [bring me the instructions], I can tell you where to get the required materials, and will craft this gem for you, free of charge.");
}
if($text=~/i will bring you the instructions/i)
{
quest::emote("cackles, almost.. crazily...");
$client->Message(5, "Rin Distlmore whispers - Very good sir! There.. there is a slight [problem] though...");
}
if($text=~/what problem?/i)
{
$client->Message(5, "Rin Distlmore whispers - I overheard people talking. The man was eaten by none other than [Untel'Dak]. You must slay this beast and bring me the instructions he will surely have in... most unpleasant places.");
}
if($text=~/untel'dak?/i)
{
quest::emote("shrugs");
$client->Message(5, "Rin Distlmore whispers - I wish I could tell you more, but I have never laid eyes on him. He is not of this world; he resides in a place where only nightmares dwell.");
}
if($text=~/i forgive you/i && $rin_quest == 0)
{
$client->Message(5, "Rin Distlmore whispers - You must be exceptionally strong. As promised, I will craft you the gem. You just have to bring me the [items] on the list.");
}
if($text=~/what items?/i && $rin_quest == 0)
{
$client->Message(5, "Rin Distlmore whispers - To craft this item for you, I will need [three items] of extremely rare quality.");
}
if($text=~/three items?/i && $rin_quest == 0)
{
$client->Message(5, "Rin Distlmore whispers - Yes. The [first] and [second] should come with only slight difficulty. The [third] you may have some trouble with.");
}
if($text=~/the first/i && $rin_quest == 0)
{
$client->Message(5, "Rin Distlmore whispers - The first gem is held by Overking Bathezid. He will not part with it willingly. It is his most prized possesion. If power is what you seek, you will have to take it from him.");
}
if($text=~/the second/i && $rin_quest == 0)
{
$client->Message(5, "Rin Distlmore whispers - The second gem is held by The Junk Beast in the Plane of Innovation. The [clockwork] some how got a hold of it, and now are refusing to give it up.");
}
if($text=~/what clockwork?/i && $rin_quest == 0)
{
$client->Message(5, "Rin Distlmore whispers - The clockwork are mechanical beings that reside in the Plane of Innovation. They are ruthless, as they have no souls. Be careful in there.");
}
if($text=~/the third/i && $rin_quest == 0)
{
$client->Message(5, "Rin Distlmore whispers - The third gem is held by none other than Aerin'Dar. His lair lies in the Plane of Valor. Thousands have died before his claws. Be careful.");
}
}
sub EVENT_ITEM {
if (plugin::check_handin(\%itemcount, 1037 => 1)) {
quest::setglobal("rin_quest",0,1,"F");
$client->Message(5, "Rin Distlmore whispers - I am so sorry! I should never have sent you to that place! Can you ever [forgive me]?");
}
else {
$client->Message(6, "Rin Distlemore looks confused" );
plugin::return_items(\%itemcount);
}
}
Lillu
09-11-2009, 03:49 AM
I can look into this tonight. just a quick guess till then, there were a missing $, and also setting qglobal to zero means making it undefined. I also set your qglobal to be visible zonewide (you can change it back to quest::setglobal("rin_quest",1,1,"F"); if you like).
Can't test it atm, but try this:
sub EVENT_SAY
{
if($text=~/Hail/i)
{
quest::emote("jumps at your voice, and begins breathing heavily...");
$client->Message(5, "Oh, it's just you. I bet [you think I'm crazy] too, huh? Everyone thinks I'm crazy!");
}
elsif($text=~/Hail/i && $rin_quest == 1)
{
$client->Message(5, ("Rin Distlmore whispers - I am so sorry! I should never have sent you to that place! Can you ever [forgive me]?");
}
if($text=~/you're not crazy/i)
{
quest::emote("nods while looking at you...");
$client->Message(5, "Rin Distlmore whispers - Before I hit rock bottom I was a successful merchant right here in Freeport. I made my living crafting marvelous gems. One night, while I was closing up shop, I was approached by a strange [man].");
}
if($text=~/what man?/i)
{
$client->Message(5, "Rin Distlmore whispers - He never gave me a name. He handed me a list of [instructions], written in a strange language. They described in extraordinary detail how to gather materials for and craft the most remarkable of gems.");
}
if($text=~/What instructions?/i)
{
$client->Message(5, "Rin Distlmore whispers - I told him it would take countless platinum to make what he asked, and he walked away in a scuff. He told me where he got them, though. If you can [bring me the instructions], I can tell you where to get the required materials, and will craft this gem for you, free of charge.");
}
if($text=~/i will bring you the instructions/i)
{
quest::emote("cackles, almost.. crazily...");
$client->Message(5, "Rin Distlmore whispers - Very good sir! There.. there is a slight [problem] though...");
}
if($text=~/what problem?/i)
{
$client->Message(5, "Rin Distlmore whispers - I overheard people talking. The man was eaten by none other than [Untel'Dak]. You must slay this beast and bring me the instructions he will surely have in... most unpleasant places.");
}
if($text=~/untel'dak?/i)
{
quest::emote("shrugs");
$client->Message(5, "Rin Distlmore whispers - I wish I could tell you more, but I have never laid eyes on him. He is not of this world; he resides in a place where only nightmares dwell.");
}
if($text=~/i forgive you/i && $rin_quest == 1)
{
$client->Message(5, "Rin Distlmore whispers - You must be exceptionally strong. As promised, I will craft you the gem. You just have to bring me the [items] on the list.");
}
if($text=~/what items?/i && $rin_quest == 1)
{
$client->Message(5, "Rin Distlmore whispers - To craft this item for you, I will need [three items] of extremely rare quality.");
}
if($text=~/three items?/i && $rin_quest == 1)
{
$client->Message(5, "Rin Distlmore whispers - Yes. The [first] and [second] should come with only slight difficulty. The [third] you may have some trouble with.");
}
if($text=~/the first/i && $rin_quest == 1)
{
$client->Message(5, "Rin Distlmore whispers - The first gem is held by Overking Bathezid. He will not part with it willingly. It is his most prized possesion. If power is what you seek, you will have to take it from him.");
}
if($text=~/the second/i && $rin_quest == 1)
{
$client->Message(5, "Rin Distlmore whispers - The second gem is held by The Junk Beast in the Plane of Innovation. The [clockwork] some how got a hold of it, and now are refusing to give it up.");
}
if($text=~/what clockwork?/i && $rin_quest == 1)
{
$client->Message(5, "Rin Distlmore whispers - The clockwork are mechanical beings that reside in the Plane of Innovation. They are ruthless, as they have no souls. Be careful in there.");
}
if($text=~/the third/i && $rin_quest == 1)
{
$client->Message(5, "Rin Distlmore whispers - The third gem is held by none other than Aerin'Dar. His lair lies in the Plane of Valor. Thousands have died before his claws. Be careful.");
}
}
sub EVENT_ITEM {
if (plugin::check_handin(\%itemcount, 1037 => 1)) {
quest::setglobal("rin_quest",1,5,"F");
$client->Message(5, "Rin Distlmore whispers - I am so sorry! I should never have sent you to that place! Can you ever [forgive me]?");
}
else {
$client->Message(6, "Rin Distlemore looks confused" );
plugin::return_items(\%itemcount);
}
}
trevius
09-11-2009, 04:08 AM
Just an FYI, but, you should never use quest globals like this:
elsif($text=~/Hail/i && $rin_quest == 1)
By doing that, it will pull the qglobal information, but it will also save the value of $rin_quest as a variable in that particular script. This means that once one person that has that qglobal hails this NPC, the next person to hail it will also get the same response. This is because the NPC will then see $rin_quest as being equal to 1 since that is what the last player set the variable to on that particular script when they spoke to it.
To use qglobals the right way and ensure that you never run into issues that could cause you major headaches (believe me, I have been through this myself lol), then use them in this way instead:
elsif($text=~/Hail/i && $qglobals{rin_quest} == 1)
Doing this will ensure 100% that the variable value does not get saved on the NPC. So, each player that interacts with it will get the actual results of the qglobals they have set instead of possibly gaining access to things that others have earned before them.
Also, I didn't review the full script you have there completely, but your elsif here would definitely be a problem:
if($text=~/Hail/i)
{
quest::emote("jumps at your voice, and begins breathing heavily...");
$client->Message(5, "Oh, it's just you. I bet [you think I'm crazy] too, huh? Everyone thinks I'm crazy!");
}
elsif($text=~/Hail/i && $rin_quest == 1)
{
$client->Message(5, ("Rin Distlmore whispers - I am so sorry! I should never have sent you to that place! Can you ever [forgive me]?");
}
An elsif will only trigger if the first "if" was false. In this case, if a player hails an NPC, the first one will always be true, so it will never get to the second elseif.
A better way to write this might be the following:
if($text=~/Hail/i)
{
if($qglobals{rin_quest} == 1)
{
$client->Message(5, ("Rin Distlmore whispers - I am so sorry! I should never have sent you to that place! Can you ever [forgive me]?");
}
else
{
quest::emote("jumps at your voice, and begins breathing heavily...");
$client->Message(5, "Oh, it's just you. I bet [you think I'm crazy] too, huh? Everyone thinks I'm crazy!");
}
}
Lillu
09-11-2009, 04:14 AM
Rather try this, I was sleepy :p
my $globalname = rin_quest;
sub EVENT_SAY {
if($text=~/Hail/i) {
quest::emote("jumps at your voice, and begins breathing heavily...");
$client->Message(5, "Oh, it's just you. I bet [you think I'm crazy] too, huh? Everyone thinks I'm crazy!");
}
if($text=~/Hail/i && $qglobals{$globalname} == 1) {
$client->Message(5, ("Rin Distlmore whispers - I am so sorry! I should never have sent you to that place! Can you ever [forgive me]?");
}
if($text=~/you're not crazy/i) {
quest::emote("nods while looking at you...");
$client->Message(5, "Rin Distlmore whispers - Before I hit rock bottom I was a successful merchant right here in Freeport. I made my living crafting marvelous gems. One night, while I was closing up shop, I was approached by a strange [man].");
}
if($text=~/what man?/i) {
$client->Message(5, "Rin Distlmore whispers - He never gave me a name. He handed me a list of [instructions], written in a strange language. They described in extraordinary detail how to gather materials for and craft the most remarkable of gems.");
}
if($text=~/What instructions?/i) {
$client->Message(5, "Rin Distlmore whispers - I told him it would take countless platinum to make what he asked, and he walked away in a scuff. He told me where he got them, though. If you can [bring me the instructions], I can tell you where to get the required materials, and will craft this gem for you, free of charge.");
}
if($text=~/i will bring you the instructions/i) {
quest::emote("cackles, almost.. crazily...");
$client->Message(5, "Rin Distlmore whispers - Very good sir! There.. there is a slight [problem] though...");
}
if($text=~/what problem?/i) {
$client->Message(5, "Rin Distlmore whispers - I overheard people talking. The man was eaten by none other than [Untel'Dak]. You must slay this beast and bring me the instructions he will surely have in... most unpleasant places.");
}
if($text=~/untel'dak?/i) {
quest::emote("shrugs");
$client->Message(5, "Rin Distlmore whispers - I wish I could tell you more, but I have never laid eyes on him. He is not of this world; he resides in a place where only nightmares dwell.");
}
if($text=~/i forgive you/i && $qglobals{$globalname} == 1) {
$client->Message(5, "Rin Distlmore whispers - You must be exceptionally strong. As promised, I will craft you the gem. You just have to bring me the [items] on the list.");
}
if($text=~/what items?/i && $qglobals{$globalname} == 1) {
$client->Message(5, "Rin Distlmore whispers - To craft this item for you, I will need [three items] of extremely rare quality.");
}
if($text=~/three items?/i && $qglobals{$globalname} == 1) {
$client->Message(5, "Rin Distlmore whispers - Yes. The [first] and [second] should come with only slight difficulty. The [third] you may have some trouble with.");
}
if($text=~/the first/i && $qglobals{$globalname} == 1) {
$client->Message(5, "Rin Distlmore whispers - The first gem is held by Overking Bathezid. He will not part with it willingly. It is his most prized possesion. If power is what you seek, you will have to take it from him.");
}
if($text=~/the second/i && $qglobals{$globalname} == 1) {
$client->Message(5, "Rin Distlmore whispers - The second gem is held by The Junk Beast in the Plane of Innovation. The [clockwork] some how got a hold of it, and now are refusing to give it up.");
}
if($text=~/what clockwork?/i && $qglobals{$globalname} == 1) {
$client->Message(5, "Rin Distlmore whispers - The clockwork are mechanical beings that reside in the Plane of Innovation. They are ruthless, as they have no souls. Be careful in there.");
}
if($text=~/the third/i && $qglobals{$globalname} == 1) {
$client->Message(5, "Rin Distlmore whispers - The third gem is held by none other than Aerin'Dar. His lair lies in the Plane of Valor. Thousands have died before his claws. Be careful.");
}
}
sub EVENT_ITEM {
if (plugin::check_handin(\%itemcount, 1037 => 1)) {
quest::setglobal("$globalname",1,5,"F");
$client->Message(5, "Rin Distlmore whispers - I am so sorry! I should never have sent you to that place! Can you ever [forgive me]?");
}
else {
$client->Message(6, "Rin Distlemore looks confused" );
plugin::return_items(\%itemcount);
}
}
Lillu
09-11-2009, 04:14 AM
Trev beats me as always hehe :)
Pandaman
09-11-2009, 07:25 AM
Thanks a ton folks! I really appreciate it. Quest globals are a pain in the ass to me, but this was a big help.
joligario
09-11-2009, 08:02 AM
A better way to write this might be the following:
if($text=~/Hail/i)
{
if($qglobals{rin_quest} == 1)
{
$client->Message(5, ("Rin Distlmore whispers - I am so sorry! I should never have sent you to that place! Can you ever [forgive me]?");
}
else
{
quest::emote("jumps at your voice, and begins breathing heavily...");
$client->Message(5, "Oh, it's just you. I bet [you think I'm crazy] too, huh? Everyone thinks I'm crazy!");
}
}
Just to caveat, you should also check if the global is defined before making a == check.
if(defined($qglobals{rin_quest}) && $qglobals{rin_quest} == 1)
Congdar
09-11-2009, 11:06 AM
Just to caveat, you should also check if the global is defined before making a == check.
if(defined($qglobals{rin_quest}) && $qglobals{rin_quest} == 1)
Checking if the global is defined first is good practice. Not doing that will get your log files filled up with perl messages about undefined variable use. The script will still work if you don't check, but when an actual error happens and you need to study the log files, it's nice to not have to wade through Perl error messages that aren't related to the error you are looking for.
In this case where all you are doing is setting a flag once, the second part is not needed.
if(defined($qglobals{rin_quest}))
is the same as
if(defined($qglobals{rin_quest}) && $qglobals{rin_quest} == 1)
The second part would only be needed if you were to use the global for further questing and updating the qglobal value to 2, 3, etc.
Additionally, organization of the code helps readability for others should the script need to be updated to extend the quest or change it.
EVENT_SAY {
if(defined($qglobals{rin_quest}) {
if($text=~/Hail/i) {
quest::say("This is the flagged conversation section");
}
}
else {
if($text=~/Hail/i) {
quest::say("This is the NON-flagged conversation section");
}
}
}
then if later you want to extend the quest using the same qglobal
EVENT_SAY {
if(defined($qglobals{rin_quest}) {
if($qglobals{rin_quest} == 1) {
if($text=~/Hail/i) {
quest::say("This is the flagged==1 conversation section");
}
}
if($qglobals{rin_quest} == 2) {
if($text=~/Hail/i) {
quest::say("This is the flagged==2 conversation section");
}
}
}
else {
if($text=~/Hail/i) {
quest::say("This is the NON-flagged conversation section");
}
}
}
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.