PDA

View Full Version : New Perl Command System


fathernitwit
11-08-2004, 02:26 PM
Well the new perl command system is in CVS. This lets you add new '#command' style in game commands written in perl. All old commands still work, this just allows you to extend it withouth coding in c++.

The commands go into a file named commands.pl in the same dir as the exe's.

things in features.h:
EMBPERL_COMMANDS - enable perl commands
EMBPERL_XS & EMBPERL_XS_CLASSES - not required, but theres not a lot you can do without them.
COMMANDS_PERL_OVERRIDE - allow perl commands to override C++ commands with the same name.

the only required sub in commands.pl is commands_init...
which should basically consist of a bunch of calls to command_add(command name, description, access_level).

Example commands.pl file displaying some example perl commands, as well as some of the stuff you can do with XS classes:

sub commands_init {
command_add("bank", "- spawn a temporary banker", 200);
command_add("giveitem", " (itemid) [charges] - give an item to a mob", 200);
}

sub bank {
#spawn Banker_Javen
quest::spawn(45054, 0, 0, $client->GetX()+10, $client->GetY(), $client->GetZ());
}

sub giveitem {
my $item = shift;
my $charges = 0;
if(defined($_[0])) {
$charges = shift;
}
my $target = $client->GetTarget();
if(!$target) {
$client->Message(13, "Error: You need a target!");
return;
} elsif(!$target->IsNPC()) {
$client->Message(13, "Error: your target must be an NPC!");
return;
}
my $n = $target->CastToNPC();
$client->Message(0, "Giving item $item to ".$n->GetName());
$n->AddItem($item, $charges);
}

Cisyouc
11-08-2004, 02:28 PM
This is a nifty idea...will #reloadquest refresh this file as well?

fathernitwit
11-08-2004, 02:33 PM
This is a nifty idea...will #reloadquest refresh this file as well?

Yes.

Rogean
11-08-2004, 03:10 PM
Very good job FNW.

RangerDown
11-08-2004, 03:21 PM
Wow! Nice work!

einsteinrs
11-08-2004, 04:01 PM
Cool
Keep up your great work FNW.

For me it s easier to code in perl than C++. It seems to me
that the new system has fixed also some broken quest commands.

Sorry for my bad english. I m german.

Kroeg
11-08-2004, 07:46 PM
Damn, you're the man... this is very exciting. I shall put this to great use in the near future! 8)

hypershadow66
11-09-2004, 06:34 AM
question on
command_add("bank", "- spawn a temporary banker", 200);
command_add("giveitem", " (itemid) [charges] - give an item to a mob", 200);

what is the , 200 for at the end?

and do we compile with perl like normal for this to compile?

Cisyouc
11-09-2004, 07:56 AM
Its the same syntax as command.cpp but without the function name at the end..

So the integer would be the default minimum status.

hypershadow66
11-09-2004, 08:07 AM
thanks cis, but i cant get the latest CVS to compile, it says im missing Common_profile.h you know where i can get this?