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 05-25-2008, 05:11 PM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

Quote:
Originally Posted by Gonner View Post
Now while I am unsure of the exact cause of this issue have you tried to set your globals for "temp_level" a bit differ.. Like each level above 70 have a differ number. 71 be temp_level, 2, 5, F then level 72 be temp_level, 3, 5, F It may require a full rewrite of some quests but that may work.

The only reason i say this is your $max_level has the same variable for Undef and for each level. That is just from a quick look at the script and not a full eval of it.

Also quest::deglobal is how you remove gloabls. Had to pound that in my head recently as some of the quest I am working on kind of require it.
Didn't see this post at first. The temp_level global is for another quest and is unrelated to the problem I have been having. I have some fairly tricky globals in use for de-leveling and access to my de-level zone to ensure there are no possible exploits to gain access to the zone.
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #2  
Old 05-25-2008, 05:41 PM
Bulle
Hill Giant
 
Join Date: Jan 2008
Posts: 102
Default

To explain it with more rigor, here is how it seems to work :
- before you enter a Perl script, the individual qglobals $XXX variables are loaded in the Perl interpreter for this zone server. Any variable defined in qglobals is set with its value from the DB, for this character (accounting for timestamps, NPC-specific variables etc)
- the $qglobals map is also initialized ANEW, at the same time (the ANEW is important here, the $qglobals starts from scratch for each script interpretation)
- there is a good chance that the Perl interpreter is reused as-is in the next script, to reduce CPU-load. The qglobals for the new PC/NPC are simply reloaded FOR THE VALUES DEFINED, but nothing is undefined as it is a complex problem to know what variables need to be undefined in the global store.

The real problem is "stale" variables from the previous PC. They are not undefined in the Perl interpreter before switching to the next PC/NPC. The $qglobals variable is not undefined either, but as it is overwritten each time with the full qglobals map (which is computed from an empty map for each script) it does not have any noticeable effect. This is why the $qglobals map is more reliable.

One test you could make to validate this assumption is : have two PCs of different levels (say 72 and 74) do the delevel quest. Their $max_level will be set to the appropriate value. If they do the turn-in they will both return to their proper level, because the variable is defined for them. Then have a level 70 character do the delevel-relevel. As its $max_level will not be set (you can see it in the DB), it should use the $max_level of the previous PC for this zone server.

Doing a #reloadquest reinitializes the Perl interpreter so the "stale" variables are removed (and the problem hidden).

I had a similar problem with temporary variables that were not erased unless I undefined them forcefully. Looks like using $qglobals will avoid this forceful deletion. I will try it when I am back to that point in my tools

Validating that (on another server than mine) would be a clear indication that $qglobals is a must from now on.
Reply With Quote
  #3  
Old 05-25-2008, 08:58 PM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

So, to make sure I understand this clearly, if I want to check for a certain global variable, I would use something like this:

Code:
if (defined($qglobals{max_level}) == 75)
?
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #4  
Old 05-25-2008, 10:51 PM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

Or maybe it should be:

Code:
if (defined($qglobals{max_level} == 75))
I guess I will need to test them both out when I get home and see which one works. Hopefully one of them does.
__________________
Trevazar/Trevius Owner of: Storm Haven
Everquest Emulator FAQ (Frequently Asked Questions) - Read It!
Reply With Quote
  #5  
Old 05-26-2008, 01:00 AM
Bulle
Hill Giant
 
Join Date: Jan 2008
Posts: 102
Default

No

You need just remember that $qglobals{max_level} is the replacement for $max_level.

So you could use :
Code:
if(defined($qglobals{max_level}))
to check that the variable is defined, in the same way you could have used if(defined($max_level))

Or you could use :
Code:
if($qglobals{max_level}) == 75)
to check if the variable is equal to 75 (after you have ensured it is defined !), in the same way you could have used if($max_level == 75)

If you want the safe solution in one "if" :
Code:
if(defined($qglobals{max_level}) && $qglobals{max_level} == 75)
With cascading "if"s :
Code:
if(!defined($qglobals{max_level}))
{ # Here you assume Max Level is 70 I guess
}
elsif($qglobals{max_level} == 71)
{ # Max Level is 71
}
elsif($qglobals{max_level} == 72)
{ # Max Level is 72
}
elsif($qglobals{max_level} == 73)
{ # Max Level is 73
}
elsif($qglobals{max_level} == 74)
{ # Max Level is 74
}
elsif($qglobals{max_level} == 75)
{ # Max Level is 75
}
else
{ # Damnit ! A super-hero !
}
Finally you can use a temporary variable (for a briefer notation), I just hope you won't get a warning in case the quest global is not defined, Perl's subtleties sometimes evade me :
Code:
$MaxLevel = $qglobals{max_level};
if(defined($MaxLevel) && $MaxLevel  == 75)
Notice how I propose a temporary variable different from max_level, to avoid any new weirdness

