ScriptUO
Official ScriptUO EasyUO Scripts => Script Snippets => Topic started by: Cerveza on November 18, 2009, 05:53:56 AM
-
I needed to randomize some landing points in Maddog's Jhelom Pens Tamer script, so I wrote this little sub.
It's working now.
;----------------------
; %1 - X Coord
; %2 - Y Coord
; %3 - + or - this many <- this is the random part
; gosub MoveRandomCoord %spotX %spotY 3
; will move you somewhere in a 9x9 box around %spotX %spotY
sub MoveRandomCoord
namespace push
namespace local MRC
set !LocationX %1
set !LocationY %2
set !Radius %3
set !BottomX ( !LocationX - !Radius )
set !TopX ( !BottomX + ( !Radius * 2 ) )
set !IncrementsX ( !TopX - !BottomX )
set !RandomX #random % !IncrementsX + !BottomX
set !BottomY ( !LocationY - !Radius )
set !TopY ( !BottomY + ( !Radius * 2 ) )
set !IncrementsY ( !TopY - !BottomY )
set !RandomY #random % !IncrementsY + !BottomY
move !RandomX !RandomY !Radius 10s
; event PathFind !RandomX !RandomY ; you can try this instead
namespace pop
return
event pathfind would be better, but it's only good for about one screen distance. If you have a small area you could try changing the move line to event pathfind.
I have set the tolerance for the move command at the !Radius variable sent to the sub. The tolerance is how close it will get to the end destination.
What this means is that after randomizing your landing point within the x by y field you specified, if there is an object at the landing site the move command will put you within !Radius of that spot.
To simplify it a bit....
gosub MoveRandomCoord 1000 1000 2
That will land you in a 4x4 square around position 1000x1000
X X X X X
X X X X X
X X O X X
X X X X X
X X X X X
Now lets say that one of those positions is a tile which you can not stop on... like a tree.
X X X X X
X X X X X
X X O X X
X T X X X
X X X X X
The move command will take you to a spot within !Radius of that tree... so in this case you will actually land.....
X X X X X X
X X X X X X
X X X X X X
X X T X X X
X X X X X X
X X X X X X
-
I'm going to incorporate this into the jhelom weapon trainer if that's alright. :)
-
Why of course it is, that's why I do these things ;)
I tried to make it all on one line... using the #random that euo provides, BUT found out you can NOT do any computing in this line:
set !Random #random % !Increments + !Bottom
I tried even simple things:
set !Random #random % ( !Top - !Bottom ) + !Bottom
Which failed.
It works great as is, just a few more lines then I wanted to use... oh well.
OH and don't use event pathfind... it gets kinda freaky movement with all the animals around. Move with a timeout works best.
-
hey cerveza must have missed this post in the navrey section. i am actually going to give this a whirl when i get home today. i wonder if that little section in the middle will work as a nice center point for navrey. seems like this may actually be the way to go for doing my script. will it pathfind around objects? i know in the middle there are a few walls that may need to get around. thank you i will let you know either tonight or tomorrow if it worked.
-
No, this sub will not pathfind. There is something that you could do here though, I'll explain after a few notes about move vs pathfind.
Move allows you to goto locations which are greater then the visible area. Pathfind does not. Move also holds up the script.
Pathfind allows you to go around blocked areas. Move does not. Pathfind doesn't hold up the script.
Ok, now onto the show....
If you use this random stop site, you can immediately do a pathfind afterwards.
I want to land at 1324 x 956
gosub MoveRandomCoord 1324 956 3
event pathfind 1324 956
That would set a random location within 3 spaces around 1324 and 956. After you move to that location (now you are definitely on the same screen as the final destination) you can event pathfind to the exact location.
I used this method when playing around with a discord rail. Works great, especially if you have always run checked.