Author Topic: Follow sub  (Read 8315 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
Follow sub
« on: February 13, 2010, 04:19:13 AM »
0
I need a following sub routine that will stop X tiles short of the followed target.

Right now I'm using

Code: [Select]
sub follow
Finditem %follow_target G_15
if #finddist > 2
  {
  event pathFind #findx #findy #findz
  }
return

I like the pathFind because the script continues while the char moves. Unlike the "move" command that must complete it's move before continuing the script.

Quote from: EasyUO Docs
The move command moves the character to a specified position. No pathfinding is done, so you should probably use event PathFind instead.

Event Pathfind - Please note that your script will keep on executing while the character is moving.

The issue is that the char will follow the target until the char is right on top of the char. I want to stop short by X (defined by me) tiles. AND I want the char to stop X tiles behind the target no matter what direction the target is going.

So if the target is going NORTH, I want to follow and stop say 4 tiles SOUTH of the target. And if the target is traveling WEST I want to stop 4 tiles EAST of the target.

If anyone has a good sub, or knows of one, lemme know so I can play with it.
« Last Edit: February 13, 2010, 04:21:32 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.

Offline Paulonius

  • Elite
  • *
  • *
  • Posts: 2040
  • Activity:
    0%
  • Reputation Power: 29
  • Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.
  • Respect: +162
  • Referrals: 1
    • View Profile
Re: Follow sub
« Reply #1 on: February 13, 2010, 05:33:13 AM »
0
What about working with an equation with -2 off of X and Y you are going to and X Y you currently have? You would have to account for the difference in different directions. Maybe something like this:


Code: [Select]
 
If #FindX > #CharposX
Set %NewFindX #FindX - 2

If #FindX < #CharposX
Set %NewFindX #FindX + 2

If #FindX = #CharposX
  {
  If #FindY > #CharposY
  Set %NewFindX #FindX - 2

  If #FindY < #CharposY
  Set %NewFindX #FindX + 2
 }

I think it would need another set of equations to work on the Y axis and some logic to decide which to use, but this is what I have been thinking about.  If you mod X and Y both you get the follower in a wing pattern and with a couple of followers you could walk around like a flock of geese. 

I would also like it to include a walk or run command so that it would keep you in stealth if appropriate.
« Last Edit: February 13, 2010, 05:38:09 AM by Paulonius »
This coin declares Caesar is "Dictator for Life." He did serve as Dictator for the remainder of his life, but his life would end only a few weeks after this issue. For Caesar to put his image on coins and essentially declare himself king was too much for Brutus and his republican allies.

"If everything seems under control, you're not going fast enough'
-Mario Andretti

"If everyone is thinking alike, someone isn't thinking."
- General George Patton Jr

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: Follow sub
« Reply #2 on: February 13, 2010, 08:13:06 AM »
0
That's what I need, some way of stopping short.

I'll play with it some and see what I can put together. I was hoping someone had already seen something in a script somewhere.
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 TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13303
  • Activity:
    0.4%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Follow sub
« Reply #3 on: February 13, 2010, 09:09:41 AM »
0
I have one Cerveza I'll give ya that I used for a PvP bot contest I was working on.  You just can't distribute it since it's directional oriented.  It's funny chase my bot.  lol
Please read the ScriptUO site RULES
Come play RIFT with me!

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: Follow sub
« Reply #4 on: February 13, 2010, 12:54:13 PM »
0
Nice! I'll work it in. Thanks TM
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 TrailMyx

  • Officially retired from UO
  • Administrator
  • *
  • *
  • Posts: 13303
  • Activity:
    0.4%
  • Reputation Power: 154
  • TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!TrailMyx is awe-inspiring!
  • Gender: Male
  • Viper!
  • Respect: +1349
  • Referrals: 33
    • View Profile
    • ScriptUO
Re: Follow sub
« Reply #5 on: February 13, 2010, 12:57:48 PM »
0
Nice! I'll work it in. Thanks TM

Ok, lemme locate it.  Remember, for your eyes only.  ;)
Please read the ScriptUO site RULES
Come play RIFT with me!

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: Follow sub
« Reply #6 on: February 16, 2010, 06:50:54 AM »
0
I like TM's solution, but since this would be a release script I'll have to come up with something myself. I was thinking along the lines of Pauls solution... here's my idea.

Code: [Select]
set %buffer 4

finditem %primary G_
if #finddist > %buffer
{
set %primaryX #findX
set %primaryY #findY
set %primaryZ #findZ

if #charPosX > %primaryX
set %movePosX ( %primaryX + %buffer )

if #charPosX < %primaryX
set %movePosX ( %primaryX - %buffer )

if #charPosX = %primaryX
set %movePosX %primaryX

if #charPosY > %primaryY
set %movePosY ( %primaryY + %buffer )

if #charPosY < %primaryY
set %movePosY ( %primaryY - %buffer )

if #charPosY = %primaryY
set %movePosY %primaryY

set %movePosZ %primaryZ

event pathFind %movePosX %movePosY %movePosZ
}
return

That *should* set the x and y properly for the char to stop behind in any of the 8 primary directions.
« Last Edit: February 16, 2010, 06:54:33 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.

Offline UOMaddog

  • Maddog
  • Elite
  • *
  • *
  • Posts: 1625
  • Activity:
    0%
  • Reputation Power: 22
  • UOMaddog might someday be someone...UOMaddog might someday be someone...UOMaddog might someday be someone...UOMaddog might someday be someone...
  • Gender: Male
  • Biggest B@D@$$ of the Universe
  • Respect: +165
  • Referrals: 8
    • View Profile
    • Insane UO