Note that to undefine a Perl variable I normally use this, instead of $XXX = undef :
Code:
undef($XXX);
I do not know whether both are equivalent. To delete a quest global from the DB the function to use is quest::delglobal as Gonner mentioned, which probably does NOT "undef" the associated variable. I have no idea whether the $qglobals map is updated at the same time, or only on next call to the script. This will have to be tested. it is the best way to know. In fact this should be tested for both delglobal and setglobal, and I hope they behave in a consistent way.
Reply With Quote
  #6  
Old 05-26-2008, 02:37 AM
Bulle
Hill Giant
 
Join Date: Jan 2008
Posts: 102
Default

I have made a few more tests with the following quest script. It is a bit long but it prints the variables at the start and end of the script :
Code:
my $LevelItemId = 1038; # Tattered Cloth Sandal
my $DefaultMaxLevel = 70;


sub EVENT_SAY
{ if(defined($maxxx_level))
  { print "maxxx_level($name) begin = $maxxx_level"; }
  else
  { print "maxxx_level($name) begin is not defined"; }
  
  if(defined($qglobals{maxxx_level}))
  { print "qglobals{maxxx_level}($name) begin = $qglobals{maxxx_level}"; }
  else
  { print "qglobals{maxxx_level}($name) begin is not defined"; }
  
  if(($text=~/65/i) && ($ulevel >= 70))
  { quest::say("Remember, DO NOT lose that trinket ! Welcome to level 65 !");
    quest::summonitem(1038);
    quest::level(65);
  }
  
  if($text=~/make me a newb/i)
  { quest::say("Arrr Arrr Arrr, my pleasure !");
    quest::level(1);
    quest::delglobal("maxxx_level"); undef($qglobals{maxxx_level});
  }
  if($text=~/make me level 73/i)
  { quest::say("OK, you're the boss after all *sigh*");
    quest::level(73);
    quest::setglobal("maxxx_level", 73, 5, "F"); $qglobals{maxxx_level} = 73;
  }
  if($text=~/make me level 75/i)
  { quest::say("OK, you're the boss after all *sigh*");
    quest::level(75);
    quest::setglobal("maxxx_level", 75, 5, "F"); $qglobals{maxxx_level} = 75;
  }

  if(defined($maxxx_level))
  { print "maxxx_level($name) end = $maxxx_level"; }
  else
  { print "maxxx_level($name) end is not defined"; }
  
  if(defined($qglobals{maxxx_level}))
  { print "qglobals{maxxx_level}($name) end = $qglobals{maxxx_level}"; }
  else
  { print "qglobals{maxxx_level}($name) end is not defined"; }
}


sub EVENT_ITEM
{ if(defined($maxxx_level))
  { print "maxxx_level($name) begin = $maxxx_level"; }
  else
  { print "maxxx_level($name) begin is not defined"; }
  
  if(defined($qglobals{maxxx_level}))
  { print "qglobals{maxxx_level}($name) begin = $qglobals{maxxx_level}"; }
  else
  { print "qglobals{maxxx_level}($name) begin is not defined"; }
  
  if(plugin::check_handin(\%itemcount, $LevelItemId => 1))
  { if(defined($qglobals{maxxx_level}))
    { quest::say("Welcome back to level $qglobals{maxxx_level}, $name");
      quest::level($qglobals{maxxx_level});
    }
    else
    { quest::say("Welcome back to level $DefaultMaxLevel, $name");
      quest::level($DefaultMaxLevel);
    }
  }
  else
  { plugin::return_items(\%itemcount);
    quest::say("I have no use for this item, $name.  Take it back.");
  } 

  if(defined($maxxx_level))
  { print "maxxx_level($name) end = $maxxx_level"; }
  else
  { print "maxxx_level($name) end is not defined"; }
  
  if(defined($qglobals{maxxx_level}))
  { print "qglobals{maxxx_level}($name) end = $qglobals{maxxx_level}"; }
  else
  { print "qglobals{maxxx_level}($name) end is not defined"; }
}
I have removed some level choices for simplicity.

Currently quest::...global do not update the $qglobals map to keep it in sync with DB changes done in the script so you have to update $qglobals explicitly.

As it is the script works fine : it updates the DB globals with quest::...global, and at the same time updates the $qglobals map for consistency, to keep them in sync.
If you code this way you can even re-read the $qglobals in the same sub, and it is consistent with what has been entered in the DB. It could be a nice "coding rule" for script writing. Best would be if the Emu server did that synchronization in quest::...global itself, I will have to look into that.
Reply With Quote
  #7  
Old 05-26-2008, 04:48 AM
trevius's Avatar
trevius
Developer
 
Join Date: Aug 2006
Location: USA
Posts: 5,946
Default

/bonks self

... Yeah, I see now. Sometimes the different ways people write things throws me off lol. I got it working perfectly so far. I think that should definitely do the trick. Thanks a ton, cause I was sick of having this issue so long lol.
__________________
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 05:03 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 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3