PDA

View Full Version : auto talk after death


ube2
9th June 2005, 09:15
I made this plugin in response to someone wanting this feature.
http://openkore.sourceforge.net/forum/viewtopic.php?t=3489

You can trigger it manually by using the command "autotalk"

talkAuto_afterDeath <flag>
whether you want to automatically talk to the NPC after death
talkAuto_distance <number>
distance away from NPC you should go
talkAuto_npc map x y
location of the NPC
talkAuto_npc_steps chat sequence
chat steps to take when talking to the NPC

example:
talkAuto_afterDeath 1
talkAuto_distance 5
talkAuto_npc comodo 188 162
talkAuto_npc_steps c r0 n

autotalk.pl
################################################## ##########
#
# autotalk
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

package autotalk;

use strict;
use Plugins;
use AI;
use Commands;
use Globals;
use Log;
use Utils;

Plugins::register('autotalk', 'talks to NPC after death or via command', \&unload);
my $mainLoopHook = Plugins::addHook('AI_pre', \&mainLoop);
my $hookCommandPost = Plugins::addHook('Command_post', \&onCommandPost);

sub unload {
Plugins::delHook('AI_pre', $mainLoopHook);
Plugins::delHook('Command_post', $hookCommandPost);
}

sub onCommandPost {
my (undef, $args) = @_;
my ($cmd, $subcmd) = split(' ', $args->{input}, 2);

if ($cmd eq "autotalk") {
AI::queue('talkAuto');
$args->{return} = 1;
}
}

sub mainLoop {
# Queue talkAuto after death
if (AI::action eq "dead" && !$::char->{dead}) {
if (!$::char->{resurrected}) {
# Force talk-auto after death
AI::queue('talkAuto') if ($::config{'talkAuto_afterDeath'});
}
}

AUTOTALK: {

if (AI::action eq "talkAuto" && AI::args->{done}) {
# Autotalk finished
AI::dequeue;

} elsif (AI::action eq "talkAuto") {
# Main autotalk block
my $args = AI::args;

# Stop if talkAuto is not enabled, or if the specified NPC is invalid
$args->{npc} = {};
main::getNPCInfo($::config{'talkAuto_npc'}, $args->{npc});
if (!defined($args->{npc}{ok})) {
$args->{done} = 1;
return;
}

# Determine whether we have to move to the NPC
my $do_route;
if ($::field{'name'} ne $args->{npc}{map}) {
$do_route = 1;
} else {
my $distance = Utils::distance($args->{npc}{pos}, $::char->{pos_to});
if ($distance > $::config{'talkAuto_distance'}) {
$do_route = 1;
}
}

if ($do_route) {
Log::message "Calculating auto-talk route to: $::maps_lut{$args->{npc}{map}.'.rsw'}($args->{npc}{map}): $args->{npc}{pos}{x}, $args->{npc}{pos}{y}\n", "route";
main::ai_route($args->{npc}{map}, $args->{npc}{pos}{x}, $args->{npc}{pos}{y},
attackOnRoute => 1,
noSitAuto => 1,
distFromGoal => $::config{'talkAuto_distance'});
} else {
# Talk to NPC if we haven't done so
if (!defined($args->{queuedTalkSequence})) {
$args->{queuedTalkSequence} = 1;

if (defined $args->{npc}{id}) {
main::ai_talkNPC(ID => $args->{npc}{id}, $::config{'talkAuto_npc_steps'});
} else {
main::ai_talkNPC($args->{npc}{pos}{x}, $args->{npc}{pos}{y}, $::config{'talkAuto_npc_steps'});
}

return;
}

$args->{done} = 1;
}
}

} #END OF BLOCK AUTOTALK
}

return 1;
Code Made From DreamX Forum (http://s10.invisionfree.com/ripley)

don
9th June 2005, 13:29
Code Made From DreamX Forum

wtf!? You just stole that from openkore forums.

tsk tsk...

ube2
9th June 2005, 14:54
:p, lolx

just wanna help this MPC forum^^




posts merged, next time i'll warn you big time for useless posting -- drey

don
9th June 2005, 20:43
:p, lolx

just wanna help this MPC forum^^


yes I kno you just wanted to help,
but also give credit to the real author of the code.

=D