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 11-10-2012, 09:08 PM
rixcraven
Sarnak
 
Join Date: Nov 2008
Location: UK
Posts: 57
Default Hiring an npc, Can anyone help??

Hi again..
Got this lil' script, which should allow the player to hire the Swordslinger, (for 5pp an hour), its not working, and I've no idea why, could someone please have a look and maybe popint me in the right direction??? Please!

sub EVENT_SAY {
my $fig = quest::saylink("fight");
if($text=~/Hail/i) {
quest::say("I am for hire, $name, and I'm currently charging 5pp per hour, Want me to fight for you $class?, just pass me 5pp");
}
sub EVENT_ITEM {
if(($platinum == 5)) {
quest::depop;
$client->MakePet(null, Trillion, "Trillion");
}
}



sub EVENT_TIMER {
if($timer eq "payme") {
quest::say("Time for my payment, $name");
quest::stoptimer("payme");
}
sub EVENT_ITEM {
if(($platinum == 5)) {
}
else {
quest::depop;
}
quest::settimer("payme", 60);
}
}
Reply With Quote
  #2  
Old 11-10-2012, 09:14 PM
joligario's Avatar
joligario
Developer
 
Join Date: Mar 2003
Posts: 1,497
Default

Multiple problems. One thing is you have two ITEM subs. Your brackets are also not matched up. And your logic may not accomplish what you are trying to do.

Not sure you are using this right: MakePet(spell_id, pettype, name=NULL)
Reply With Quote
  #3  
Old 11-10-2012, 09:32 PM
rixcraven
Sarnak
 
Join Date: Nov 2008
Location: UK
Posts: 57
Default

Quote:
Originally Posted by joligario View Post
Multiple problems. One thing is you have two ITEM subs. Your brackets are also not matched up. And your logic may not accomplish what you are trying to do.

Not sure you are using this right: MakePet(spell_id, pettype, name=NULL)
that bit works fine!!...
I didn't know yo couldn't have 2 event items, where I ran into problems was where I want the player to pay for the hours service..
Reply With Quote
  #4  
Old 11-10-2012, 10:11 PM
c0ncrete's Avatar
c0ncrete
Dragon
 
Join Date: Dec 2009
Posts: 719
Default

you can't have two subroutines with the same name in the same namespace in perl. only the last one ends up being used. if you want to check your scripts for compilation errors while writing them, add these lines at the top and run then from a command line, instead of using them from within the emulator:

Code:
use strict;
use warnings;
when you run your script from within the emulator, you'll most likely need to either remove the additional lines listed above or add the following to get them to run:

Code:
no strict 'vars';
if you were to add those lines to your script, you'd see a message similar to this one, indicating something likely isn't working as you expected it to:

example_script.pl
Code:
use strict;
no strict 'vars';
use warnings;

use constant {
    TRUE  => 1,
    FALSE => 0
};

sub conditionMet_1 {
    my $bool = defined($_[0]) ? shift : FALSE;
    print "DEBUG: checking conditionMet_1($bool)\n";
    return $bool;
}

sub conditionMet_2 {
    my $bool = defined($_[0]) ? shift : FALSE;
    print "DEBUG: in checking conditionMet_2($bool)\n";
    return $bool;
}

sub EVENT_ARBITRARY {
    # checking for TRUE(1) returned in both conditions
    # second condition is not checked if first fails
    if ( conditionMet_1(shift) && conditionMet_2(shift) ) {
        print "DEBUG: both conditions passed\n";
    }
    else {
        print "DEBUG: both conditions did not pass\n";
    }
}

sub EVENT_ARBITRARY {
    # same as before, but checking for FALSE on either condition
    # since this subroutine has the same name and is last in the list, it is used
    print "DEBUG: in second defintion of EVENT_ARBITRARY\n";
    if ( !conditionMet_1(shift) || !conditionMet_2(shift) ) {
        print "DEBUG: both conditions did not pass\n";
    }
    else {
        print "DEBUG: both conditions passed\n";
    }
}

EVENT_ARBITRARY(FALSE, TRUE);
output:
Code:
C:\EQEmu\sandbox>perl test_conditionals.pl
Subroutine EVENT_ARBITRARY redefined at test_conditionals.pl line 34.
DEBUG: in second defintion of EVENT_ARBITRARY
DEBUG: checking conditionMet_1(0)
DEBUG: both conditions did not pass
command-line debugging will also let you know when you have things like missing brackets, semicolons, or any other major syntax issues.
Reply With Quote
  #5  
Old 11-11-2012, 09:10 AM
rixcraven
Sarnak
 
Join Date: Nov 2008
Location: UK
Posts: 57
Default

Quote:
Originally Posted by c0ncrete View Post
you can't have two subroutines with the same name in the same namespace in perl. only the last one ends up being used. if you want to check your scripts for compilation errors while writing them, add these lines at the top and run then from a command line, instead of using them from within the emulator:

Code:
use strict;
use warnings;
when you run your script from within the emulator, you'll most likely need to either remove the additional lines listed above or add the following to get them to run:

Code:
no strict 'vars';
if you were to add those lines to your script, you'd see a message similar to this one, indicating something likely isn't working as you expected it to:

example_script.pl
Code:
use strict;
no strict 'vars';
use warnings;

use constant {
    TRUE  => 1,
    FALSE => 0
};

sub conditionMet_1 {
    my $bool = defined($_[0]) ? shift : FALSE;
    print "DEBUG: checking conditionMet_1($bool)\n";
    return $bool;
}

sub conditionMet_2 {
    my $bool = defined($_[0]) ? shift : FALSE;
    print "DEBUG: in checking conditionMet_2($bool)\n";
    return $bool;
}

sub EVENT_ARBITRARY {
    # checking for TRUE(1) returned in both conditions
    # second condition is not checked if first fails
    if ( conditionMet_1(shift) && conditionMet_2(shift) ) {
        print "DEBUG: both conditions passed\n";
    }
    else {
        print "DEBUG: both conditions did not pass\n";
    }
}

sub EVENT_ARBITRARY {
    # same as before, but checking for FALSE on either condition
    # since this subroutine has the same name and is last in the list, it is used
    print "DEBUG: in second defintion of EVENT_ARBITRARY\n";
    if ( !conditionMet_1(shift) || !conditionMet_2(shift) ) {
        print "DEBUG: both conditions did not pass\n";
    }
    else {
        print "DEBUG: both conditions passed\n";
    }
}

EVENT_ARBITRARY(FALSE, TRUE);
output:
Code:
C:\EQEmu\sandbox>perl test_conditionals.pl
Subroutine EVENT_ARBITRARY redefined at test_conditionals.pl line 34.
DEBUG: in second defintion of EVENT_ARBITRARY
DEBUG: checking conditionMet_1(0)
DEBUG: both conditions did not pass
command-line debugging will also let you know when you have things like missing brackets, semicolons, or any other major syntax issues.
Ok!,
had another shot, this is how it looks now
But, got a problem with the else statement?, anyone got thoughts, thanks for the help thus far!
sub EVENT_SAY {
if($text=~/Hail/i) {
quest::say("I am for hire, $name, and I'm currently charging 5pp per hour, Want me to fight for you $class?, just pass me 5pp");
}

sub EVENT_TIMER {
if($timer eq "payme") {
quest::say("Time for my payment, $name");
quest::stoptimer("payme");
}
}
else {
quest::say("No pay, no fighting, see you around, $name");
quest::depop;
}
sub EVENT_ITEM {
if(($platinum == 5)) {
quest::depop;
$client->MakePet(null, Trillion, "Trillion");
}
}
quest::settimer("payme", 60);
}
Reply With Quote
  #6  
Old 11-11-2012, 11:06 AM
Secrets's Avatar
Secrets
Demi-God
 
Join Date: May 2007
Location: b
Posts: 1,448
Default

You have syntax errors all over the place.

As a general rule of thumb, for every left bracket, there is a closing right bracket. If there's an if statement, a bracket follows that if statement to encapsulate the following commands.

For example,
sub EVENT_SAY { <-- Starting bracket for SUB_EVENT
if($name eq "Penny")
{ - If the name matches "Penny", do the below command.
quest::say("Hi Penny!");
} - Close the if statement
} - Close the subroutine.

I recommend taking a tutorial on perl. It will teach you elementary concepts about the scripting language.

http://www.tizag.com/perlT/

Furthermore, remember that you can set quest globals in order to save your variables past zoning, zone shutdown, or client desync. There are examples littered over this forum as well as on the EQEmulator wiki for a detailed description of how they work.

If you aren't ready to learn about that, using a simple variable would be good enough to track paid status. You would still have to kill the player's pet by depopping it by client ID, but this should get you started on checking a timer. Alternatively, use makepet to spawn a pet by NPC ID, assign a script to the pet in the templates folder.

The alternative would be something like what i listed below.

Code:
sub EVENT_ITEM {
if(($platinum == 5)) {
$client->MakePet(0, Trillion, "Trillion"); #change this to a static NPC types ID
}
else
{
quest::say("That's not 5 platinum, $name!");
}
}

sub EVENT_SAY {
if($text=~/Hail/i) {
quest::say("I am for hire, $name, and I'm currently charging 5pp per hour, Want me to fight for you $class?, just pass me 5pp");
}
}
You'll have to do the NPC script seperate, but basically hand your pet 5 plat every so often to make sure it doesn't despawn.

Hope that helps.
Reply With Quote
  #7  
Old 11-11-2012, 11:26 AM
sorvani
Dragon
 
Join Date: May 2010
Posts: 966
Default

and for god sakes use the damn code tags...
Reply With Quote
  #8  
Old 11-11-2012, 04:20 PM
lerxst2112
Demi-God
 
Join Date: Aug 2010
Posts: 1,743
Default

And, as c0ncrete demonstrated above, Perl will happily tell you where the syntax errors are, you just need to use it.

Code:
C:\Temp>perl -c t.pl
syntax error at t.pl line 12, near "else"
syntax error at t.pl line 23, near "}"
t.pl had compilation errors.
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 02:36 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 - 2024, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3