Re: Follow sub
« Reply #7 on: February 16, 2010, 01:33:45 PM »
0
You can't guarantee the Z-axis is correct however many tiles away from the person you're following, thereby causing the script to fail to pathfind. However, you might be able to look at the #TILEZ for the X/Y-coordinates. Just an idea!
There are 10 kinds of people in this world: those that understand binary and those that don't!

Windows:  A 64-bit tweak of a 32-bit extension to a 16-bit user interface for an 8-bit operating system based on a 4-bit architecture from a 2-bit company that can't stand 1 bit of competition!

Offline Paulonius

  • Elite
  • *
  • *
  • Posts: 2040
  • Activity:
    0%
  • Reputation Power: 29
  • Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.
  • Respect: +162
  • Referrals: 1
    • View Profile
Re: Follow sub
« Reply #8 on: February 16, 2010, 02:04:49 PM »
0
I think there is going to be a Z variance to account for a lot of the time unless you are standing on the same spot, but do you really need Z for the pathfind? I leave Z out for subs that run into my house and it works fine.
This coin declares Caesar is "Dictator for Life." He did serve as Dictator for the remainder of his life, but his life would end only a few weeks after this issue. For Caesar to put his image on coins and essentially declare himself king was too much for Brutus and his republican allies.

"If everything seems under control, you're not going fast enough'
-Mario Andretti

"If everyone is thinking alike, someone isn't thinking."
- General George Patton Jr

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: Follow sub
« Reply #9 on: February 23, 2010, 06:59:33 AM »
0
This was over at EUO

Code: [Select]
if #FindX >= #CharPosX
  set %x #FindX - 1
else 
  set %x #FindX + 1
 
if #FindY >= #CharPosY
  set %y #FindY - 1
else 
  set %y #FindY + 1
 
event pathfind %x %y #findz

Just putting it here to consolidate all these options.
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 MWinc

  • Restricted - No Posting
  • *
  • Posts: 1
  • Activity:
    0%
  • Reputation Power: 0
  • MWinc has no influence.
  • Respect: 0
  • Referrals: 2
    • View Profile
Re: Follow sub
« Reply #10 on: March 08, 2010, 09:35:39 AM »
0
Code: [Select]
namespace global Movement
set !characters ; all characters intending to be moved
set !Leader ; the leader
set %Move_Timer 200 ; time in ms between move checks
set %Move_Time #systime
set %Follow_Dist 2 ; how far it stays behind

While #true
{
while #systime < %Move_Time
wait 1
repeat
uoxl swap
until #charid = !Leader
set !Leaderx #charposx
set !Leadery #charposy
for %clinr 1 #clicnt
{
uoxl swap
if #charid notin !characters
continue
Gosub Calculate_Dist ; Some math required in this sub. Explanation below
if #result > 2
{
gosub Calculate_Move ; based on #chardir sets where the follower should move
Event pathind %Pathfindx %Pathfindy %Pathfindz
}
}
set %Move_Time #systime + %Move_Timer
}

Sub Calculate_Dist
set %Distance_X ABS ( #charposx - !Leaderx )
set %Distance_Y ABS ( #charposy - !Leadery )
if %Distance_X >= %Distance_Y
set %Distance1 %Distance_X
else
set %Distance1 %Distance_Y
set %Total_Distance  ( %Distance1 + ( ABS ( %Distance_X - %Distance_Y ) ) )
return %Total_Distance

The Cpu usage and script lag for doing a mathematical calculation is far less than that of Repeated Finditems. Plus Utilizing the info already on your computer (!Leaderx !Leadery) you get a much more accurate reading of the distance/location.
« Last Edit: March 08, 2010, 10:51:44 AM by manwinc »

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: Follow sub
« Reply #11 on: March 08, 2010, 11:35:46 AM »
0
I see what your doing, eliminate the finditem to determine distance and use values of x,y for the different chars.

I'll play with that... thanks!
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 manwinc

  • Elite
  • *
  • *
  • Posts: 2556
  • Activity:
    0%
  • Reputation Power: 32
  • manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!manwinc is a rising star!
  • Gender: Male
  • "The Devs Hard at Work"
  • Respect: +123
  • Referrals: 1
    • View Profile
Re: Follow sub
« Reply #12 on: March 08, 2010, 11:48:17 AM »
0
Yeah, I haven't played with the sub for find dist yet because all i've incorporated is moving to the Exact location of the leader
Monkeys and Typewriters!

" Oh I know, We'll make a Boss Encounter that requires 3 keys per player to enter, Then we'll make it not a closed instance so you never know if you are going to pop into a fresh room or a boss that has 1% Health left with 20 dudes smashing its face in, wasting your time and effort"

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: Follow sub
« Reply #13 on: March 08, 2010, 11:52:05 AM »
0
It will work, I'm sure. Swap to one char, note his position, swap to the other char, note his position. Compare the two and move accordingly.

Eliminating the finditem is a great idea. Swapping is much quicker. I'm going to work this idea into my movement. I also want to go back to a position oriented system, now it's based on whatever direction the Primary char is facing, which *could* be a problem.
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 NObama

  • Everything I need to know, I learned from Miffy's Item Finder.
  • Elite
  • *
  • *
  • Posts: 3454
  • Activity:
    0%
  • Reputation Power: 43
  • NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.NObama is a force to reckon with.
  • Respect: +161
  • Referrals: 2
    • View Profile
Re: Follow sub
« Reply #14 on: March 08, 2010, 11:53:18 AM »
0
Yeah, I haven't played with the sub for find dist yet because all i've incorporated is moving to the Exact location of the leader

Another reference to the army!  It's like manwinc has a superpower that lets him predict which threads I'm lurking each day and posts tidbits to torment me!

Curses!

:p

Tags: