ScriptUO
Official ScriptUO EasyUO Scripts => Script Debug => Topic started by: Kryz on August 11, 2015, 08:57:07 PM
-
Hey So I am working on my monger script, decided it was time to start diving into actual ship movement. I am looking for advice on how to effectively move the ship to a set of coordinates with little to no issues and no multiple commands, IE don't yell forward three times etc. This is what I have at the moment. Its a bit wonky at the end coordinates. Let me know what y'all think and if you know of a better way to go about this let me know i'm open to anything. I seem to always miss the target by 1 or 2 tiles and then the end mess happens.
Sub ShipGoToLocation
Set %GoalX #CHARPOSX + 10 ;change these values to set destination
Set %GoalY #CHARPOSY - 20 ; change these values to set destination
NavStart:
if #CHARPOSY > %GoalY
{
;;;
if #CHARPOSX = %GoalX
{
event Macro 3 0 Forward
while #CHARPOSY > %GoalY + 1
{
}
event Macro 3 0 stop
GOTO NavStart
}
;;;
if #CHARPOSX > %GoalX
{
event Macro 3 0 forward left
while #CHARPOSX > %GoalX +1 && #CHARPOSY > %GoalY + 1
{
}
event Macro 3 0 stop
GOTO NavStart
}
;;;
if #CHARPOSX < %GoalX
{
event Macro 3 0 forward right
while #CHARPOSX < %GoalX +1 && #CHARPOSY > %GoalY + 1
{
}
event Macro 3 0 stop
GOTO NavStart
}
}
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
if #CHARPOSY = %GoalY
{
if #CHARPOSX = %GoalX
{
event Macro 3 0 stop
halt
}
;;;
if #CHARPOSX > %GoalX
{
event Macro 3 0 left
while #CHARPOSX > %GoalX +1 && #CHARPOSY = %GoalY
{
}
event Macro 3 0 stop
GOTO NavStart
}
;;;
if #CHARPOSX < %GoalX
{
event Macro 3 0 right
while #CHARPOSX < %GoalX && #CHARPOSY = %GoalY
{
}
event Macro 3 0 stop
GOTO NavStart
}
}
if #CHARPOSY < %GoalY
{
if #CHARPOSX = %GoalX
{
event Macro 3 0 back
while #CHARPOSX < %GoalX && #CHARPOSY < %GoalY
{
}
event Macro 3 0 stop
GOTO NavStart
}
if #CHARPOSX > %GoalX
{
event Macro 3 0 back left
while #CHARPOSX > %GoalX && #CHARPOSY < %GoalY
{
}
event Macro 3 0 stop
GOTO NavStart
}
if #CHARPOSX < %GoalX
{
event Macro 3 0 forward right
while #CHARPOSX < %GoalX && #CHARPOSY < %GoalY
{
}
event Macro 3 0 stop
GOTO NavStart
}
}
halt
-
Don't forget the "forward one" and "backward one" style commands when you need to get exact.
-
So essentially I should run these within 5 or so and then go to a precise mode at that point? I don't think I need it to get the exact coordinates, IE its not TMapping a chest... If I am in the right subserver exact Coord's aren't going to break me. The way I have it now might be overkill. Ill probably redo for within a range of 5 and ignore getting the precise.
That could work with minimal code, easy enough just some fine tuning.
TM did you see anything way out of place or a way to clean up my sub a little bit?
-
This is an example of how I might do it. There leaves a lot to be worked over.
This assumes the boat is facing north. It doesn't turn the boat to make easy to pass things. There is no journal checking for "We've stopped moving".
set !NewX #CharPosX + 40
set !NewY #CharPosY + 40
gosub MoveBoat !NewX !NewY
display ok #result
halt
sub MoveBoat
if %0 <> 2
return #false
namespace push
namespace local MoveBoat , #systime , #charid
set !DestX %1
set !DestY %2
set !dX ABS ( !DestX - #charposx ) / 2
set !dY ABS ( !DestY - #charposy ) / 2
set !TimeOut #scnt + !dX + !dY + 1
set #result #false
while !DestX <> #charposx && !DestY <> #charposy && !TimeOut > #scnt
{
;North and South axis
if !DestY < #charposy
{
event macro 3 0 forward
while !DestY < #charposy
{
if !TimeOut < #scnt
{
event macro 3 0 stop
break
}
}
event macro 3 0 stop
}
else
{
if !DestY > #charposy
{
event macro 3 0 backward
while !DestY > #charposy
{
if !TimeOut < #scnt
{
event macro 3 0 stop
break
}
}
event macro 3 0 stop
}
}
;East and West Axis
if !DestX < #charposx
{
event macro 3 0 left
while !DestX < #charposx
{
if !TimeOut < #scnt
{
event macro 3 0 stop
break
}
}
event macro 3 0 stop
}
else
{
if !DestX > #charposx
{
event macro 3 0 right
while !DestX > #charposx
{
if !TimeOut < #scnt
{
event macro 3 0 stop
break
}
}
event macro 3 0 stop
}
}
}
if !DestX = #charposx && !DestY = #charposy
set #result #true
namespace clear
namespace pop
return #result
-
Do the event macro move commands work while you are piloting a boat?
-
I tried issuing the move command while piloting the boat but not specifically the event macro keys. Good question... but this works perfectly for me... maybe under lag or poor scripting you can br off a tile or two but is exact x y important? Not usually if you're not doing 8x8