Warp Portal ultimate macro! REVISED

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:

Warp Portal ultimate macro! REVISED

#1 Post by Darki »

EDITED: I've tweaed the macro adding the latest features, like subroutines, and I've reduced the code a lot. This set of macros is meant to allow you to command your slave Priest to cast the skill Warp Portal, no matter where you are or what warps does it have.

First the chunk of subroutine:

Code: Select all

sub warpPosition {
	my ($_px, $_py) = @_;
	my $_l = $::char->{look}{body};
	if (!defined $_l || $_l > 7) {$_l = int(rand(8))};
	my @_areas = ( 
		[[0,4], [0,3],[-1,3],[1,3],[-1,4],[1,4],[-1,5],[1,5],[0,5],[0,2],[-1,2],[1,2],[-2,2],[2,2],[-2,3],[2,3],[-2,4],[2,4],[-2,5],[2,5],[-2,6],[2,6],[-1,6],[1,6],[0,6]] ,
		[[-3,3], [-3,2],[-2,3],[-4,3],[-3,4],[-2,2],[-3,1],[-1,3],[-4,2],[-2,4],[-5,3],[-3,5],[-4,4],[-2,1],[-1,2],[-3,0],[0,3],[-4,1],[-1,4],[-5,2],[-2,5],[-6,3],[-3,6],[-5,4],[-4,5]] ,
		[[-4,0], [-3,0],[-3,-1],[-3,1],[-4,-1],[-4,1],[-5,-1],[-5,1],[-5,0],[-2,0],[-2,-1],[-2,1],[-2,-2],[-2,2],[-3,-2],[-3,2],[-4,-2],[-4,2],[-5,-2],[-5,2],[-6,-2],[-6,2],[-6,-1],[-6,1],[-6,0]] ,
		[[-3,-3], [-2,-3],[-3,-2],[-3,-4],[-4,-3],[-2,-2],[-1,-3],[-3,-1],[-2,-4],[-4,-2],[-3,-5],[-5,-3],[-4,-4],[-1,-2],[-2,-1],[0,-3],[-3,0],[-1,-4],[-4,-1],[-2,-5],[-5,-2],[-3,-6],[-6,-3],[-4,-5],[-5,-4]] ,
		[[0,-4], [0,-3],[1,-3],[-1,-3],[1,-4],[-1,-4],[1,-5],[-1,-5],[0,-5],[0,-2],[1,-2],[-1,-2],[2,-2],[-2,-2],[2,-3],[-2,-3],[2,-4],[-2,-4],[2,-5],[-2,-5],[2,-6],[-2,-6],[1,-6],[-1,-6],[0,-6]] ,
		[[3,-3], [3,-2],[2,-3],[4,-3],[3,-4],[2,-2],[3,-1],[1,-3],[4,-2],[2,-4],[5,-3],[3,-5],[4,-4],[2,-1],[1,-2],[3,0],[0,-3],[4,-1],[1,-4],[5,-2],[2,-5],[6,-3],[3,-6],[5,-4],[4,-5]] ,
		[[4,0], [3,0],[3,1],[3,-1],[4,1],[4,-1],[5,1],[5,-1],[5,0],[2,0],[2,1],[2,-1],[2,2],[2,-2],[3,2],[3,-2],[4,2],[4,-2],[5,2],[5,-2],[6,2],[6,-2],[6,1],[6,-1],[6,0]] ,
		[[3,3],[2,3],[3,2],[3,4],[4,3],[2,2],[1,3],[3,1],[2,4],[4,2],[3,5],[5,3],[4,4],[1,2],[2,1],[0,3],[3,0],[1,4],[4,1],[2,5],[5,2],[3,6],[6,3],[4,5],[5,4]]
	);
	my @_area = @{@_areas[$_l]};
	my $_skip;	
	foreach my $_z (@_area) {
		my ($_x, $_y) = ($_px + $_z->[0], $_py + $_z->[1]);
		next if (!$::field->isWalkable($_x, $_y));
		next if (!Misc::checkLineWalkable({x => $_px, y => $_py},{x => $_x, y => $_y}, 0));
		$_skip = 0;
		foreach my $_npc (@{$::npcsList->getItems()}) {
			next if ($_npc->{pos_to}{x} != $_x || $_npc->{pos_to}{y} != $_y);
			$_skip = 1;
			last;
		}
		next if ($_skip == 1);
		foreach my $_pl (@{$::playersList->getItems()}) {
			next if ($_pl->{pos_to}{x} != $_x || $_pl->{pos_to}{y} != $_y);
			$_skip = 1;
			last;
		}
		next if ($_skip == 1);
		foreach my $_mon (@{$::monstersList->getItems()}) {
			next if ($_mon->{pos_to}{x} != $_x || $_mon->{pos_to}{y} != $_y);
			$_skip = 1;
			last;
		}
		next if ($_skip == 1);
		return $_x." ".$_y;
	}
	return "none";
}
If you wanna know what does this do, it just checks for all the possible spots around the bot to cast the skill, and looks for obstacles and objects so it can put the warp portal in a good spot. Currently, it tries to cast the skill in the direction the bot is looking for, but in the future I'll try to make it start checking in the same direction the master is, that way it will look more natural.

