stepSelector

Other plugins for extending OpenKore's functionality. This forum is only for posting new plugins and commenting on existing plugins. For support, use the Support forum.

Moderator: Moderators

Message
Author
H0lyShit
Noob
Noob
Posts: 1
Joined: 05 Nov 2009, 10:26
Noob?: No

stepSelector

#1 Post by H0lyShit »

I remember last time we have a plugin call stepSelector where we can choose bot's way point ourself so it will not walk like a robot. but i cant find this plugin anymore, anyone know any similar plugin? Or where can I download this plugin? I already search this forum.

User avatar
kLabMouse
Administrator
Administrator
Posts: 1301
Joined: 24 Apr 2008, 12:02

Re: stepSelector

#2 Post by kLabMouse »

If you dare to post in "Other Plugins". You must attach the actual plugin Source.
But there is none.
And, StepSelector last version was developed by some Russian members at Rofan, that is down to do some work and optimizations.

lolfox
Noob
Noob
Posts: 1
Joined: 10 Jul 2010, 17:47
Noob?: Yes

Re: stepSelector

#3 Post by lolfox »

found V2 on thier forums,

but i cant start:

it says Undefined subroutine & Settings:: add ConfigFile at line 82
dont kno how to fix it,

anyone can help?
Attachments
StepSelectorV2.zip
(4.16 KiB) Downloaded 397 times

Mr_M
Noob
Noob
Posts: 10
Joined: 31 Mar 2011, 22:35
Noob?: No

Re: stepSelector

#4 Post by Mr_M »

Hi, it is quite sometime i using this plugins till latest version openkore 2.1.
It fail to run due to changes on
AI::ai_route($point{map}, $point{x}, $point{y},
attackOnRoute => 1,
noSitAuto => 1,
notifyUponArrival => 1);

Error say something about actor "isa".
anyone can give some idea on how to solve this problem.
This is nice plugins, n i using more then 8 years without any problem.
It support up to version 2.07.

Code: Select all

# ICQ 266048166 (c) Click
# StepSelector
#
# Step selector for automatic waypoint walking. 
#                             for OpenKore 1.9.4-1.9.5
# 27.06.2007
#
# Config.txt:
# StepSelector_active 0 #Tells to the plugin if the auto-walking must start automatically (1) or manually (0)
# StepSelector_mode repeat #Tells to the plugin what to do when the path is finished 
#                          #repeat: the path will be repeated from 0
#                          #stop: the auto-walking will be stopped
#                          #reverse: the auto-walking will be reversed
#
#
# How to use:
# Put the plugin in the plugin folder and boot OpenKore from wxstart.exe
# When logged on go to the dungeon or field or any map and type in the command line: 
# step start
# You'll see the message "Selector ready. Map clicks catching is on...". Now, click points on the map viewer you would like
# to have as waypoints (points you'll walk on during the path walking). When all points you'd like to walk on are selected,
# type in command line:
# step stop
# If you want to save manually the coords (they will be saved automatically at OpenKore shut down) you can type:
# step save
# To activate the step-walking type:
# step on
# To deactivate type instead:
# step off
# If you type only "step" then automatically steps will be activated/deactivated looping.
# You can type:
# step list [map_name]
# To have a list of steps for current map or a list of steps for map_name map.
# You can also type:
# step show [map_name]
# To show steps on the map viewer, and
# step hide
# To hide them
# You can call also:
# step n
# where n is a number and the plugin will automatically stop the steps selection when reached n points clicked on the map.
# You can call:
# step restart
# To restart the steps walking through the path selected.
# Lastly you can call:
# step dump
# To create a plugin variables dump, for debugging purposes.
# Steps are memorized for each map you select to. You can share the steps points sharing the file map_steps.txt in your control folder.
# You DON'T need to create the config file manually, simply put the login file in /logins the login itself will take care of creating the config file.
#
# Enjoy!

package StepSelector;

use strict;
use Plugins;
use Log qw(message error);
use Globals;
use Settings;
use Commands;
use Misc qw(calcRectArea);
use AI qw(ai_route);
use Data::Dumper;

