EQEmulator Forums

EQEmulator Forums (https://www.eqemulator.org/forums/index.php)
-   Quests::Q&A (https://www.eqemulator.org/forums/forumdisplay.php?f=599)
-   -   ENTERZONE Global Script (https://www.eqemulator.org/forums/showthread.php?t=41480)

The_Beast 08-14-2017 07:26 PM

ENTERZONE Global Script
 
Just an idea i have up in the air in at the moment. Obviously an ENTERZONE sub in the global player would apply to
all zones. But there's a little glitch in my plan, because there is some zones I don't want the script to run in.
I could put the script in every zone player file, but global would be more practical. What I am looking at
is running it in every "cancombat" zone only. (I am working with perl, not lua). Any ideas ? lol

ghanja 08-15-2017 10:59 PM

Several ways, varying in complexity and/or "work".

1. Likely the easiest unless you want to go at the source to add a new export, is:
Code:

sub EVENT_ENTERZONE {
    my @noncombatzones = ("freeportn", "runnyeye", "nexus");
    if ($zonesn ~~ @noncombatzones) {
          ## do nothing
    } else {
          ## do something
    }
}

Or some variance of the above. I chose non-combat zones in case there are fewer of them than combat zones.

2. Read from the DB using DBI (though this would of course create a potential for many calls to the DB):

Code:

sub readcombat {
    my $read_zone = $_[0];
    $connect = plugin::MySQL_Connect();
    $query = "
        SELECT `cancombat`
        FROM zone
        WHERE `short_name` = ? LIMIT 1
    ";
    $qh = $connect->prepare($query);
    $qh->execute($read_zone);
    while (@row = $qh->fetchrow_array()){
        return $row[0];
    }
    return;
}

return 1;

Tossing the above in either an existing plugin file or creating its own. Using it:

Code:

sub EVENT_ENTERZONE {
    if (plugin::readcombat($zonesn)) {
      ## do this when combat is 1 (aka true)
    } else {
      ## do this when combat is 0 (aka false)
    }
}

3. Edit the source to add an LUA/Perl export and, I've been away again too long from C++ to do this on the spot and I wasn't nearly as proficient at it as some others (Akka, Kingly, demon, hell any of the dev team)

So there's a start I hope.

The_Beast 08-16-2017 01:53 AM

Quote:

Originally Posted by ghanja (Post 255515)
Several ways, varying in complexity and/or "work".

1. Likely the easiest unless you want to go at the source to add a new export, is:
Code:

sub EVENT_ENTERZONE {
    my @noncombatzones = ("freeportn", "runnyeye", "nexus");
    if ($zonesn ~~ @noncombatzones) {
          ## do nothing
    } else {
          ## do something
    }
}

Or some variance of the above. I chose non-combat zones in case there are fewer of them than combat zones.

Wow, thank you so much. This number 1. looks like an easy work, if it can work. There is definately not many
non-combat zones. Just the regular common ones, GH, GL, PoK, Nexus, etc., so this would make it more simplified.
I will check it tomorrow and let you know :)

The_Beast 08-16-2017 06:34 AM

Well tried it out ghanja and it works great. I tested it out with just a simple little "movepc" for the #do something, lol
But had to change your ~~ to == (took me a few minutes to realize it) :P
But thanks a million for your help. It opens up some options for me. :)
EDIT : Sorry, not completely working right, I just let it do the movepc once and figured it was working great.
It's not recognizing the nocombatzones. I set it to punt me to the nexus, but it does that even when in one of the
zones specified. But I'll keep working on it.

ghanja 08-16-2017 12:05 PM

Please provide the code you're using. Smart matching should very much work.

The_Beast 08-16-2017 03:27 PM

I just used what you had to test the function of it with a movepc.

Code:

sub EVENT_ENTERZONE {
    my @noncombatzones = ("freeportn", "runnyeye", "nexus");
    if ($zonesn = @noncombatzones) {
          ## do nothing
    }
    else {
        quest::movepc(152,0,0,-31);
    }
}


NatedogEZ 08-16-2017 04:54 PM

Thats broke.. a single "=" just sets a variable to a value. :D

The_Beast 08-16-2017 05:22 PM

Quote:

Originally Posted by NatedogEZ (Post 255522)
Thats broke.. a single "=" just sets a variable to a value. :D

Oh sorry, that's a lazy typo in the post, lol The one I was testing has ==
which I changed over from ghanja's ~~ cause it wasn't doing anything

ghanja 08-16-2017 08:58 PM

Code:

sub EVENT_ENTERZONE {
        my @noncombatzones = ("freportn", "runnyeye", "nexus");  ## type the zonesn of the non-combat zones (thus cancombat = 0)
        if ($zonesn ~~ @noncombatzones) {
                ## this will happen if the zone they are in is one of the noncombatzones listed in the above array
        } else {
                ## this will happen if the zone they are in is NOT one of the noncombatzones listed in the above array
                $client->Message(15, "You are being moved now");
                quest::movepc(152,0,0,-31);
        }
}

I had an extra E, the zonesn should be freportn not freeportn, there should be no issues with using the smart matching (i.e. ~~)

Yeah, Perl will throw a fit if you are doing a Perl -c script.pl on it, but, its syntax is fine.

I'm under the assumption you're putting this code in your /quests/global/global_player.pl so ensure to target your test toon, issue a #reloadquest and then zone somewhere other than the test zones (which will be every zone not listed in the @noncombatzones array).

That said, I would just use the plugin method, if you have the DBI ppm installed.

The_Beast 08-16-2017 10:03 PM

Yes, I caught that freportn spelling the first time, but I never tested with that zone anyway. I was zoning into cancombat zones,
such as butcher, misty, etc., but nothing was happening until I changed the ~~ to == (as I mentioned in my post above) Then it
would punt me to nexus, even zoning into a noncombat zone, (like runnyeye) or any zone, for that matter.
This time I copied and pasted your last one into global_player.pl (I have #reloadquest hotkey) I use all the time.
I've used the DBI for few things in the past, successfully, so I will look at using that instead. Thank You muchly :)

The_Beast 08-17-2017 09:23 AM

This problem was solved by the way. It was too much human error and not enough human air. :P Seems I had a little
extra curly } hiding in the global player file before I pasted ghanja's script in there to test. But it works great now.
Many Thanks to ghanja :)