Next, the macros:

Code: Select all

automacro warpPortal {
	console /^\(From: ####name of your master####\) : open warp$/i
	overrideAI 1
	exclusive 0
	call {
 		if (@invamount (Blue Gemstone) > 0) goto blue
		do pm " ####name of your master####" I need a Blue Gemstone.
		stop
	:blue
		do ai manual
		$px = @arg("$.pos", 1)
		$py = @arg("$.pos", 2)
		$loc = warpPosition($px, $py)
		if ("$loc" == "none") goto noSkill
		do sl 27 $loc
		lock all; pause 2
		if (@eval (if (!$::char->{warp}{memo}[0]) {return 0}) == 0) goto fail
		release useWarp
		do pm " ####name of your master####" Those are my current saved maps:
			$i = 0
			while ($i <= 3) as warpLoop
			do pm " ####name of your master####" @eval ($i + 1) : @eval ($::char->{warp}{memo}[$i])
			$i++
		end warpLoop
		do pm " ####name of your master####" where to?
		pause 10
		do pm " ####name of your master####" I guess you changed your mind...
		do warp cancel
		goto ending
	:fail
		do pm " ####name of your master####" Sorry, I couldn't cast the skill.
	:ending
		set exclusive 1; release all; lock useWarp; do ai on
		stop
	:noSkill
		do pm " ####name of your master####" I don't have place for the skill.
		do ai on
	}
}

 automacro useWarp {
 	console /^\(From: ####name of your master####\) : (1st|2nd|3rd|4th|close) warp$/i
 	overrideAI 1
 	exclusive 1
	call {
		if ($.lastMatch1 == "close") goto cancel
		do eval my %_warp = ("1st", "0", "2nd", "1", "3rd", "2", "4th", "3");$::Macro::Data::varStack{dest} = $_warp{$::Macro::Data::varStack{".lastMatch1"}}
		do warp $dest
		do pm " ####name of your master####" Warp opened! Destination: @eval ($::maps_lut{$::char->{warp}{memo}[$dest].'.rsw'})!
		goto ending
	:cancel
		do pm " ####name of your master####" I guess you changed your mind...
		do warp cancel	
	:ending
		release all;lock useWarp; do ai on
	 }
}
these set of macros are what really do the work. The process is simple: to begin the action, you gotta tell the slave, by PM, "open warp". Your bot will stop all AI process and block other macros, so this doesn't get interrupted by anything else. Then it will check a good spot to cast the skill, and if found, it will use it. Then it will PM you the list of warps it has.

After this, you have 10 seconds to tell your bot the destination by PM'ing "1st warp", "2nd warp", "3rd warp" or "4th warp", depending on your option. If 10 secs pass, or you say "close warp", the macro will stop, warp will be closed. In case you choose a proper destination, the bot will open the warp. After any of those cases, the bot will be put back to normal, and if it was following you, it will do so even if you warp away.

This macro will tell you if the bot is out of gemstones, or doesn't have space or the warp couldn't be opened. There are some options I'd like to add but for now it has served me well. Enjoy!
Last edited by Darki on 21 Jun 2011, 00:05, edited 12 times in total.
ImageImageImage
ImageImageImage
ImageImageImage

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

Re: Warp Portal macro

#2 Post by Darki »

EDIT: Now, the macro finally got a little shorter thanks to Ezza's help, but, the BIG part is still there.

The code that checks for the correct spot once the default one is already used, uses a huge if statement with tooo many lines, and it'd be perfect to make it shorter, of course. The best way would be by an eval, but honestly I'm not really sure about how to do it... I'd like to ask for a little advice on that matter, because using the mod Ezza did as an example doesn't make me to understand it completely. ><

So, my thoughs go to the sub closestWalkableSpot code. I was thinking about taking the code directly (as I need to make it check for NPCs and characters too)and use it in the eval. Now, the idea would be this. I have the code:

Code: Select all

	foreach my $z ( [0,0], [0,1],[1,0],[0,-1],[-1,0], [-1,1],[1,1],[1,-1],[-1,-1],[0,2],[2,0],[0,-2],[-2,0] ) {
		next if !$field->isWalkable($pos->{x} + $z->[0], $pos->{y} + $z->[1]);
		$pos->{x} += $z->[0];
		$pos->{y} += $z->[1];
		return 1;
	}
	return 0;
}
Now, the question is how could i do the way I want.

Code: Select all

	if ($_l == 6 || $_l == 5) {foreach my $z ( [0,0], [0,1],[1,0],[0,-1],[-1,0], [-1,1],[1,1],[1,-1],[-1,-1],[0,2],[2,0],[0,-2],[-2,0] )} 
	elsif (($_l == 4 || $_l == 3) {foreach my $z ( [0,0], [0,1],[1,0],[0,-1],[-1,0], [-1,1],[1,1],[1,-1],[-1,-1],[0,2],[2,0],[0,-2],[-2,0] )} 
	elsif (($_l == 2 || $_l == 2) {foreach my $z ( [0,0], [0,1],[1,0],[0,-1],[-1,0], [-1,1],[1,1],[1,-1],[-1,-1],[0,2],[2,0],[0,-2],[-2,0] )}
	else {foreach my $z ( [0,0], [0,1],[1,0],[0,-1],[-1,0], [-1,1],[1,1],[1,-1],[-1,-1],[0,2],[2,0],[0,-2],[-2,0] )}

# here would check the look direction and depending on that would set the $z in an order to make it closer to the caster. Yes, I know in all cases the $z is the same, but as I'm trying to figure out how to do the other parts, that's a minor problem, I'll change them when the other things are clear

		next if !$field->isWalkable($pos->{x} + $z->[0], $pos->{y} + $z->[1]);
		foreach (@{$::playersList->getItems()}) { next if ($_->{pos_to}{x} != $pos->{x} + $z->[0] || $_->{pos_to}{y} != $pos->{y} + $z->[1]);

# here would check if the spot is walkable and full. It'd need also a check for npcs but I don't know how to do it in eval.

		$pos->{x} += $z->[0];
		$pos->{y} += $z->[1];
		return 1;
	}
	return 0;
}

# and the rest I guess what does is setting the correct squares.
As you can see the syntax is completely trashed and shitty because my perl knowledge is also a shit. But I hope you can get the idea of what I mean... >< in case this was possible, it could be added to the eval to get the "default" spot (what Ezza suggested) and make it as simple as like 10 times shorter.

So, can someone correct my eval raping? xD
ImageImageImage
ImageImageImage
ImageImageImage

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

Re: Warp Portal macro

#3 Post by ezza »

The foreach function is not right... but i'm not going to discuss that. This time I need an input.

1. Which direction is actually $look if it is in the value of 0 to 6.

2. The ([0,0], [0,1],[1,0],[0,-1],[-1,0], [-1,1],[1,1],[1,-1],[-1,-1],[0,2],[2,0],[0,-2],[-2,0]) is actually a square blocks from +-2 in radius to you. Meaning... there are 25 available spots to check but I dont know why its only 13 there (they ignore some spots). Actually I have other way to list all the avail coordinates from the bot standing.

Code: Select all

do eval my @lines;@_x = ($::char->{'pos'}{'x'} - 2) .. ($::char->{'pos'}{'x'} + 2); @_y = ($::char->{'pos'}{'y'} - 2) .. ($::char->{'pos'}{'y'} + 2);foreach my $_a (@_x) {foreach my $_b (@_y) {next if ($_a == $::char->{'pos'}{'x'} && $_b == $::char->{'pos'}{'y'});push @lines,$_a ." ". $_b}} my $_lines = join ", ", @lines; message "$_lines\n"
#print 24 avail spot
Now you can minimize all the unnessessary macro lines into 2 or 3 lines.

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

Re: Warp Portal macro

#4 Post by Darki »

What does that code you posted, to get the 24 spots? Is there a way to make it so depending on the position you're facing, it get's the spots in a defined order?

I know the code I wtote is wrong, I said I'm an azz doing that yet. xD
For the looking direction, from this code:

Code: Select all

$_l = $::char->{look}{body} - 1;
-1 is north, 0 is northwest, and so on, 6 is northeast.

I also noticed that the $z asignement was incomplete, but as I know how to do that I thought it was more important to know how to do the code correctly. I just copied the code from the subroutine. if we wanna take in care all squares in the 5x5 area we'd need this:

Code: Select all

foreach my $z ( [0,0], [0,1],[1,0],[0,-1],[-1,0], [-1,1],[1,1],[1,-1],[-1,-1], [0,2],[2,0],[0,-2],[-2,0], [-1,2],[-1,-2],[1,-2],[1,2], [-2,1],[-2,-1],[2,-1],[2,1], [-2,2],[-2,-2],[2,-2],[2,2] )
I took them more or less randomly... It's not in order, but well, that's easy to tweak. The idea is to change the order depending on the face direction, so it doesn't take a very far spot if there are other free spots closer.

So, anyways, my question is on the syntax, how could that work? I don't ignore your idea, but I really wanna know how to do that one because I feel I'm getting better at this... :oops:
ImageImageImage
ImageImageImage
ImageImageImage

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

Re: Warp Portal macro

#5 Post by ezza »

Well, after the input of the $look, now I understand it more clearer of what you are doing. I'm suggesting that we find the warp spot then later we force our char to look at the direction of the warp spot. Like this the range of cast spot will be 8 times more flexible instead of warp at certain direction.

Code: Select all

macro warp {
	$emptyList = 0
	$isWalkable = 1
	$cellIsFull = 0
	
	call listPortals

:start
	call isWalkable
	call cellIsFull
   
	if ($emptyList = 1) goto end
	if ($isWalkable = 0 || $cellIsFull = 1) goto start

	call direction

:look
	while ($direction != $look) as look
		do bangbang
		pause 1
		$look = @eval($::char->{look}{body} - 1)
	end look

	log Pos= $.pos, Warp= $warp, Direction= $direction, Look= $look
	log do the warp at $warp here
	stop

:end
	log Spot Is Not Available!!
}

macro direction {
   do eval ($::Macro::Data::varStack{warp}, $::Macro::Data::varStack{look}) = ($_warp{x} ." ". $_warp{y}, $::char->{look}{body} - 1);my %_pos = ("x" => $::char->{'pos'}{'x'}, "y" => $::char->{'pos'}{'y'}); getVector(\%_vec, \%_pos, \%_warp);$::Macro::Data::varStack{direction} = int sprintf("%.0f", ((360 - vectorToDegree(\%_vec)) / 45) - 1);
}

macro listPortals {
   do eval my @lines;@_x = ($::char->{'pos'}{'x'} - 2) .. ($::char->{'pos'}{'x'} + 2); @_y = ($::char->{'pos'}{'y'} - 2) .. ($::char->{'pos'}{'y'} + 2);foreach my $_a (@_x) {foreach my $_b (@_y) {next if ($_a == $::char->{'pos'}{'x'} && $_b == $::char->{'pos'}{'y'});push @lines,$_a ." ". $_b}} $_lines = join ", ", @lines;
}

macro isWalkable {
   do eval if ($_lines eq "" || !defined $_lines) {$::Macro::Data::varStack{emptyList} = 1;return} ($_warp{x},$_warp{y}) = undef; my @_coors = split(/, /, $_lines); foreach (@_coors) {my @_coor = split(/ /, $_);next if (!$::field->isWalkable($_coor[0], $_coor[1])); ($_warp{x},$_warp{y}) = ($_coor[0],$_coor[1]);last} if (!defined $_warp{x} || !defined $_warp{y}) {$::Macro::Data::varStack{isWalkable} = 0}
   if ($isWalkable = 0) call deleteSpot
}

macro cellIsFull  {
   do eval if ($_lines eq "" || !defined $_lines) {$::Macro::Data::varStack{emptyList} = 1;return} foreach (@{$::playersList->getItems()}) {next if ($_->{pos_to}{x} != $_warp{x} || $_->{pos_to}{y} != $_warp{y});$::Macro::Data::varStack{cellIsFull} = 1;last}
   if ($cellIsFull = 1) call deleteSpot
}

macro deleteSpot {
   do eval my @lines; my @_isWalkable = split(/, /,$_lines);foreach (@_isWalkable) {next if ($_ eq $_warp{x}." ".$_warp{y}); push @lines,$_; } $_lines = join ", ", @lines
}

The code still need to do some if statement regarding on whether to use bingbing or bangbang... other than that.. its done.


[Edited]
Darki wrote:What does that code you posted, to get the 24 spots? Is there a way to make it so depending on the position you're facing, it get's the spots in a defined order?
Yes. Yes with the help of the macro direction. But you need to reverse engineering the code. Ex: x = y + z.. so y = x - z

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

Re: Warp Portal macro

#6 Post by Darki »

Goddamnit, it's too early for so much code... :shock:

Let me try to understand this... First you ckeck the spots in one direction, then if there aren't free spots, you change the direction and check again? Why you check all spots around the character and then check the other spots in other directions? I'm not really sure about what do macros direction and listportals... or well, I kinda understand but I don't see the way the macro works. ._.

At the beggining of my "research" when I was writting the first attemp of the code, the bot was checking some spots in all directions, but I tried to get the position of the spots in the direction it was facing because I don't need it to check everywhere. That's whay I like the idea of the code I tried, but it seems you're going in a totally different path.

So, seeing that code works, I'm still curious of how would be the other code. I'd love to learn the correct way, because it annoys me not being able to complete it. D: so, how would it be then?
ImageImageImage
ImageImageImage
ImageImageImage

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

Re: Warp Portal macro

#7 Post by ezza »

Darki wrote:Goddamnit, it's too early for so much code... :shock:
Just consider you are very lucky to have such example in your early exp.


Darki wrote:Let me try to understand this... First you ckeck the spots in one direction, then if there aren't free spots, you change the direction and check again? Why you check all spots around the character and then check the other spots in other directions? I'm not really sure about what do macros direction and listportals... or well, I kinda understand but I don't see the way the macro works. ._.
Simple to say...
1st group: (x-2, y-2), (x-2,y-1), (x-2, y), (x-2, y+1), (x-2, y+2)
2nd group: (x-1, y-2), (x-1,y-1), (x-1, y), (x-1, y+1), (x-1, y+2)
3rd group: (x, y-2), (x,y-1), will skip (x, y), (x, y+1), (x, y+2)
4th group: (x+1, y-2), (x+1,y-1), (x+1, y), (x+1, y+1), (x+1, y+2)
5th group: (x+2, y-2), (x+2,y-1), (x+2, y), (x+2, y+1), (x+2, y+2)

The portal list will generate in that order and always priority from the left to right of 1st group and so on for the next group. The $direction is your warp direction from your standing spot. The while statement will check if your $look is in the same direction as your warp spot direction. This method is vice versa from your method... it set the warp spot 1st and then try to look at the spot while yours is try to find the spot from your $look direction. Thats it.

Darki wrote:...but it seems you're going in a totally different path...
Ermm... maybe I'm over reacting abit in this case. Sorry if that will caused you a fatal brain damage.



p.s: See also the updated code above. Good Luck^^

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

Re: Warp Portal macro

#8 Post by Darki »

Don't take me wrong, I'm really thankful for your help, Ezza. I'ts just that I'd also like to know what were my errors in my own tries, because that's the code I do understand barely, and I'm sure you know I'd understand even better if I'm corrected in something I already tried than in a totally new thing. xD

For your idea, just a stupid question. What's the point on making the bot looking to the direction AFTER calculating the spot for the portal? I mean, when you do an skill you automatically face the direction, so if you calculate the spot already, there's no need to look there, I guess, you'd only need to cast the skill directly. Am I wrong?

Let me explain a little further my idea, because I think there's a little missunderstanding. In the original macro, the bot check the place where it's looking, not to get a direction to start, but to take a place to cast the portal. You don't check the area around you, you check the area around those spots once you calculate them to have a wide area in front of you. For example, if you're looking north, the bot will get as a default spot one 4 squares up, and then it will calculate alternative spots in an area around THAT spot, not around you.

The looking direction was, to give an order to that calculation. If you're looking north and the default spot is not usable, it will start looking in the spots closer to you. But if you leave that code in that way for all directions, then when you look south it would start getting the alternative coordenates from the same order and it would be in the further squares, not the closer ones.

I don't see the idea in my code that bad because it let you manipulate the directions in a very easy way (you just need to change the orders in the $z string thingy), but well, I hope I explained yet, when I do in english I end thinking I suck at explaining. :(
ImageImageImage
ImageImageImage
ImageImageImage

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

Re: Warp Portal macro

#9 Post by ezza »

How about ...

Code: Select all

if ($look = -1) {take out all the spots which direction is 6, 7 and 0}
if ($look = 0) {take out all the spots which direction is 7, 0 and 1}
and so on...
Note: Direction is based on the 45 degree round the clock each block. Is it logic?

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

Re: Warp Portal macro

#10 Post by Darki »

But wouldn't cover more area without unnecesary checks the other way? To do what you mean in the same squares that I mean, it'd need a check of an area of 13x13 squares (169 squares), and it's very difficult not to find a free spot in an area of 5x5 in front of you unless you are stepping in front of a wall on purpose.

For a "normal bot" I'm sure your method would be the best, but as I'm trying to use it by chat commands in a slave bot I think there's no need to do so much work, you can see with your own eyes when your bot is facing a wall and just move it. If it's following you, there usually will be space around you and the bot tends to face you (not by the config thingy, just by walking with you). And even in worst of the cases, you could just add a "bangbang" and repeat macro.

That, and I think this way with this code (but well done):

Code: Select all

do eval $_x = $::char->{'pos'}{'x'};$_y = $::char->{'pos'}{'y'};$_l = $::char->{look}{body} - 1;if ($_l == 6) {$_x -= 3;$_y += 3} elsif ($_l == 5) {$_x += 4} elsif ($_l == 4) {$_x += 3;$_y -= 3} elsif ($_l == 3) {$_y -= 4} elsif ($_l == 2) {$_x -= 3;$_y -= 3} elsif ($_l == 1) {$_x -= 4} elsif ($_l == 0) {$_x -= 3;$_y += 3} else {$_y += 4};
   if ($_l == 6 || $_l == 5) {foreach my $z ( [0,0], [0,1],[1,0],[0,-1],[-1,0], [-1,1],[1,1],[1,-1],[-1,-1],[0,2],[2,0],[0,-2],[-2,0] )}
   elsif (($_l == 4 || $_l == 3) {foreach my $z ( [0,0], [0,1],[1,0],[0,-1],[-1,0], [-1,1],[1,1],[1,-1],[-1,-1],[0,2],[2,0],[0,-2],[-2,0] )}
   elsif (($_l == 2 || $_l == 2) {foreach my $z ( [0,0], [0,1],[1,0],[0,-1],[-1,0], [-1,1],[1,1],[1,-1],[-1,-1],[0,2],[2,0],[0,-2],[-2,0] )}
   else {foreach my $z ( [0,0], [0,1],[1,0],[0,-1],[-1,0], [-1,1],[1,1],[1,-1],[-1,-1],[0,2],[2,0],[0,-2],[-2,0] )}

# here would check the look direction and depending on that would set the $z in an order to make it closer to the caster. Yes, I know in all cases the $z is the same, but as I'm trying to figure out how to do the other parts, that's a minor problem, I'll change them when the other things are clear

      next if !$field->isWalkable($_x + $z->[0], $_y + $z->[1]);
      foreach (@{$::playersList->getItems()}) { next if ($_->{pos_to}{x} != $_x + $z->[0] || $_->{pos_to}{y} != $_y + $z->[1]);

# here would check if the spot is walkable and full. It'd need also a check for npcs but I don't know how to do it in eval.

      $_x += $z->[0];
      $_y += $z->[1];
      return 1;
   }
   return 0;
}
$::Macro::Data::varStack{look} = $_l; $::Macro::Data::varStack{wx} = $_x; $::Macro::Data::varStack{wy} = $_y;
would be even more simple in terms of understanding and tweaking. You could, for example, control perfectly the order to get the spots in every direction, and everything would be done by 1 eval.

That, if I knew how to write that in the correct syntax, something I don't know.
ImageImageImage
ImageImageImage
ImageImageImage

Post Reply