# Register the plugin
Plugins::register("StepSelector", "Select steps for map routing", \&on_unload, \&on_reload);
# Register plugin hooks
my $startHook = Plugins::addHook("start3", \&on_Start, undef);
my $wpHook = Plugins::addHook("waypoint/arrived", \&on_WP, undef);
my $aiHook = Plugins::addHook("AI_pre", \&on_AI, undef);
my $mapHook = Plugins::addHook("packet_mapChange", \&on_MapChange, undef);
# Register command 'step' hook
my $cmdHook = Commands::register( ['step' , 'select map steps' , \&step_map] );

# Configurations
my $cfgFile = $Settings::controlFolders . "map_steps.txt";
#my $cfgFile = $Settings::controlFolders . "/map_steps.txt";
#my $cfgFile1 = Settings::getControlFilename("map_steps.txt");
if (!-f $cfgFile) {
    open(CFGFILE,">>" . $cfgFile);
    close(CFGFILE);
}

my %stepCfg;
my $cfgID = Settings::addControlFile($cfgFile, loader => [\&parseStepsConfig, \%stepCfg]);

my $mapView;
my $interfaceOk = defined $interface;
my $callName;
my $callData;
my $active;
my $stepping = 0;
my $maxSelect;
my $resetMap;
my $currentMap;
my $stepsShowed;
my $currentPos;
my $doWalk = 1;
my $reverseWalk;

# Check if current interface supports a map viewer
if ($interfaceOk) {
    $mapView = $interface->{mapViewer};
}
else {
    message 'StepSelector can\'t run in this mode, $interface object isn\'t defined.' . "\n",'StepSelector';
}

sub on_unload {
    message "Saving Steps...\n",'StepSelector';
    saveConfigFile($cfgFile);
    Plugins::delHook($startHook);
    Plugins::delHook($wpHook);
    Plugins::delHook($aiHook);
    Plugins::delHook($mapHook);
    Commands::unregister($cmdHook);
#    Settings::delConfigFile($cfgID);
    undef $callName;
    undef $callData;
    undef $resetMap;
}

sub on_reload {
    on_unload();
}

sub on_Start {
    $active = exists $config{'StepSelector_active'} ? $config{'StepSelector_active'} : 0;
}

# Commands handler
sub step_map {
    if ($interfaceOk) {
        my (undef,$do) = @_;
        my $map;
        
        if ($do =~ /(.*?)\s(.*?)/) {
            ($do,$map) = $do =~ /(.*?)\s+(.*?)/;
        }
        
        # If no arguments are given then select the default action (activate|deactivate)
        if (!defined $do || $do eq '') {
            if ($active == 0) {
                $do = 'on';
            }
            else {
                $do = 'off';
            }
        }
        
        if ($do eq 'on') {
            # Activate the StepSelector
            $active = 1;
            message "Step walking activated.\n",'StepSelector';
            on_WP();
        }
        elsif ($do eq 'off') {
            # Deactivate the StepSelector
            $active = 0;
            message "Step walking deactivated.\n",'StepSelector';
        }
        elsif ($do eq 'restart') {
            $currentPos = 0;
            $doWalk = 1;
            message "Restarting Steps path...\n",'StepSelector';
        }
        elsif ($do eq 'start') {
            # Start selecting steps on map
            start_step();
        }
        elsif ($do eq 'stop') {
            # Stop selecting steps on map
            stop_step();
        }
        elsif ($do eq 'list') {
            message createStepsString($map) . "\n",'StepSelector';
        }
        elsif ($do eq 'show') {
            showSteps($map);
        }
        elsif ($do eq 'hide') {
            hideSteps($map);
        }
        elsif ($do eq 'save') {
            saveConfigFile();
        }
        elsif ($do =~ /\d+/) {
            # Start selecting steps on map
            start_step($do);
        }
        elsif ($do eq 'dump') {
            dumpVars();
        }
        else {
            if ($do ne 'help') {
                message "Wrong call. Correct syntax is:\n",'StepSelector';
            }
            
            message "step [on|off|restart|start|stop|<number>|list|show|hide] [map_name]\n",'StepSelector';
        }
    }
    else {
        message 'StepSelector can\'t run in this mode, $interface object isn\'t defined.' . "\n",'StepSelector';
    }
}

# Handles clicks on map.
sub mapClicked {
    my (undef,$x,$y) = @_;
    
    if (calcRectArea($x, $y, int(rand 2) + 2)) {
        if (defined $maxSelect) {
            if ($maxSelect <= 0) {
                $maxSelect = 0;
                return stop_step();
            }
            
            $maxSelect--;
        }
        
        step_add($x,$y,$field{name});
    }
}

sub on_AI {
    if ($field{name} ne $currentMap || $currentMap eq '' && @ai_seq == 0) {
        on_WP();
    }
    if (@ai_seq == 0) {on_WP();}    
}

# Move through steps.
sub on_WP {
    if ($field{name} ne $currentMap || $currentMap eq '') {
        $currentMap = $field{name};
        $currentPos = 0;
    }
    
    if ($field{name} eq $currentMap && $currentMap ne '' && exists $stepCfg{$currentMap} && $active == 1 && $doWalk == 1) {
        queueStep();
    }
}

sub on_MapChange {
    on_WP();
}

# Start catching clicks on map.
sub start_step {
    $maxSelect = shift;
    
    if ($maxSelect == 0) {
        undef $maxSelect;
    }
    
    if ($stepping == 0) {
        $stepping = 1;
        $callName = $mapView->{clickCb};
        $callData = $mapView->{clickData};
        $mapView->onClick(\&mapClicked);
        if (exists $stepCfg{$field{name}}) {
            $resetMap = $field{name};
        }
        
        if (defined $maxSelect || $maxSelect > 0) {
            message "Selector ready. Map clicks catching for $maxSelect steps is on...\n",'StepSelector';
        }
        else {
            message "Selector ready. Map clicks catching is on...\n",'StepSelector';
        }
    }
    else {
        message "Selector already started.\n",'StepSelector';
    }
}

# Stop catching clicks on map.
sub stop_step {
    if ($stepping == 1) {
        $stepping = 0;
        $mapView->onClick($callName,$callData);
        $callName = undef;
        $callData = undef;
        message "Selector stopped. Map clicks catching is off...\n",'StepSelector';

    my $map = $currentMap;
    if ($interfaceOk && defined $mapView && exists $stepCfg{$map}) {
        my @steps = @{$stepCfg{$map}};
        
        foreach my $step (@steps) {
            my ($x,$y) = @{$step};           
            my $i = 0;
            foreach my $mstep (@{$mapView->{portals}->{$map}}) {
                if ($mstep->{x} eq $x && $mstep->{y} eq $y) {
                    undef @{$mapView->{portals}->{$map}}[$i];
                }
                $i++;
            }
        }
        
        if (@steps > 0) {
            $mapView->{needUpdate} = 1;
            $mapView->update();
        }
    }
    }
    else {
        message "Selector not started yet.\n",'StepSelector';
    }
}

# Add a step to the current map.
sub step_add {
    my ($x,$y,$map,$hideMsg) = @_;

    if ($resetMap eq $map && exists $stepCfg{$map} && $map ne '') {
        if (!$hideMsg) {
            message "Deleting old steps for $map...\n",'StepSelector';
        }
        undef $resetMap;
        undef $stepCfg{$map};
    }
    
    push(@{$stepCfg{$map}}, [($x,$y)]);
    
    if (!$hideMsg) {
        message "Step added: $map, $x $y\n",'StepSelector';

    if ($interfaceOk && defined $mapView && exists $stepCfg{$map}) {
        my @steps = @{$stepCfg{$map}};
        
        foreach my $step (@steps) {
            my ($x,$y) = @{$step};
            push(@{$mapView->{portals}->{$map}},{x=>$x,y=>$y});
        }
        
        if (@steps > 0) {
            $mapView->{needUpdate} = 1;
            $mapView->update();
            $stepsShowed = 1;
        }
     }
    }
}

# Show steps on the map viewer.
sub showSteps {
    my $map = shift;

    if (!defined $map || $map eq '') {
        $map = $currentMap;
    }
    
    if ($interfaceOk && defined $mapView && exists $stepCfg{$map}) {
        my @steps = @{$stepCfg{$map}};
        
        foreach my $step (@steps) {
            my ($x,$y) = @{$step};
            
            push(@{$mapView->{portals}->{$map}},{x=>$x,y=>$y});
        }
        
        if (@steps > 0) {
            message 'Showing steps on map ' . $map . "...\n",'StepSelector';
            $mapView->{needUpdate} = 1;
            $mapView->update();
            $stepsShowed = 1;
        }
        else {
            message 'No steps to show exist for map ' . $map . ".\n",'StepSelector';
        }
    }
    elsif (!$interfaceOk) {
        message "Current interface is not supported.\n",'StepSelector';
    }
    else {
        message "Map doesn't exist.\n",'StepSelector';
    }
}

# Hide steps on the map viewer.
sub hideSteps {
    my $map = shift;

    if (!defined $map || $map eq '') {
        $map = $currentMap;
    }
    
    if (!$stepsShowed) {
        message 'Steps are not showed on map ' . $map . " yet.\n",'StepSelector';        
    }
    
    if ($interfaceOk && defined $mapView && exists $stepCfg{$map}) {
        my @steps = @{$stepCfg{$map}};
        
        foreach my $step (@steps) {
            my ($x,$y) = @{$step};
            
            my $i = 0;
            foreach my $mstep (@{$mapView->{portals}->{$map}}) {
                if ($mstep->{x} eq $x && $mstep->{y} eq $y) {
                    undef @{$mapView->{portals}->{$map}}[$i];
                }
                $i++;
            }
        }
        
        if (@steps > 0) {
            message 'Hiding steps on map ' . $map . "...\n",'StepSelector';
            $mapView->{needUpdate} = 1;
            $mapView->update();
        }
        else {
            message 'No steps to hide exist for map ' . $map . ".\n",'StepSelector';
        }
    }
    elsif (!$interfaceOk) {
        message "Current interface is not supported.\n",'StepSelector';
    }
    else {
        message "Map doesn't exist.\n",'StepSelector';
    }
}

# Queue waypoints.
sub queueStep {
    if ($currentPos >= @{$stepCfg{$currentMap}} && $currentPos > 0 && $config{StepSelector_mode} eq 'stop') {
        $doWalk = 0;
        message "Last Step reached, stopping walk...\n",'waypoint';
        return;
    }
    elsif ($currentPos >= @{$stepCfg{$currentMap}} && $currentPos > 0 && $config{StepSelector_mode} eq 'repeat') {
        $currentPos = 0;
        message "Last Step reached, repeating walk...\n",'waypoint';
    }

    my %point = (
            map => undef,
            x => undef,
            y => undef
    );
    
    if ($currentPos < @{$stepCfg{$currentMap}} && $reverseWalk == 0) {
        my $step = @{$stepCfg{$currentMap}}[$currentPos];
        my ($x,$y) = @{$step};
        
        $point{map} = $currentMap;
        $point{x} = $x;
        $point{y} = $y;
        
        $currentPos++;
    }
    elsif ($currentPos > 0) {
        if ($reverseWalk == 0) {
            message "Last Step reached, reversing walk...\n",'waypoint';
            $reverseWalk = 1;
        }
        $currentPos--;
        
        my $step = @{$stepCfg{$currentMap}}[$currentPos];
        my ($x,$y) = @{$step};
        
        $point{map} = $currentMap;
        $point{x} = $x;
        $point{y} = $y;
        
        if ($currentPos == 0) {
            $reverseWalk = 0;
        }
    }
    
    if ($point{map} ne '' && $point{x} ne '' && $point{y} ne '') {
        my @points;
        push(@points, \%point);
        
				AI::ai_route($point{map}, $point{x}, $point{y},
				attackOnRoute => 2,
				noSitAuto => 0,
				notifyUponArrival => 1);
    }
}

##### PARSING CONFIG #####

sub parseStepsConfig {
    my $file = $Settings::controlFolders . "map_steps.txt";
    my $r_hash = shift;
    my $no_undef = shift;

    undef %{$r_hash} unless $no_undef;
    my ($key, $value, $inBlock, $commentBlock);

    open FILE, "< $file";
    foreach (<FILE>) {
        next if (/^[\s\t]*#/);
        s/[\r\n]//g;	# Remove line endings
        s/^[\t\s]*//;	# Remove leading tabs and whitespace
        s/\s+$//g;	        # Remove trailing whitespace
        next if ($_ eq "");
        
        if (!defined $commentBlock && /^\/\*/) {
            $commentBlock = 1;
            next;
        }
        elsif (m/\*\/$/) {
            undef $commentBlock;
            next;
        }
        elsif (defined $commentBlock) {
            next;
        }
        elsif (!defined $inBlock && /{$/) {
            # Begin of block
            s/ *{$//;
            ($key, $value) = $_ =~ /^(.*?) (.*)/;
            $key = $_ if ($key eq '');
            
            if ($key eq 'steps') {
                $inBlock = $value;
            }
        }
        elsif (defined $inBlock && $_ eq "}") {
            # End of block
            undef $inBlock;
        }
        elsif (/^\s*(\d+) (\d+)\s*$/) {
            # Create list if doesn't exist
            if (!exists $stepCfg{$inBlock}) {
                $stepCfg{$inBlock} = [()];
            }
            # Coordinates
            my ($x,$y) = $_ =~ /^\s*(\d+) (\d+)\s*$/;
            step_add($x,$y,$inBlock,1);
        }
    }

    close FILE;

    if ($inBlock) {
            error "$file: Unclosed { at EOF\n",'StepSelector';
            return 0;
    }
    
    return 1;
}

sub createStepsString {
    my $map = shift;

    if (!defined $map || $map eq '') {
        $map = $currentMap;
    }
    
    my $str;
    
    if ($map ne '' && exists $stepCfg{$map}) {
        $str = 'StepSelector Path: [' . $map . '] ';
        my $i = 0;
        foreach my $step (@{$stepCfg{$map}}) {
            my ($x,$y) = @{$step};
            $str .= $i . ':(' . $x . ';' . $y . ') ';
            $i++;
        }
    }
    else {
        $str = 'Wrong map selected: ' . $map;
    }
    
    return $str;
}

###### SAVING CONFIG #####

sub saveConfigFile {
    my $file = $Settings::controlFolders . "map_steps.txt";
    
    # Set File Name
    if ($file eq '') {
        $file = $Settings::controlFolders . "map_steps.txt";
    }
    
    # Open the file
    open(CFGFILE,">$file") or return 0;

    # Look through saved steps
    foreach my $map (keys %stepCfg) {
        print CFGFILE 'steps ', $map, " {\n";
        
        my @steps = @{$stepCfg{$map}};
        foreach my $xy (@steps) {
            my ($x,$y) = @{$xy};
            print CFGFILE '  ', $x, ' ', $y, "\n";
        }
        undef @steps;
        
        print CFGFILE "}\n\n";
    }
    
    close CFGFILE;
    
    message "Steps saved.\n",'StepSelector';
}

###### DUMP #####

sub dumpVars {
    open(DUMPFILE,">$Settings::logs_folder/steps_dump.txt");
    
    print DUMPFILE "Step Config:\n";
    print DUMPFILE Dumper(\%stepCfg);
    
    print DUMPFILE "\n\n";
    print DUMPFILE "Current map: $currentMap \n";
    
    print DUMPFILE "\n\n";
    print DUMPFILE "Current pos: $currentPos \n";
    
    close(DUMPFILE);
    
    message "Dump saved.\n",'StepSelector';
}

1;

EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: stepSelector

#5 Post by EternalHarvest »

Mr_M wrote:Error say something about actor "isa".
Post errors.txt.

Post Reply