View Full Version : Hiring an npc, Can anyone help??
rixcraven
11-10-2012, 09:08 PM
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);
}
}
joligario
11-10-2012, 09:14 PM
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)
rixcraven
11-10-2012, 09:32 PM
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..
c0ncrete
11-10-2012, 10:11 PM
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:
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:
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
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:
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.
rixcraven
11-11-2012, 09:10 AM
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:
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:
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
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:
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);
}
Secrets
11-11-2012, 11:06 AM
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.
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.
sorvani
11-11-2012, 11:26 AM
and for god sakes use the damn code tags...
lerxst2112
11-11-2012, 04:20 PM
And, as c0ncrete demonstrated above, Perl will happily tell you where the syntax errors are, you just need to use it.
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.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.