View Full Version : Timer Problem
Randymarsh9
05-12-2009, 05:32 PM
Ok I have a quest where the npc starts a timer and is supposed to kick the person back to PoK after a minute and a half. Nothing happens.
This is the quest giver
sub EVENT_SAY{
if ($text=~/hail/i){
quest::say("text");
}
if ($text =~/ready/i){
quest::spawn(1295,0,0,-31.4,-165.8,0.5);
quest::moveto(-1094.4, 29.7, -26.9);
quest::settimer("wizboot", 90);
}
}
sub EVENT_TIMER{
if ($timer eq "wizboot"){
quest::movepc(202,-107,-190,-156);
quest::stoptimer("wizboot");
}
}
I also added
if ($timer eq "wizboot"){
quest::movepc(202, -107,-190,-156);
quest::stoptimer("wizboot");
}
to player.pl. For some reason this won't boot the person back to PoK
joligario
05-12-2009, 06:08 PM
I don't believe player.pl has access to your NPC timer. You should try to run it all from player.pl.
Randymarsh9
05-12-2009, 06:20 PM
how would I have it start from player.pl
trevius
05-12-2009, 06:21 PM
Doing that is actually a bit more complex than it might sound. There are a couple of ways to do it, but here is a way that I recently wrote to handle a similar situation and modified to fit what you are wanting:
npcname.pl file for the npc giving the quest
sub EVENT_SAY {
if($text=~/hail/i && defined($qglobals{zone_wiz}))
{
quest::say("You have already started this event.");
}
if($text=~/hail/i && !defined($qglobals{zone_wiz}))
{
quest::say("You have about 1.5 minutes before you get booted!");
quest::setglobal("zone_wiz", 1, 5, "M1");
quest::setglobal("zone_wiz_delay", 1, 5, "M2");
}
}
player.pl in the zone shortname directory
sub EVENT_ZONE {
quest::stoptimer("wizboot");
}
sub EVENT_ENTERZONE {
quest::settimer("wizboot", 5);
}
sub EVENT_TIMER {
if ($timer eq "wizboot")
{
quest::stoptimer("wizboot");
if (!defined($qglobals{zone_wiz}) && defined($qglobals{zone_wiz_delay})) {
quest::delglobal(zone_wiz_delay);
$client->Message(15, "You are returning to PoK now!");
quest::movepc(202, -107,-190,-156);
}
quest::settimer("wizboot", 5);
}
}
That is a quick edit, so I may have missed something, but I think that should work for you. Basically, in the player.pl, there is no easy way to trigger a timer to start, so I have one running that starts when a player zones in. If you expect to have many people in this zone, you might want to set the delay longer so it isn't working too hard on it (I set mine to check ever 60 secs), but if you are only having a couple in the zone, 5 sec checks should be fine.
Randymarsh9
05-12-2009, 07:01 PM
Alright I edited in the stuff you suggested and its working perfectly. Thanks again for the help
Randymarsh9
05-24-2009, 08:34 PM
I am making a quest where ideally the NPC will cycle through a group of phrases, but it isn't even saying the first thing.
sub EVENT_SPAWN{
quest::settimer("Timer1",10);
}
sub EVent_TIMER{
if ($timer eq "Timer1"){
quest::say("text");
quest::stoptimer("Timer1");
quest::settimer("Timer2",10);
}
if ($timer eq "Timer2"){
quest::say("text");
quest::stoptimer("Timer2");
quest::settimer("Timer3",10);
}
if ($timer eq "Timer3"){
quest::say("text");
quest::stoptimer("Timer3");
quest::settimer("Timer4",10);
}
if ($timer eq "Timer4"){
quest::say("text");
quest::stoptimer("Timer4");
quest::settimer("Timer1",10);
}
}
joligario
05-24-2009, 08:37 PM
Did you try changing EVent to EVENT? Not sure if it is case sensitive or not, but most likely it is.
Randymarsh9
05-24-2009, 10:22 PM
I tried that, but it still doesnt work
trevius
05-24-2009, 10:35 PM
Yeah, you do definitely need to make sure to use all uppercase. That script should work fine when you have it set like this:
sub EVENT_SPAWN {
quest::settimer("Timer1",10);
}
sub EVENT_TIMER {
if ($timer eq "Timer1"){
quest::say("text1");
quest::stoptimer("Timer1");
quest::settimer("Timer2",10);
}
if ($timer eq "Timer2"){
quest::say("text2");
quest::stoptimer("Timer2");
quest::settimer("Timer3",10);
}
if ($timer eq "Timer3"){
quest::say("text3");
quest::stoptimer("Timer3");
quest::settimer("Timer4",10);
}
if ($timer eq "Timer4"){
quest::say("text4");
quest::stoptimer("Timer4");
quest::settimer("Timer1",10);
}
}
Make sure to do a #reloadquest and also a #repop to start the timer. Also, make sure you have the script named properly.
joligario
05-24-2009, 10:44 PM
Maybe try integers instead of strings for timer id as a last resort.
Congdar
05-24-2009, 11:06 PM
If you use integers, change eq to ==
sub EVENT_SPAWN {
quest::settimer(1, 10);
}
sub EVENT_TIMER {
if ($timer == 1){
quest::say("text1");
quest::stoptimer(1);
quest::settimer(2, 10);
}
if ($timer == 2){
quest::say("text2");
quest::stoptimer(2);
quest::settimer(3, 10);
}
if ($timer == 3){
quest::say("text3");
quest::stoptimer(3);
quest::settimer(4, 10);
}
if ($timer == 4){
quest::say("text4");
quest::stoptimer(4);
quest::settimer(1, 10);
}
}
Yeormom
06-18-2009, 11:47 PM
I was messing around with event timers the other night and it appeared that the timer could not get the player that triggered the event. Things like quest::movepc() didn't function and $client wasn't exported for the timer event.
Capheus
06-19-2009, 10:17 AM
Getting $client in a timer in most cases will not happen cause a timer is not triggered by the client. Is these cases you have to store the client in another variable or qglobal. I have the common types below, but there are many other ways of doing this too.
sub EVENT_SPAWN {
$x = $npc->GetX();
$y = $npc->GetY();
quest::set_proximity($x - 20, $x + 20, $y - 20, $y + 20);
quest::settimer("testclient",5);
}
sub EVENT_SAY {
if($text=~/hail/i)
{$firstclient = $client;}
}
sub EVENT_AGGRO {
$secondclient = $client;
}
sub EVENT_COMBAT {
$thirdclient = $client;
}
sub EVENT_ENTER {
$fourthclient = $client;
}
sub EVENT_ENTERZONE {
$fifthclient = $client;
}
sub EVENT_TIMER {
if ($timer eq "testclient") {
if ($firstclient != 0)
{$cone = $firstclient->GetName();}
if ($secondclient != 0)
{$ctwo = $secondclient->GetName();}
if ($thirdclient != 0)
{$cthree = $thirdclient->GetName();}
if ($fourthclient != 0)
{$cfour = $fourthclient->GetName();}
if ($fifthclient != 0)
{$cfive = $fifthclient->GetName();}
quest::say("$cone");
quest::say("$ctwo");
quest::say("$cthree");
quest::say("$cfour");
quest::say("$cfive");
}
}
Yeormom
06-19-2009, 10:43 AM
Some of the data is sent to the timer event, such as $name of player and $entity_list for the zone. I was specifically trying to functions for the client but those seemed to fail as well, strangely enough.
sub EVENT_TIMER
{
quest::say("Hello $name");
$c = $entity_list->GetClientByName($name);
$charname = $c->GetName();
quest::say("Hi $charname");
$c->MovePC(1,1,1,1);
$c->CastSpell(1,1);
}
Output:
NPC says, 'Hello JohnDoe'
NPC says, 'Hi JohnDoe'
*crickets*
*more crickets*
Not an actual script but prefect representation if all function input had valid data.
Congdar
06-19-2009, 05:58 PM
not sure if this will fix it, but the client movepc function takes 5 parameters... zoneid, x, y, z, heading
and since movepc failed, castspell probably didn't even get called.
Yeormom
06-19-2009, 06:10 PM
Well that was just a sample of what would happen and would produce the same results each time, even if only one line per event_timer. The heading parameter is optional. The perl parser checks to see if there are 4 or 5 parameters, and a default is used if only 4 are present.
I just rewrote the quest functions to get the client by entity_list if initiator was not defined for my solution, as it appears not all data is exported when an event timer is triggered. Not sure how some people are reporting they are successfully using quest functions like selfcast and movepc in the EVENT_TIMER call.
Capheus
06-20-2009, 09:34 AM
Ok, trying to figure out what you are looking for. Here is another script that will allow you to use the client in sub EVENT_TIMER.
sub EVENT_SAY {
if($text=~/hail/i) {
quest::say("Would you like a [buff] or would you like to [goto] Crushbone?");
}
if($text=~/buff/i) {
quest::say("Ok hold on while I get you the spell in my book.....");
$theclienteid = $client->GetID(); #store client id
$thename = $name; #store client name
$theclient = $client; #store client
quest::settimer("heal",10);
}
if($text=~/goto/i) {
quest::say("Ok hold on while I find the right coordinates.....");
quest::settimer("goto",10);
$thename = $name; #store client name
$theclient = $client; #store client
}
}
sub EVENT_TIMER {
if ($timer eq "heal") {
quest::say("Found it! This should help $thename.");
quest::stoptimer("heal");
$theclient->CastSpell(26,$theclienteid); #casts skin like wood on self
}
if ($timer eq "goto") {
quest::say("Off you go $thename!");
quest::stoptimer("goto");
$theclient->MovePC(58,143.4,-595.8,3.1,62.4); #MovePC(zoneID, x, y, z, h)
}
}
Yeormom
06-20-2009, 11:06 AM
I'll give that a whurl Capheus. That's exactly what I was trying to do with little to no successful results. I'm starting to believe it has something to do with my highly customized build of Perl that I use for other applications. Thanks for taking the time to post your example.
I rewrote the timer trigger event so it tracks and always exports $client and $npc now so even the generic quest functions like quest::movepc() work now in EVENT_TIMER. I'll need to do more QA against it before distribution can be considered.
trevius
06-20-2009, 05:06 PM
Just a minor note that might help a bit;
When exporting the client (or anything for that matter) to a timer, you always want to check for a NULL pointer before doing anything with it. Otherwise, if your client has died or left the zone, the zone will probably crash when you try to use the pointer later. Here is an example of what I mean from part of the script posted above:
if ($theclient && $theclienteid) {
$theclient->CastSpell(26,$theclienteid); }
Yeormom
06-20-2009, 05:09 PM
You most often don't get the crash if the player has left the zone since the perl client is checking to see if the reference is defined and IsClient() but when a player re-enters the zone with the timer still active, as their $entity_list id has changed.
Capheus
06-21-2009, 02:18 AM
Never knew about the zone crashing thing, I'll have to keep that in mind.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.