Author Topic: Move to a (semi)random coordinate.  (Read 4094 times)

0 Members and 1 Guest are viewing this topic.

Offline CervezaTopic starter

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Move to a (semi)random coordinate.
« on: November 18, 2009, 05:53:56 AM »
+1
I needed to randomize some landing points in Maddog's Jhelom Pens Tamer script, so I wrote this little sub.

It's working now.

Code: [Select]
;----------------------
; %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


« Last Edit: May 18, 2010, 06:24:53 AM by Cerveza »
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Scrripty

  • Guest
Re: Move to a (semi)random coordinate.
« Reply #1 on: November 19, 2009, 10:32:25 AM »
+1
I'm going to incorporate this into the jhelom weapon trainer if that's alright. :)

Offline CervezaTopic starter

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: Move to a (semi)random coordinate.
« Reply #2 on: November 19, 2009, 10:38:22 AM »
+1
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:
Code: [Select]
set !Random #random % !Increments + !Bottom
I tried even simple things:
Code: [Select]
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.
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Offline kenshin87

  • Full Member
  • ***
  • Posts: 113
  • Activity:
    0%
  • Reputation Power: 2
  • kenshin87 has no influence.
  • Respect: +35
  • Referrals: 1
    • View Profile
Re: Move to a (semi)random coordinate.
« Reply #3 on: February 26, 2010, 10:00:14 AM »
+1
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.

Offline CervezaTopic starter

  • Hacksimus Maximus
  • Scripthack
  • *
  • Posts: 5857
  • Activity:
    0%
  • Reputation Power: 80
  • Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!Cerveza is awe-inspiring!
  • Gender: Male
  • So... Hows that Hopey-Changey thing working out?
  • Respect: +403
  • Referrals: 11
    • View Profile
Re: Move to a (semi)random coordinate.
« Reply #4 on: February 26, 2010, 10:07:59 AM »
+1
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
Code: [Select]
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.
« Last Edit: February 26, 2010, 10:14:38 AM by Cerveza »
XXXXXXXXXX________________________________________] 20%
I've forgotten more about this game then most people will ever know.
Thank you for controlling your children. Their manners reflect your love for them.
Give a man a fish and you feed him for a day. Don't teach a man to fish, and you feed yourself. He's a grown man. Fishing's not that hard.

Tags: