Advanced runFromTarget (from old forums) recover

Moderator: Moderators

Message
Author
Darki
Been there done that!
Been there done that!
Posts: 143
Joined: 25 Oct 2008, 08:14
Noob?: No
Location: Spain, Madrid
Contact:

Advanced runFromTarget (from old forums) recover

#1 Post by Darki »

I've been using this macro and it works quite well, so I though about writting it here so people can find it well. <.< Basically it gets the distance from monsters, then makes the character run from it if the monster distance is less or equal to the distance given.

Well, first you need to mod a little your macro plugin:
  • Go to Macro plugin file, and open the file Automacro.pm. you gotta search for this script:

    Code: Select all

    # checks for monster, credits to illusionist
    sub checkMonster {
    	my $monsterList = $_[0];
    	foreach (@monstersID) {
    		next unless defined $_;
    		if (existsInList($monsterList, $monsters{$_}->{name})) {
    			my $pos = calcPosition($monsters{$_});
    			my $val = sprintf("%d %d %s", $pos->{x}, $pos->{y}, $field->name);
    			$varStack{".lastMonster"} = $monsters{$_}->{name};
    			$varStack{".lastMonsterPos"} = $val;
    			return 1
    		}
    	}
    	return 0
    }
    Then change it to this:

    Code: Select all

    sub checkMonster {
           my ($monsterList, $mondist) = $_[0] =~ /^(.*),\s(\d+)\s*$/;
           return 0 if ($mondist < 1);
    	foreach (@monstersID) {
    		next unless defined $_;
    		if (existsInList($monsterList, $monsters{$_}->{name})) {
    			my $mypos = calcPosition($char);
    			my $pos = calcPosition($monsters{$_});
    			my $dist = sprintf("%.0f", distance($mypos, $pos));
    			my $val = sprintf("%d %d %s", $pos->{x}, $pos->{y}, $field->name);
    			$varStack{".lastMonster"} = $monsters{$_}->{name};
    			$varStack{".lastMonsterPos"} = $val;
    			$varStack{".lastMonsterDist"} = $dist;
    			$varStack{".lastMonsterID"} = $monsters{$_}->{binID};
    			return $dist <= $mondist ?1:0
    		}
    	}
    	return 0
    }
  • Now open the file Utilities.pm in the same folder and find this code (is at the top):

    Code: Select all

    our @EXPORT_OK = qw(ai_isIdle q4rx between cmpr match getArgs refreshGlobal getnpcID getPlayerID
    	getVenderID getItemIDs getItemPrice getInventoryIDs getStorageIDs getSoldOut getInventoryAmount
    	getCartAmount getShopAmount getStorageAmount getVendAmount getRandom getRandomRange getConfig
    	getWord callMacro getArgFromList getListLenght);
    You gotta to add the word getmonsterID, like in here:

    Code: Select all

    our @EXPORT_OK = qw(ai_isIdle q4rx between cmpr match getArgs refreshGlobal getnpcID getmonsterID getPlayerID
    
    In the same file, you gotta find this code too:

    Code: Select all

    # get player array index
    sub getPlayerID {
    	foreach my $pl (@{$playersList->getItems()}) {
    		return $pl->{binID} if $pl->name eq $_[0]
    	}
    	return -1
    }
    And ADD after it (look: add, not overwrite) the following one:

    Code: Select all

    sub getmonsterID {
    	my ($name, $pool) = @_;
    	for (my $id = 0; $id < @{$pool}; $id++) {
    		next unless $$pool[$id];
    		next unless $monsters{$$pool[$id]}->{name};
    		if ($monsters{$$pool[$id]}->{name} eq $name) {return $id}
    	}
    	return -1
    }
  • Next step is open the file Parser.pm and look for the following part (it's at the top too):

    Code: Select all

    use Macro::Utilities qw(refreshGlobal getnpcID getItemIDs getItemPrice getStorageIDs getInventoryIDs
    	getPlayerID getVenderID getRandom getRandomRange getInventoryAmount getCartAmount getShopAmount
    	getStorageAmount getVendAmount getConfig getWord q4rx getArgFromList getListLenght);
    You gotta add again the word getmonsterID like here:

    Code: Select all

    use Macro::Utilities qw(refreshGlobal getnpcID getmonsterID getItemIDs getStorageIDs getInventoryIDs
    
    On the same file, look for this code:

    Code: Select all

    	while (($kw, $targ) = parseKw($cmd)) {
    		$ret = "_%_";
    		# first parse _then_ substitute. slower but more safe
    		$arg = subvars($targ);
    
    		if ($kw eq 'npc')           {$ret = getnpcID($arg)}
    Here you gotta add the following line after the part it's showed:

    Code: Select all

    elsif ($kw eq 'monster') {$ret = getmonsterID($arg, $::monstersID)}
    So it should look like this:

    Code: Select all

    	while (($kw, $targ) = parseKw($cmd)) {
    		$ret = "_%_";
    		# first parse _then_ substitute. slower but more safe
    		$arg = subvars($targ);
    
    		if ($kw eq 'npc')           {$ret = getnpcID($arg)}
    		elsif ($kw eq 'monster') {$ret = getmonsterID($arg, $::monstersID)}
  • And FINALLY go to Data.pm and look for this part:

    Code: Select all

    our $macroKeywords =
    	"npc"          . "|" .
    	"cart"         . "|" .
    	"inventory"    . "|" .
    	"store"        . "|" .
    	"storage"      . "|" .
    	"player"       . "|" .
    And just add

    Code: Select all

    "monster"       . "|" .
    
    So it will look like this:

    Code: Select all

    our $macroKeywords =
    	"npc"          . "|" .
    	"cart"         . "|" .
    	"inventory"    . "|" .
    	"store"        . "|" .
    	"storage"      . "|" .
    	"player"       . "|" .
    	"monster"      . "|" .
    
Okay, now you have modified your macro plugin. To make your character run after certain mosters & distances, you gotta use this automacro:

Code: Select all

automacro avoid {
    map moc_fild12
    monster Picky,Super Picky,PecoPeco's Egg,Drops, 12
    #Notice the coma space and number 12 above? This avoid automacro only trigger if any of the monster list
    #distance is equal or less than the number given.
    timeout 5
    exclusive 1
    set Move 10
    #set Move to how many distance per trigger you want it to move.
    call check
}
macro check {
[
    $mon = $.lastMonster
    $monID = $.lastMonsterID
    $dist = $.lastMonsterDist
    $monPos = $.lastMonsterPos
    $map = $.map
    $myPos = $.pos
    $myPosX = @arg ("$myPos", 1)
    $myPosY = @arg ("$myPos", 2)
    $monPosX = @arg ("$monPos", 1)
    $monPosY = @arg ("$monPos", 2)
    $map = $.map
    do eval message T("Macro Avoid: $::Macro::Data::varStack{mon} \($::Macro::Data::varStack{monID}\)\n"), "teleport"; message T("Monster Dist\= $::Macro::Data::varStack{dist} \, Monster Loc\: \($::Macro::Data::varStack{monPosX},$::Macro::Data::varStack{monPosY}\) Map\= $::Macro::Data::varStack{map}\n"), "teleport";
]
     do as

     if ($myPosX > $monPosX) goto east
     if ($myPosX < $monPosX) goto west
  :X0
     if ($myPosY < $monPosY) goto X0south
     if ($myPosY > $monPosY) goto X0north
     log We have the same co-ord to the Monster
     do @random ("east", "west", "south", "north") $Move
     log Move Random
     stop
  :X0south
     log Monster Loc: North X-axis0
     do south $Move
     log Move South
     stop
  :X0north
     log Monster Loc: South X-axis0
     do north $Move
     log Move North
     stop

:east
        if ($myPosY < $monPosY) goto eastSouth
        if ($myPosY > $monPosY) goto eastNorth
      :Y0east
        log Monster Loc: West Y-axis0
        do east $Move
        log Move East
        stop  
     :eastSouth
        log Monster Loc: NorthWest
        do southeast $Move
        log Move South East
        stop
     :eastNorth
        log Monster Loc: SouthWest
        do northeast $Move
        log Move North East
        stop

:west
        if ($myPosY < $monPosY) goto westSouth
        if ($myPosY > $monPosY) goto westNorth
      :Y0west
        log Monster Loc: East Y-axis0
        do west $Move
        log Move West
        stop  
     :westSouth
        log Monster Loc: NorthEast
        do southwest $Move
        log Move South West
        stop
     :westNorth
        log Monster Loc: SouthEast
        do northwest $Move
        log Move North West
        stop
}
Note that this is old stuff, so if someone made it more actual it would be cool to know what was done on it. It works perfect for me with the last SVN downloaded OK and macro plugin.

I got this from old forums, here -> http://bibian.ath.cx/openkore/viewtopic ... et&start=0
I hope this helps, though I did nothing, all the credits to the people who worked on that post. Image
ImageImageImage
ImageImageImage
ImageImageImage

ezza
Developers
Developers
Posts: 109
Joined: 04 Apr 2008, 09:50

Re: Advanced runFromTarget (from old forums) recover

#2 Post by ezza »

If you said "original" ... I would rather read this 3 links 1st...

1. http://bibian.ath.cx/openkore/viewtopic ... sc&start=0
2. http://bibian.ath.cx/openkore/viewtopic ... 110#177110
3. http://forums.openkore.com/viewtopic.php?f=37&t=186 - the last attemp...



p.s: Any idea for the 3rd link?

Darki
Been there done that!
Been there done that!
Posts: 143
Joined: 25 Oct 2008, 08:14
Noob?: No
Location: Spain, Madrid
Contact:

Re: Advanced runFromTarget (from old forums) recover

#3 Post by Darki »

I just read the one in the link I posted and I found it really useful, I was looking in the old forums because I was interested in what was said here -> http://forums.openkore.com/viewtopic.php?f=29&t=5064, so I didn't read those ones because I wasn't looking for it. I can fix a little the first post to add all the functions.

So, from what I read in the third link, it seems there's a problem with the distance triggering? I can try to test it, if you want. What should I do, put this

Code: Select all

if ($monster->name eq $monsters{$_}->{name}) {
      if ($monster->{binID} eq $monsters{$_}->{binID}) {
            $counter++;
            next;
      } else {
            my $monsToMonDist = sprintf("%.1f",distance($pos, $monster->{pos_to}));
            $counter++ if $monsToMonDist < 12;
            next;
      }
} 
on the sub checkMonster? What should I do next?

Because if there's a problem with the distance between two monsters I'm looking forward to help fixing that, I was planning to use that macro function to change the looting configs when some aggresive monsters are near the loot (like when you kill a Geographer near another one).
ImageImageImage
ImageImageImage
ImageImageImage

franibaflo
Human
Human
Posts: 35
Joined: 06 May 2012, 10:11
Noob?: Yes

Re: Advanced runFromTarget (from old forums) recover

#4 Post by franibaflo »

Are these changes already in effect on the latest SVN version of the macro plugin? Because I've tried to open the files mentioned and it seems a lot of changes has been made and I'm terrified to change the files and end up being screwed.

If there are still not implemented in SVN, would anyone be kind enough to post the edited files which are on par with the latest SVN version of the macro plugin?

Post Reply