PDA

View Full Version : My first attempt at a "watcher" script


Neiv
09-12-2008, 11:02 AM
Here's what I've come up with. Any help in this would be greatly appreciated.

Background: Player finds item, and item gives him pvp status until he can take the item safely to his kingdom. Each time player zones, certain npcs look for him in an attempt to get the item (via an aggro object in player.pl). If one of those npcs catches up with him and kills him, the following script is triggered:


#Slayer pl
sub EVENT_SLAY
{
if(plugin::check_hasitem($client, 13732)) #slayer looks for item#
{
quest::setglobal("kingdomfaction", 4, 7, "F"); #gives kingdom faction to kingdom 4#
$client->NukeItem(13732);#slayer takes item#
$client->SetPVP(0); #removes pvp status from itembearer#

my $x;
my $y;
my $z;
my $h;

$x = $npc->GetX();
$y = $npc->GetY();
$z = $npc->GetZ();
$h = $npc->GetHeading();

quest::setglobal("king", 4, 7, "F"); #sets global for watcher#
quest::spawn2(999247,0,0,$x+5,$y+5,$z,$h);
#Lord over the kingdom of the slayer is spawned at the loc of the player corpse#
}
}


At this point the player zones due to death, making it likely that the zone will be empty of PCs; hence, the watcher:


#Watcher pl -- watcher is on a 2-point stationary grid with a 5-sec delay
SUB EVENT_WAYPOINT
{
if (defined($qglobals{king}))
{
if ($qglobals{king} == 4)
{
quest::signal(999247,1); #signals Lord spawned in slayer script#
}
}
}


The watcher, in theory, should keep pinging the global until the watcher signals the spawned Lord of the slayer once the player arrives back in the zone. The Lord script is below:


#Lord pl -- spawned in slayer script
and signaled by watcher

sub EVENT_SIGNAL
{
quest::settimer("kneel",10);
quest::setsky(14); #sky is changed
quest::selfcast(3430); #bright light surrounds the Lord of slayer
}


sub EVENT_TIMER
{
if(timer eq "kneel")
{
$npc->SetAppearance(4); #Lord of slayer kneels next to corpse#
quest::shout("Ah, so there you are");
quest::settimer("shout",10);
}

if(timer eq "shout")
{
$npc->SetAppearance(0); #Lord of slayer stands#
quest::shout2("My servants, hear me and rejoice! For my power and cruelty have returned to me. I now reign supreme. Join me, my minions, and together we shall destroy our enemies!");
quest::settimer("depop",10);
}

if(timer eq "depop")
{
quest::setsky(1); #returns sky to normal
quest::delglobal("king"); #king global set by slayer seleted
quest::depop(); #Lord of slayer disappears
}
}


I have tried this out, and once I am killed and zone back into the zone the Lord is standing there by my corpse but does nothing more. What am I doing wrong?

Neiv
09-12-2008, 12:01 PM
Just to avoid wasting anyone's time, I've already caught SUB EVENT_WAYPOINT and changed it to sub EVENT_WAYPOINT.

I also placed . . .

"quest::delglobal("king");"

just above the "quest::setglobal("king", 4, 7, "F");" in the Slayer script.

The script is still not working.

