Code: Select all
#############################################
automacro onStart {
hook in_game
run-once 1
exclusive 1
set inGame 1
call coors
}
macro coors {
do eval @_degree0 = ([-1,1],[-2,2],[-1,2],[0,1],[0,2],[1,1],[2,2],[1,2]);@_degree315 = ([-1,0],[-2,0],[-2,1],[-2,2],[-1,1],[-1,2],[0,1],[0,2]);@_degree270 = ([-1,-1],[-2,-2],[-2,-1],[-1,0],[-2,0],[-1,1],[-2,1],[-2,2]);@_degree225 = ([-1,0],[-2,0],[-1,-1],[-2,-1],[-2,-2],[-1,-2],[0,-1],[0,-2]);@_degree180 = ([-1,-1],[-2,-2],[-1,-2],[0,-1],[0,-2],[1,-1],[1,-2],[2,-2]);@_degree135 = ([0,-1],[0,-2],[1,-1],[1,-2],[2,-2],[2,-1],[1,0],[2,0]);@_degree90 = ([1,-1],[2,-2],[2,-1],[1,0],[2,0],[1,1],[2,1],[2,2]);@_degree45 = ([1,0],[2,0],[1,1],[2,1],[2,2],[1,2],[0,1],[0,2]);
}
############################################
macro warp {
if ($inGame = 1) goto pass
goto end
:pass
$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 setWarp
log Pos= $.pos, Warp= $warp, Look= $look
log do the warp at $warp here
stop
:end
log Spot Is Not Available!!
}
macro setWarp {
do eval ($::Macro::Data::varStack{warp}, $::Macro::Data::varStack{look}) = ($_warp{x} ." ". $_warp{y}, $_l)
}
macro listPortals {
do eval $_l = $::char->{look}{body} - 1;if ($_l == -1) {@_degree = @_degree315} elsif ($_l == 0) {@_degree = @_degree0} elsif ($_l == 1) {@_degree = @_degree45} elsif ($_l == 2) {@_degree = @_degree90} elsif ($_l == 3) {@_degree = @_degree135} elsif ($_l == 4) {@_degree = @_degree180} elsif ($_l == 5) {@_degree = @_degree225} else {@_degree = @_degree270};
do eval my @lines;foreach (@_degree) {my $_x = $::char->{pos}{x} + $_->[0];my $_y = $::char->{pos}{y} + $_->[1];push @lines, $_x ." ". $_y} $_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 @_delete = split(/, /,$_lines);foreach (@_delete) {next if ($_ eq $_warp{x}." ".$_warp{y}); push @lines,$_; } $_lines = join ", ", @lines
}
I think the code above suits you very well. The angle that you are looking is 90 degree. Let say $look = 0, the angle should be around 315 to 45 degree. Thats is our range of sight i mean human sight. But there will be only 8 spot per $look. If you want more spot, try edit the macro coors so that it will include more far coordinate.
Note: in_game hook currently is in $conState == 4, so it wont trigger unless --> http://forums.openkore.com/viewtopic.ph ... 942#p21942
Happy warping ^^