EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Quests::Q&A (https://www.eqemulator.org/forums/forumdisplay.php?f=599)
-   -   Player.pl question (https://www.eqemulator.org/forums/showthread.php?t=41780)

Aardil 02-23-2018 04:36 PM

Player.pl question
 
I an working on an event that covers several zones.
I am using Player.pl to detect the player level.

Through signals (determined by the player level)
A signal is sent to a zone controller.

Zone controller depops a few NPC's and spawns NPC's of the correct level.

All the above works as it should.

Now he question.

Since this happens in several zones, I am unsure of what to do with the player .pl

Should I take all signals from every zone and place them all in a single player.pl? ( it would end up being about 5000 lines of code ( 100 lines of code per zone and there are 50 effected zones).

If it all needs to go in one player.pl is there a way to sub devide the code by zone so it wont be looking through 5000 lines to find a match?
Maybe something like this?
Code:

sub EVENT_ZONE {
  if(zonen == "butcher"){
    if($ulevel <= 5 && $ulevel >= 1) {
    quest::signalwith(51,22,0);
        quest::signalwith(51,12,10);
        }
        elsif($ulevel <= 10 && $ulevel >= 6) {
        quest::signalwith(51,22,0);
        quest::signalwith(51,13,10);
        }
        elsif($ulevel <= 15 && $ulevel >= 11) {
        quest::signalwith(51,22,0);
        quest::signalwith(51,14,10);
        }
        elsif($ulevel <= 20 && $ulevel >= 16) {
        quest::signalwith(51,22,0);
        quest::signalwith(51,15,10);
        }
        elsif($ulevel <= 25 && $ulevel >= 21) {
        quest::signalwith(51,22,0);
        quest::signalwith(51,16,10);
        }
        elsif($ulevel <= 30 && $ulevel >= 26) {
        quest::signalwith(51,22,0);
        quest::signalwith(51,17,10);
        }
        elsif($ulevel <= 35 && $ulevel >= 31) {
        quest::signalwith(51,22,0);
        quest::signalwith(51,18,10);
        }
        elsif($ulevel <= 40 && $ulevel >= 36) {
        quest::signalwith(51,22,0);
        quest::signalwith(51,19,10);
        }
        elsif($ulevel <= 45 && $ulevel >= 41) {
        quest::signalwith(51,22,0);
        quest::signalwith(51,20,10);
        }
        elsif($ulevel <= 49 && $ulevel >= 46) {
        quest::signalwith(51,22,0);
        quest::signalwith(51,21,10);
        }
        else {
        quest::signalwith(50,22,0);
        }
        }
        }

The above code is not tested as written. It does what it should without the
if (zonen == "butcher") { line

Or can each zone have a specific player.pl that only effects that zone?

c0ncrete 02-23-2018 05:45 PM

you can have a player.pl for each zone, yes.

Aardil 02-23-2018 06:02 PM

ok that idea got shot to hell.
There is a player.pl in templates that is rather important in the newbie zones.
Some of this takes place in newbie zones so I can not write a specific player.pl for those zones.

Looking through commands (perl reference)
I see that there is a sub EVENT_ENTERZONE
and a sub EVENT_ZONE

Could I use both of these in the same player.pl?
sub EVENT_ENTERZONE is already being used and I dont want to break anything in that section.
If so I could use sub_EVENTZONE for what I need in the templet for the newbie zones and use a separate player.pl for the other zones.

c0ncrete 02-23-2018 06:42 PM

Yes, you can use both in the same script, but they do different things. ZONE fires any time any player zones (via Client::Handle_OP_ZoneChange()). ENTERZONE only fires on entering a zone (via Client::CompleteConnect()).

It should be simple enough to put a conditional in any EVENT that you are worried about adding to, and then have it call an external, custom subroutine or collection of them.

Also, you are able to call external files from your scripts via perl's 'do', that way you can keep all of your individual zone files separate, even if they're all in the same folder.

Code:

# current full working directory
( my $cwd = $0 ) =~ s/(?:(?!\\|\/)\S)+$//;

# hash with zonesn as keys and external scripts to run for the zone
my %signal_zone = {
        butcher => "singal_butcher.pl",
        cauldron => "signal_cauldron.pl"
};

# you'll want to add some sanity checks to make sure you have valid data here
sub EVENT_ENTERZONE
{
        do "${cwd}$signal_zone$zonesn";
}


Aardil 02-23-2018 07:46 PM

ok that might work as far as the player.pl issue.

I have one further question.
The whole purpose for using player.pl is so I can determine the player level.

Lets say I add Event_Zone in the original player.pl (the one in templates).
From your snippet, it signals the individual zone controller and it carries out the functions.

How do I pass along the user level info to the zone controller?

Am I back to 1000 lines because every 5 levels is a different signal?

For sake of argument.

I would prefere the player .pl (in templates using EVENT_ZONE)
to sense what zone and player level then pass both of those on to the zone controller.

Is it possible?

Aardil

c0ncrete 02-23-2018 08:15 PM

You can pass any information on to the external script via the use of @ARGV, as shown below.

Code:

my $player = "YoMomma";
my $zonesn = "butcher";

# current full working directory
( my $cwd = $0 ) =~ s/(?:(?!\\|\/)\S)+$//;

# you'll want to add some sanity checks to make sure you have valid data here
sub EVENT_ENTERZONE
{

        # hash with zonesn as keys and external scripts to run for the zone
        my %signal_zone = (
                butcher => "signal_butcher.pl",
                cauldron => "signal_cauldron.pl"
        );

        {
                local @ARGV = ($player);
                do "$cwd$signal_zone{$zonesn}";
        }
}

EVENT_ENTERZONE();

Above code calls the following (signal_butcher.pl located in the same folder):
Code:

print $ARGV[0];
Printed result:
Code:

YoMomma


All times are GMT -4. The time now is 02:48 PM.

Powered by vBulletin®, Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.