ghanja 08-17-2017 03:33 PM

I do believe this may fly (I always doubt things when it seems all too easy):

embparser.cpp

Replace line 1099 (as of current build) with:
Code:

        ExportVar(package_name.c_str(), "zonecancombat", zone->CanDoCombat());
}

Which, if I'm looking at everything right, should allow for a new exported variable of $zonecancombat

To use:
Code:

if ($zonecancombat) {
    ## do stuff for zones you CAN combat in
} else {
    ## do stuff for zones you can NOT combat in
}

Hopefully someone more intimately familiar with the source will come behind me and let us know otherwise or verify the above, either or.

The_Beast 08-18-2017 11:24 AM

Quote:

Originally Posted by ghanja (Post 255535)
I do believe this may fly (I always doubt things when it seems all too easy):

embparser.cpp

Replace line 1099 (as of current build) with:
Code:

        ExportVar(package_name.c_str(), "zonecancombat", zone->CanDoCombat());
}

Which, if I'm looking at everything right, should allow for a new exported variable of $zonecancombat

To use:
Code:

if ($zonecancombat) {
    ## do stuff for zones you CAN combat in
} else {
    ## do stuff for zones you can NOT combat in
}

Hopefully someone more intimately familiar with the source will come behind me and let us know otherwise or verify the above, either or.

This compiled fine with no errors, I'll let you know if it works, lol

The_Beast 08-18-2017 12:00 PM

No go on that, but, this is what I did to compile.(as per the code posted)
Code:

void PerlembParser::ExportZoneVariables(std::string &package_name) {
        if (zone) {
                ExportVar(package_name.c_str(), "zoneid", zone->GetZoneID());
                ExportVar(package_name.c_str(), "zoneln", zone->GetLongName());
                ExportVar(package_name.c_str(), "zonesn", zone->GetShortName());
                ExportVar(package_name.c_str(), "instanceid", zone->GetInstanceID());
                ExportVar(package_name.c_str(), "instanceversion", zone->GetInstanceVersion());
                TimeOfDay_Struct eqTime;
                zone->zone_time.GetCurrentEQTimeOfDay( time(0), &eqTime);
                ExportVar(package_name.c_str(), "zonehour", eqTime.hour - 1);
                ExportVar(package_name.c_str(), "zonemin", eqTime.minute);
                ExportVar(package_name.c_str(), "zonetime", (eqTime.hour - 1) * 100 + eqTime.minute);
                ExportVar(package_name.c_str(), "zoneweather", zone->zone_weather);
                ExportVar(package_name.c_str(), "zonecancombat", zone->CanDoCombat());
        }
}

Then added to global_player :
Code:

sub EVENT_ENTERZONE

  if ($zonecancombat) {
  quest::movepc(152,0,0,-31);
  } else {
    ## do stuff for zones you can NOT combat in
}


ghanja 08-18-2017 09:40 PM

Bah, figured it was just too easy. I'll have another look at the source. Havent had eyes in it for awhile, so is a re-re-relearn type of deal for me.


All times are GMT -4. The time now is 09:41 AM.

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