Angelox
09-12-2008, 12:07 PM
Did you check for typos? again, this (http://enginsite.com/Perl.htm) will help.

joligario
09-12-2008, 12:29 PM
Might want to change timer to $timer

Angelox
09-12-2008, 12:33 PM
Might want to change timer to $timer

Yea, good idea, hehe! I didn't see that one.

Neiv
09-12-2008, 12:43 PM
The syntax of all three scripts checks out "ok"

Neiv
09-12-2008, 12:45 PM
Might want to change timer to $timer

GAH! How could I have missed that? I'll try the script again and see if it works. Does the watcher script look okay to you, Angelox?

Neiv
09-12-2008, 12:49 PM
Script still does not work :(

Angelox
09-12-2008, 12:52 PM
GAH! How could I have missed that? I'll try the script again and see if it works. Does the watcher script look okay to you, Angelox?

Looks good, but you never know tell you try; put a lot of quest shouts in there so you know where it gets hung up, my buddy Qadar came up with this type de-bugger which I think is very cool (notice the quest global variable $debugpl2);
sub EVENT_WAYPOINT {
## In Butcher > Oot ########################### In Butcher > Oot ###########
if (($skiffa==0.5) && ($skiffa < 40)){
if($debugpl2==1){quest::shout ("Zoneing in From the timorous, setting 1");}
quest::delglobal("skiffa");
quest::setglobal("skiffa",1,7,"F");
$skiffa=undef;}
elsif (($skiffa==1) && ($skiffa < 40)){
if($debugpl2==1) {quest::shout ("setting 2");}
quest::delglobal("skiffa");
quest::setglobal("skiffa",2,7,"F");
$skiffa=undef;}
elsif (($skiffa==2) && ($skiffa < 40)){
if($debugpl2==1) {quest::shout ("setting 3");}
quest::delglobal("skiffa");
quest::setglobal("skiffa",3,7,"F");
$skiffa=undef;}
elsif (($skiffa==3) && ($skiffa < 40)){
if($debugpl2==1) {quest::shout ("setting 4");}
quest::delglobal("skiffa");
------------Snipped--------------

set global '$debugpl2' to 1 and it shouts, set to 0 and it doesn't. So now you can track and debug anywhere your script gets hung up.

Angelox
09-12-2008, 01:38 PM
I don't understand this;
if (defined($qglobals{king}))
and also, I try to make my globals as short as possible;
kingdomfaction = king1
you have to follow sequence to set a global;
quest::delglobal("king1");
quest::setglobal("king1",3,7,"F");
$king1=undef;}


And I don't know how this;
if (defined($qglobals{king}))
is related.

Neiv
09-12-2008, 01:39 PM
Okay, I've narrowed down the problem to the watcher script. I sandwiched the "setglobal" in the slayer script between two shouts, like this:


quest::delglobal("king");
quest::shout("global deleted, resetting global");
quest::setglobal("king", 4, 7, "F");
quest::spawn2(999247,0,0,$x+5,$y+5,$z,$h);
quest::shout("king spawned, handing off to watcher");

I can see both shouts in the chat box as I zone due to death, so that tells me the global is setting. Plus, the fact that the king actually npc spawns in the spawn2 function tells me it's making it through.

I also added some shouts to the watcher script, like this:

sub EVENT_WAYPOINT
{
quest::shout("start WAY POINT");
if (defined($qglobals{king}))
{
if ($qglobals{king} == 4)
{
quest::shout("start signal");
quest::signal(999247);
quest::shout("signal completed");
}
}
}



The first watcher shout ("start WAY POINT") repeats every five seconds, but never proceeds to the second or third shouts. That tells me something is amiss in one of the two $qglobals lines. Any thoughts?

AndMetal
09-12-2008, 01:56 PM
Is your watcher set to have access to qglobals in the npc_types table?

Neiv
09-12-2008, 02:11 PM
Is your watcher set to have access to qglobals in the npc_types table?
I didn't bother changing that flag since my other global works fine without it. In my kingdom global, the king sets a global for a kingdom buff and that works fine; and another npc deletes that global when the kingdom has been defeated, and that works fine. Are you saying the access needs to be turned on only on an npc that is checking a global? I went ahead and tuned it on for all npcs involved just in case.

In the meantime . . .

I have been playing with the watcher script and changed it from this:
sub EVENT_WAYPOINT
{
quest::shout("start WAY POINT");
if (defined($qglobals{king}))
{
if ($qglobals{king} == 4)
{
quest::shout("start signal");
quest::signal(999247);
quest::shout("signal completed");
}
}
}


. . . to this:

sub EVENT_WAYPOINT
{
quest::shout("start WAY POINT");
if (defined($qglobals{king} == 4))
{
quest::shout("start signal");
quest::signal(999247);
quest::shout("signal completed");
}
}



All the shouts are now displaying as they should, but the spawned king still is not doing what he needs to do. I'm going to start playing with him, but does the revised slayer script look right?

Angelox
09-12-2008, 02:16 PM
No it only looks like it's working, but it's not - set the flag

AndMetal
09-12-2008, 03:05 PM
Just to clarify, the flags allows that particular NPC to view the globals. This is so they don't have to exported for every single NPC (which, as you can imagine, can be VERY resource intensive). Anyone can set a global, even without the flag set in npc_types. That's why you can set it in the player.pl file (which coincidentally has the globals accessable automatically), but can't read it in the watcher script.

This caused me a lot of headache with the PoJ Trial of Execution when it was first changed, but once I figured it out, it was easy enough to fix.

Angelox
09-12-2008, 03:14 PM
I would have mine working 'half-assed' when I forget to set that- it would do things like make the global, but not change it.

Neiv
09-13-2008, 05:04 PM
Okay, appreciate the tip on setting the qglobal flag on the npcs. Things are almost working correctly. I'm currently having an issue with the watcher. The signal script on the watcher triggers a settimer on the spawned npc. That timer has three parts to it so that the npc kneels to simulate "looting" the item (actually stripped from the client by the slayer), then stands to make an announcement to the server that he is now ruling the world, then depops. The problem is, the watcher keeps tripping the timer and restarting it before the npc is able to depop. How do I get the signal to stop?

joligario
09-13-2008, 08:08 PM
When using quest::settimer(id,time), as soon as it hits 0, it will start over and repeat itself. Make sure you are using quest::stoptimer(id).

Another idea (not sure if it will work; you will need to test)... you might be able to have him signal himself. For example, looks like the NPCID is 999247. To start the sequence, I would have the watcher signal the Lord:

#Watcher.pl ()
sub EVENT_WAYPOINT {
if (defined($qglobals{king})) {
if ($qglobals{king} == 4) {
quest::signalwith(999247,1,1); #Signal 1 to Lord
}
}
}

Then I would have the lord do this:

#Lord.pl (999247)
sub EVENT_SIGNAL {
if ($signal == 1) { #Sequence started
quest::setsky(14); #Change sky
quest::selfcast(3430); #Light of Nife
quest::signalwith(999247,2,10); #Tell Lord to kneel
}
if ($signal == 2) { #Kneel
$npc->SetAppearance(4); #Kneeling appearance
quest::shout("Ah, so there you are");
quest::signalwith(999247,3,10); #Tell Lord to shout
}
if ($signal == 3) { #Shout
$npc->SetAppearance(0); #Standing appearance
quest::shout2("My servants, hear me and rejoice! For my power and cruelty have returned to me. I now reign supreme. Join me, my minions, and together we shall destroy our enemies!");
quest::signalwith(999247,4,10); #Tell Lord to depop
}
if ($signal == 4) { #Depop
quest::setsky(1); #Change sky to normal
quest::delglobal("king"); #Delete global
$king = undef;
quest::depop(); #Depop
}
}

Once again, you will have to test. I am not sure if the scripting will efficiently allow to signal itself. If not, have the watcher send the signals with 10 second additions.

Neiv
09-14-2008, 12:03 AM
I will try this, thanks. One point though. I have a stoptimer on all the timers, so I don't think that's the problem. The shout and emote statements are being repeated, and I have to think that's due to the EVENT_WAYPOINT, which triggers each time the npc leaves a waypoint (in this case, every 7 seconds--I tried adjusting it to 10 seconds, but the npc stalls out for some reason). Which is also why I'm dubious about adding seconds to the timer function of the watcher (whether in a timer or a signalwith function). If the watcher re-signals the Lord each time he leave a waypoint, and if the pause time of the waypoint movement is set to 7, then it seems to me that the waypoint movement of the watcher will override any longer duration of time I set in a timer on the Lord. Feel free to correct me on this if I'm wrong.

I'll try the signalwith function and see if I get different results. Thanks again.

joligario
09-14-2008, 12:51 AM
Here's what I've come up with. Any help in this would be greatly appreciated.

Background: Player finds item, and item gives him pvp status until he can take the item safely to his kingdom. Each time player zones, certain npcs look for him in an attempt to get the item (via an aggro object in player.pl). If one of those npcs catches up with him and kills him, the following script is triggered:


#Slayer pl
sub EVENT_SLAY
{
if(plugin::check_hasitem($client, 13732)) #slayer looks for item#
{
quest::setglobal("kingdomfaction", 4, 7, "F"); #gives kingdom faction to kingdom 4#
$client->NukeItem(13732);#slayer takes item#
$client->SetPVP(0); #removes pvp status from itembearer#

my $x;
my $y;
my $z;
my $h;

$x = $npc->GetX();
$y = $npc->GetY();
$z = $npc->GetZ();
$h = $npc->GetHeading();

quest::setglobal("king", 4, 7, "F"); #sets global for watcher#
quest::spawn2(999247,0,0,$x+5,$y+5,$z,$h);
#Lord over the kingdom of the slayer is spawned at the loc of the player corpse#
}
}


At this point the player zones due to death, making it likely that the zone will be empty of PCs; hence, the watcher:


#Watcher pl -- watcher is on a 2-point stationary grid with a 5-sec delay
SUB EVENT_WAYPOINT
{
if (defined($qglobals{king}))
{
if ($qglobals{king} == 4)
{
quest::signal(999247,1); #signals Lord spawned in slayer script#
}
}
}


The watcher, in theory, should keep pinging the global until the watcher signals the spawned Lord of the slayer once the player arrives back in the zone. The Lord script is below:


#Lord pl -- spawned in slayer script
and signaled by watcher

sub EVENT_SIGNAL
{
quest::settimer("kneel",10);
quest::setsky(14); #sky is changed
quest::selfcast(3430); #bright light surrounds the Lord of slayer
}


sub EVENT_TIMER
{
if(timer eq "kneel")
{
$npc->SetAppearance(4); #Lord of slayer kneels next to corpse#
quest::shout("Ah, so there you are");
quest::settimer("shout",10);
}

if(timer eq "shout")
{
$npc->SetAppearance(0); #Lord of slayer stands#
quest::shout2("My servants, hear me and rejoice! For my power and cruelty have returned to me. I now reign supreme. Join me, my minions, and together we shall destroy our enemies!");
quest::settimer("depop",10);
}

if(timer eq "depop")
{
quest::setsky(1); #returns sky to normal
quest::delglobal("king"); #king global set by slayer seleted
quest::depop(); #Lord of slayer disappears
}
}


I have tried this out, and once I am killed and zone back into the zone the Lord is standing there by my corpse but does nothing more. What am I doing wrong?

Ok, this is what I was going with. I don't see any stoptimer here so that is why I was checking. If you have more code to it, maybe posting your updated code might show us what problem you are having.

Neiv
09-14-2008, 09:18 AM
Yeah, sorry about that. I have modified this several times since I posted. Here is the Lord script with the stoptimers:


sub EVENT_SIGNAL
{
quest::settimer("kneel",3);
quest::setsky(0);
quest::selfcast(3430);
}

sub EVENT_TIMER
{
if($timer eq "kneel")
{
$npc->SetAppearance(4);
quest::shout("Ah, there you are!");
quest::settimer("shout",3);
}
if($timer eq "shout")
{
quest::stoptimer("kneel");
$npc->SetAppearance(0);
quest::shout2("My servants, hear me and rejoice! For my power and cruelty have returned to me. I now reign supreme. Join me, my minions, and together we shall destroy our enemies!");
quest::settimer("depop",3);
}
if($timer eq "depop")
{
quest::stoptimer("shout");
quest::setsky(1);
quest::delglobal("king");
quest::emote("fades into shadow");
quest::depop();
}
}


I have also tried putting the stoptimer at the end of each timer block rather than at the beginning of the next timer, but the problem persists. My latest version of the script is this:


sub EVENT_SIGNAL
{
quest::settimer("kneel",3);
quest::setsky(0);
quest::selfcast(3430);
}

sub EVENT_TIMER
{
if($timer eq "kneel")
{
$npc->SetAppearance(4);
quest::shout("Ah, there you are!");
quest::settimer("shout",3);
}
if($timer eq "shout")
{
quest::stoptimer("kneel");
$npc->SetAppearance(0);
quest::shout2("My servants, hear me and rejoice! For my power and cruelty have returned to me. I now reign supreme. Join me, my minions, and together we shall destroy our enemies!");
quest::stoptimer("shout");
quest::setsky(1);
quest::delglobal("king");
quest::emote("fades into shadow");
quest::depop();
}
}


This version seems to work since the Lord is nowhere in sight once I zone back in (I am bound at the same point in the zone where I am killed so I can check movement once back in), but by the time I zone back in, the Lord has poofed. I'd really like to fix this so that I can actually see the Lord's movements without the watcher restarting the signal script each time he leaves a waypoint.

joligario
09-14-2008, 09:42 AM
Ok, I see. You could add a variable that doesn't allow him to continuously react to signals. And with your stoptimers, you should stop them as soon as the trigger hits. Take a look at this example:

my $started;

sub EVENT_SPAWN {
$started = 0;
}

sub EVENT_SIGNAL {
if ($started == 0) {
$started = 1;
quest::setsky(0);
quest::selfcast(3430);
quest::settimer("kneel",3);
}
}

sub EVENT_TIMER {
if($timer eq "kneel") {
quest::stoptimer("kneel");
$npc->SetAppearance(4);
quest::shout("Ah, there you are!");
quest::settimer("shout",3);
}
if($timer eq "shout") {
quest::stoptimer("shout");
$npc->SetAppearance(0);
quest::shout2("My servants, hear me and rejoice! For my power and cruelty have returned to me. I now reign supreme. Join me, my minions, and together we shall destroy our enemies!");
quest::settimer("depop",3);
}
if($timer eq "depop") {
quest::stoptimer("depop");
quest::setsky(1);
quest::delglobal("king");
quest::emote("fades into shadow");
quest::depop();
}
}

Neiv
09-14-2008, 10:34 PM
my $started;

sub EVENT_SPAWN {
$started = 0;
}

sub EVENT_SIGNAL {
if ($started == 0) {
$started = 1;

This code is crashing the zone. I looked at the QuestObjects page and didn't see anything like it there.

joligario
09-15-2008, 02:08 AM
I've never used a my outside of a sub before, just saw that used in another file. Maybe put it inside the spawn? Not sure if that will change the scope of it though, which will negate what I was doing...

Or try my $started = 0;

That's the only thing I could think of that would be wrong here.

Neiv
09-17-2008, 08:41 PM
Or try my $started = 0;

That did it. Works like a charm now. Thanks!