Openkore.com
http://forums.openkore.com/

Macro Recorder [upgrade]
http://forums.openkore.com/viewtopic.php?f=34&t=658
Page 1 of 1

Author:  DeniZka [ 28 Apr 2008, 23:09 ]
Post subject:  Macro Recorder [upgrade]

Usage: rec [NAME|pause|cont|stop|play|play..|..|save|p<n>|+p|-p]

NAME -start recording <NAME>ed macro
pause -pause recording
cont -continue recording
stop -stop recording
play -play last recorded macro
play.. -play loop last recorded macro
.. -break play loop
save -save macro
p<n> -manual add pause (n second) to macro list
+p|-p -enable|disable adding pauses in macro list (default: disable)
you can switch +p|-p even you recording macro


Code:
# macro recorder by DeniZka
# Last update 03/01/2008
# based on macro recorder by Arachno
# This source code is licensed under the
# GNU General Public License, Version 2.
# See http://www.gnu.org/licenses/gpl.html

package recorder;
use strict;
use Plugins;
use Settings;
use Globals;
use Log qw(message error);

Plugins::register('recorder', 'records a macro', \&Unload);

my $chooks = Commands::register(
   ['rec', "Macro recorder", \&commandHandler]
);

my $hooks = Plugins::addHooks(
   ['Commands::run/post', \&cmdRun, undef],
   ['Command_post', \&cmdRun, undef]
);

my $talkseq;
my $premacros;
my %macros;
my %current = (
   'name' => undef,
   'recording' => 0,
   'time' => 0,
   'macro' => [],
   'addpauses' => 0
);

sub Unload {
   message "macro recorder unloading, cleaning up.\n", "macro";
   Plugins::delHooks($hooks);
   Commands::unregister($chooks)
}

sub commandHandler {
   my (undef, $arg) = @_;
   if (!defined $arg) {
      message "Macro recorder\n", "list";
      message "Usage: rec [NAME|pause|cont|stop|play|play..|..|save|p<n>|+p|-p]\n";
      message "NAME   -start recording <NAME>ed macro\n";
      message "pause  -pause recording\n";
      message "cont   -continue recording\n";
      message "stop   -stop recording\n";
      message "play   -play last recorded macro\n";
      message "play.. -play loop last recorded macro\n";
      message "..     -break play loop\n";
      message "save   -save macro\n";
      message "p<n>   -manual add pause (n second) to macro list\n";
      message "+p|-p  -enable|disable adding pauses in macro list (default: disable)\n";
      message "        you can switch +p|-p even you recording macro\n"
   } elsif ($arg eq 'stop') {
      if ($talkseq ne ""){push @{$current{macro}}, $talkseq}
      if ($current{recording}) {
         message "stopped recording ".$current{name}."\n", "list";
         $macros{$current{name}} = $current{macro};
         $current{recording} = 0;
         $current{macro} = []
      } else {
         error "nothing to do.\n"
      }
   } elsif ($arg eq 'save') {
      my @folders = Settings::getControlFolders();
      my $filename = $folders[0]."/macros-".time.".rec";
      open MACRO, "> $filename";
      foreach my $m (keys %macros) {
         print MACRO "macro $m {\n";
         foreach my $s (@{$macros{$m}}) {print MACRO "\t$s\n"}
         print MACRO "}\n"
      }
      close MACRO;
      message "macros written to $filename.\n"
   } elsif ($arg eq 'pause') {
      message "pause recording\n", "list";
      $current{recording} = 0
   } elsif ($arg eq 'cont') {
      message "continue recording\n", "list";
      $current{time} = time;
      $current{recording} = 1
   } elsif ($arg eq 'play' || $arg eq 'play..') {
      if (defined $current{name} && !$current{recording}) {
         $premacros = $config{"macro_file"};
         if (!defined $premacros) {$premacros = "macros.txt"}
         my @folders = Settings::getControlFolders();
         open (MACRO, ">:utf8", "$folders[0]/play_macros.txt");
         foreach my $m (keys %macros) {
            if ($arg eq "play..") {
                my $job_name_string = "$jobs_lut{$char->{'jobID'}}";
               print MACRO "automacro $m {\n";
               print MACRO "\tclass $job_name_string\n";
               print MACRO "\tcall $m\n";
               print MACRO "}\n"
            }
            print MACRO "macro $m {\n";
            if ($arg eq "play..") {print MACRO "\tlock $m\n"}
            foreach my $s (@{$macros{$m}}) {print MACRO "\t$s\n"}
            if ($arg eq "play..") {print MACRO "\trelease $m\n"}
            else {print MACRO "\tdo conf macro_file $premacros\n"}
            print MACRO "}\n";
         }
         close MACRO;   
         Commands::run("conf macro_file play_macros.txt");
         Commands::run("macro ".$current{name});
      } else {
         message "macro was not recorded\n", "list";
      }
   } elsif ($arg eq '..') {
      if (defined $premacros) {Commands::run("conf macro_file $premacros")}
   } elsif ($arg eq '+p') {
      message "pauses will add in macro record\n", "list";   
      $current{addpauses} = 1;
   } elsif ($arg eq '-p') {
      message "pauses will NOT add in macro record\n", "list";      
      $current{addpauses} = 0;
   } elsif ($arg =~ /^p(\d+)/) {
      my $pause = substr($arg, 1);
      if ($pause == 1) {push @{$current{macro}}, "pause"}
      if ($pause > 1)  {push @{$current{macro}}, "pause $pause"}
   } else {
      message "recording macro $arg\n", "list";
      $current{macro} = [];
      $current{name} = $arg;
      $current{recording} = 1;
      $current{time} = time
   }
}

