Go Back   EQEmulator Home > EQEmulator Forums > Quests > Quests::Q&A

Quests::Q&A This is the quest support section

Reply
 
Thread Tools Display Modes
  #1  
Old 07-30-2008, 04:22 AM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default Problem with my $variable

I am not quite sure how to get this working. Basically, I want my NPC to change what a variable is equal to on a timer, and then use that variably to decide when to do or not to do something. The variable I am using is $cast and for some reason, it always casts the illusion, even though everything else in the quest is working properly. The variable is supposed to switch to equal 0, and when it is 0, she isn't supposed to cast the illusions.

Code:
#Illusionist Quest

sub EVENT_SPAWN {

  my $cast;
  my $x = $npc->GetX();
  my $y = $npc->GetY();

  quest::set_proximity($x - 10, $x + 10, $y - 10, $y + 10);
  quest::settimer("stopcast",1200);
$cast=1;

}

sub EVENT_SAY {

  if ($text =~/hail/i) {
    quest::say ("Would you like me to [return] you to your natural form?  Or would you like me to [stop] changing your illusion when you enter the Nexus?"); }

  if ($text =~/return/i) {
    quest::say ("There, you are now back to your natural appearance.");
    quest::playerrace(0); } 

  if ($text =~/stop/i) {
    quest::say ("Ok, I won't change it from now on.  Unless you change your mind and wish for me to [start] changing it again next time.");
    quest::setglobal("illusion", 1, 1, "F"); } 

  if ($text =~/start/i) {
    quest::say ("Sure, I will be happy to start changing your illusion again next time!");
    quest::setglobal("illusion", 1, 1, "M10"); } 

}

sub EVENT_ENTER {

  if (defined($qglobals{nexusmove})) {
  }
  else {
    quest::movepc(152, quest::ChooseRandom(-30,-25,-20,-15,-10,-5,0,5,10,15,20,25,30,35),quest::ChooseRandom(-30,-25,-20,-15,-10,-5,0,5,10,15,20,25,30,35),-30);
    quest::setglobal("nexusmove", 1, 1, "M10");
  }

  if ($cast=1) {
    if ($ulevel >= 5) {
      if (defined($qglobals{illusion})) {
      }
      else {
    	  quest::playerrace(quest::ChooseRandom(14,27,42,43,46,58,60,62,63,66,75,82,85,89,95,108,120,123,150,151,153,161,209,210,211,212,356,367,433,436,454,455,456,458,464,469,470,472,473));
    	  quest::playertexture(quest::ChooseRandom(1,2,3,4,5));
    	  quest::movepc(152, quest::ChooseRandom(-30,-25,-20,-15,-10,-5,0,5,10,15,20,25,30,35),quest::ChooseRandom(-30,-25,-20,-15,-10,-5,0,5,10,15,20,25,30,35),-30);
          quest::setglobal("illusion", 1, 1, "M10");
      }
    }
  }
}

sub EVENT_TIMER {

my $cast;

  if ($timer eq "stopcast") {
$cast=0;
    quest::stoptimer("stopcast");
    quest::say ("I must concentrate for a while before I can cast more illusions.");
#    quest::doanim(33);
$npc->SetAppearance(1);
    quest::settimer("startcast",3600);
 }

  if ($timer eq "startcast") {
$cast=1;
    quest::stoptimer("startcast");
    quest::say ("I have gathered enough energy to begin casting illusions once again!");
#    quest::doanim(0);
$npc->SetAppearance(0);
    quest::settimer("stopcast",1200);
 }

}
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #2  
Old 07-30-2008, 04:40 AM
AndMetal
Developer
 
Join Date: Mar 2007
Location: Ohio
Posts: 648
Default

I'm still a little fuzzy on how exactly my functions, but I think it you declare my $cast at the beginning of the script, before sub EVENT_SPAWN, it will allow only that script to use it, and it will carry through all of the subs.

Then again, this:
Code:
  if ($cast=1) {
    if ($ulevel >= 5) {
      if (defined($qglobals{illusion})) {
      }
      else {
    	  quest::playerrace(quest::ChooseRandom(14,27,42,43,46,58,60,62,63,66,75,82,85,89,95,108,120,123,150,151,153,161,209,210,211,212,356,367,433,436,454,455,456,458,464,469,470,472,473));
    	  quest::playertexture(quest::ChooseRandom(1,2,3,4,5));
    	  quest::movepc(152, quest::ChooseRandom(-30,-25,-20,-15,-10,-5,0,5,10,15,20,25,30,35),quest::ChooseRandom(-30,-25,-20,-15,-10,-5,0,5,10,15,20,25,30,35),-30);
         quest::setglobal("illusion", 1, 1, "M10");
      }
    }
  }
Should probably be this:
Code:
  if ($cast==1) {
    if ($ulevel >= 5) {
      if (!defined($qglobals{illusion})) {
    	  quest::playerrace(quest::ChooseRandom(14,27,42,43,46,58,60,62,63,66,75,82,85,89,95,108,120,123,150,151,153,161,209,210,211,212,356,367,433,436,454,455,456,458,464,469,470,472,473));
    	  quest::playertexture(quest::ChooseRandom(1,2,3,4,5));
    	  quest::movepc(152, quest::ChooseRandom(-30,-25,-20,-15,-10,-5,0,5,10,15,20,25,30,35),quest::ChooseRandom(-30,-25,-20,-15,-10,-5,0,5,10,15,20,25,30,35),-30);
    	  quest::setglobal("illusion", 1, 1, "M10");
      }
    }
  }
Otherwise, all you're doing is seeing if a variable can set to be a value, which will always return true. The second part is just making the script a little simpler.

Hope this at least points you in the right direction.
__________________
GM-Impossible of 'A work in progress'
A non-legit PEQ DB server
How to create your own non-legit server

My Contributions to the Wiki
Reply With Quote
  #3  
Old 07-30-2008, 08:40 AM
joligario's Avatar
joligario
Developer
 
Join Date: Mar 2003
Posts: 1,490
Default

Another thing to look at: Is a 'my' variable script level or sub level?
Reply With Quote
  #4  
Old 07-30-2008, 09:55 AM
Theeper
Discordant
 
Join Date: May 2004
Posts: 290
Default

In PERL, "my" variables are private in scope. They're not the same as "local" variables, but they function as you'd expect a local variable would in this context. Not using "my" makes a variable global.
Reply With Quote
  #5  
Old 07-30-2008, 07:25 PM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

I think AndMetals suggestion cleared it up for me, though I didn't have time to fully test it yet. I was defining my variable in the subs instead of defining it 1 time before the subs to they all use the same one. That should allow each section to see any changes made to it.
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

   

All times are GMT -4. The time now is 06:32 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3