sub cmdRun {
   return unless $current{recording};
   my ($trigger, $args) = @_;
   my $cmd = "do ";
   if ($trigger eq 'Commands::run/post') {
      if ($args->{switch} eq "talk"){
         #record talknpc sequence
         my @i = split(/\s/, $args->{args});
         if ($i[0] =~ /^\d+/) {
            if ($config{"autoTalkCont"} eq "1") {
               message "autoTalkCont DISABLED to create coorect talk sequence \n", "list";
               Commands::run("conf autoTalkCont 0");
            }
            #dialog end, add it to macro list
            if ($talkseq ne "") {push @{$current{macro}}, $talkseq;}
            my $npc = $npcsList->get($i[0]);
            $talkseq = "do talknpc ".$npc->{pos_to}{x}." ".$npc->{pos_to}{y};
         } elsif ($i[0] eq "cont") {
            $talkseq .= " c"
         } elsif ($i[0] eq "resp") {
            if ($i[1] =~ /^\d+/) {$talkseq .= " r$i[1]"}
         } elsif ($i[0] eq "num") {
            if ($i[1] =~ /^\d+/) {$talkseq .= " d$i[1]"}
         } elsif ($i[0] eq "text") {
            if ($i[1] =~ /^\w+/) {$talkseq .= " t=$i[1]"}
         } elsif ($i[0] eq "no") {
            $talkseq .= " n"
         }
         return
      }
      $cmd .= $args->{switch}." ".$args->{args}
   } else {
      #wrong input will comments
      $cmd = "#$args->{input}"
   }
   $cmd =~ s/\s*$//g;
   return if $cmd =~ /^do rec/ || $cmd =~ /^do macro/ || $cmd =~ /^do talk (.*)/;
   if ($current{addpauses}) {
      my $pause = time - $current{time};
      if ($pause == 1) {push @{$current{macro}}, "pause"}
      if ($pause > 1)  {push @{$current{macro}}, "pause $pause"}
   }
   if ($talkseq ne ""){
      #dialog end, add it to macro list
      push @{$current{macro}}, $talkseq;
      $talkseq = "";
   }
   push @{$current{macro}}, $cmd;
   $current{time} = time
}

1;



This macro was born with my recorder.
It's almost complete nooby quest for rRO. Strings started with # - are commands that i input
Code:
#rec Noob
macro Noob {
# lock Noob <- this added by my self
   do talknpc 53 114 c c r0 c c c c
   do talknpc 53 114 c c
   do move 148 112
   do move 99 20
   do talknpc 100 29 c r0 c c
   do move 101 95
   do talknpc 99 105 c c r0 c c c c c c c c
   do talknpc 99 105 c r0
#there NPC warps me to another NPC so i add a pause
#rec p2
   pause 2
   do talknpc 83 111 c r0 c c c c c c c c c c c r0
   do talknpc 83 111 c r0
#there NPC warps me to another NPC so i add a pause
#rec p2
   pause 2
   do talknpc 118 108 c c c r1 c r0 c c r1 c c c c c n
   do talknpc 115 111 c r0 c c c c c c c c c c r0 c
   do talknpc 115 111 c r0 c r0
#there NPC warps me to another NPC so i add a pause
#rec p2
   pause 2
   do talknpc 17 182 c c c r0 c c c c c c c c c n
   do talknpc 38 182 c c c c r0 c
#there i got all items, and i need to look items number that i can wear
#rec pause
#i
#rec cont
   do eq 1
   do eq 2
   do eq 3
   do eq 4
   do eq 5
   do eq 6
#rec stop
}
#rec save

Author:  kigusswong [ 08 Sep 2010, 15:53 ]
Post subject:  Re: Macro Recorder [upgrade]

may i know how to use this block of code?
Where should i place this code?
What name should i save as?
What is the command I need to add?

Thanks in advanced :-)

Author:  claudio_sbc [ 16 Jun 2017, 01:41 ]
Post subject:  Re: Macro Recorder [upgrade]

Hi...
Just I need save it as xxx.pl and pt on plugins folder?

How I need to put to stop recorder?

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/