Author Topic: Follow sub  (Read 8317 times)

0 Members and 1 Guest are viewing this topic.

Scrripty

  • Guest
Re: Follow sub
« Reply #15 on: March 08, 2010, 12:20:40 PM »
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.

That gave me a small idea for the targetter I'm working on.  It does a finditem every loop to find new targets... so I basically made it a for #findindex loop and sped it WAY up. :)  The little things set off inspiration I guess.  Now it will scan for new enemies and iterate through ALL FOUND before searching again.  It's a little thing... but in some situations it REALLY speeds things up.  I ran around luna and added vendor scanning... and they loaded up pretty fast since I didn't have to do a finditem for EVERY one of them.  I do an initial finditem, then loop through it testing each one found for addition to my lists... so all of them that are found get ignored before the next scan.  Sped it WAY up. :)  I knew to do this, but it just sparked me to get it done.  I also noticed a little tidbit that anything PLAYER based gets loaded immediately no matter what.  But anything like a vendor or an npc, WILL NOT update it's info while you are running.  It waits till you stop or pause your running.  Something to think about while writing scripts.

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 #16 on: March 09, 2010, 07:20:59 PM »
0
So, I was running the following part of the army utilizing the Math functions Orn gave me from EUO and noticed that my characters weren't following me when they had a #finddist of 10 and I set them to follow if the Computed Distance was Less than 15.


Did Some tests between Calculated Distance and #Finddist and Determined that you can just use this

Code: [Select]
set %Distance_X ABS ( #charposx - %Pathfindx )
set %Distance_Y ABS ( #charposy - %Pathfindy )
if %Distance_X >= %Distance_Y
set %Distance1 %Distance_X
else
set %Distance1 %Distance_Y

%Distance1 = #finddist
for every instance I've tested So far.
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 BadManiac

  • Jr. Member
  • **
  • Posts: 61
  • Activity:
    0%
  • Reputation Power: 4
  • BadManiac has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Re: Follow sub
« Reply #17 on: March 10, 2010, 04:29:55 PM »
0
I need a following sub routine that will stop X tiles short of the followed target.
I'll be giving you exactly that as soon as I get home today. Watch this space.

You can use my Automagic Pathfinding sub along with a component sub from it called "ScaledLine" to achieve what you're trying to do. I initially wrote it to use in rail engines, for resource gathering scripts, they often use move, so you need very precise routes between for example tree's and other obstacles. I wanted to use Event Pathfind instead, but it can only pathfind a small distance (depending on your update radius). So I wrote a (BIG) sub that chops a distance into manageable pieces and pathfinds each individual segment.

What you can do is use the ScaledLine sub to calculate a point X tiles away from your target, along a life from your current position to the target. Then pathfind to that new point. It'll use the UO event pathfind function, and stop X tiles from the target. I've used exactly this in the past for disco training at the oriental dragon spawn in ilsh, to disco and follow it around at a fixed distance. Don't expect EXACT precision at all times tho, UO's pathfind function has a bit of a personality ;)

I'll share the full source later when I get home.

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 #18 on: March 10, 2010, 04:43:38 PM »
0
Wow! Thanks BM! I'm looking forward to seeing/trying it out.
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 #19 on: March 10, 2010, 04:50:58 PM »
0
Cerv, DL the newest army menu/cs Run 2 Clients with it and select Fall back for the movement.
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"

Scrripty

  • Guest
Re: Follow sub
« Reply #20 on: March 10, 2010, 04:54:53 PM »
0
Cerv, DL the newest army menu/cs Run 2 Clients with it and select Fall back for the movement.

I can't wait to play with BM's sub since I had a love affair with his looter for so long. :)  I'll go test the army script for ya right now manw.

Offline BadManiac

  • Jr. Member
  • **
  • Posts: 61
  • Activity:
    0%
  • Reputation Power: 4
  • BadManiac has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Re: Follow sub
« Reply #21 on: March 10, 2010, 06:24:36 PM »
0
Ok, here's the original script posted on EUO.com: http://www.easyuo.com/forum/viewtopic.php?p=189786
Saves me posting the full description again.

The whole thing is recursive too, so if the pathfind fails, but is yet within it's timelimit, it will call itself to get around large obstacles like mountains and player houses.
For lulz try pathfinding straight through a large town like Britain. For Epic Lulz try to pathfind across an ocean (to an island from mainland) and set a really long timeout, It'll keep tying, persistent bastard that it is ;)


But the interesting bit for this task is the ScaledLine sub. Which I originally wrote a full fixed point square root function for, until I realized that all 8 directions are the same distance according to the UO client...
Take this grid: (works better in monospace font)
123
456
789
in the real world, moving from 1 to 9 is a longer distance than moving from 7 to 9. Diagonal, hypotenuse and all that. In UO it's the same distance. A right triangle where side A and B are of equal length would have an equal length hypotenuse too (wrap your head around that for a bit :P ). So that simplified the math required almost infinitely.

So here's a sub you can use alongside the pathfinding sub(s) to do what you want, right out of the box.
Note that you could use event pathfind instead of calling my sub here, or even move, if the distance is always reasonably short.

Interesting things are the ScaledLine sub, which takes two sets of coordinates, X1, Y1 and X2,Y2, and a distance, it returns a XXX_YYY formatted set of coordinates *distance* tiles away from X1,Y1 along the straight line to X2,Y2.
Sub XYReadout simply changes those to separate variables, saves a few lines of code.
Code: [Select]
;#############################
;# KeepDistance Sub
;# %1 is the target to keep at distance
;# %2 is the distance to keep
;#############################
SUB KeepDistance
SET !target %1
SET !distance %2
FINDITEM !target
IF #FINDKIND = -1
RETURN
IF #FINDDIST <> !distance
{
GOSUB ScaledLine #FINDX #FINDY #CHARPOSX #CHARPOSY !distance
GOSUB XYReadout #RESULT targx targy
GOSUB Distance #CHARPOSX #CHARPOSY !targx !targy
GOSUB BMPathfind !targx !targy 0
}
RETURN

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 #22 on: March 10, 2010, 07:07:16 PM »
0
Ok, so I have my weekend planned... around working with this!

Thanks a ton for this. I'm really looking forward to pluggin it in and seein how it runs!
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 #23 on: March 11, 2010, 01:29:59 AM »
0
Very cool.  I will be taking a look at this as well.
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 #24 on: March 11, 2010, 07:58:00 AM »
0
Lemme run this past everyone.

The %buffer is how far away I want the follower. The level at which the follower should begin movement.

Would this formula work?

Code: [Select]
sub follow
  set %pri_X #charPosX
  set %pri_Y #charPosY

gosub SwapTo %support ; swap clients to the support char
  set %sup_X #charPosX
  set %sup_Y #charPosY

; compare the two, is the formula here right?
if %sup_X < ( %pri_X + %buffer ) && %sup_X > ( %pri_X - %buffer) && %sup_Y < ( %pri_Y + %buffer ) && %sup_Y > ( %pri_Y - %buffer )
  {
    gosub SwapTo %primary ; go back to the primary char and return to the main loop because they are within %buffer of each other
    return
  }

movement stuff

I think I'm doing that right...

*The intent here is to remove the "finditem" and rely on position and math to speed up the script.
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 #25 on: March 11, 2010, 08:25:18 AM »
0
So BM, as I understand it, your script doesn't care how far away the target it is heading to is, it simply sets course based on the direction and breaks the trip down into segments to pathfind (or move) there. 

I REALLY like the idea and am psyched to check it out.  I was talking this over with MWinc and Twinkle McNugget and we were playing with the idea of creating an array of waypoints based on movement by the leader.  This sounds like it has the potential to be a lot simpler.
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 BadManiac

  • Jr. Member
  • **
  • Posts: 61
  • Activity:
    0%
  • Reputation Power: 4
  • BadManiac has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Re: Follow sub
« Reply #26 on: March 11, 2010, 08:38:23 AM »
0
The target has to be within finditem range for my sub to work, but if you're multi clienting and share the position via globals, no it doesn't matter, as long as there IS a path between the two.

Offline Katu

  • Jr. Member
  • **
  • Posts: 43
  • Activity:
    0%
  • Reputation Power: 2
  • Katu has no influence.
  • Respect: +5
  • Referrals: 0
    • View Profile
Re: Follow sub
« Reply #27 on: March 11, 2010, 01:47:49 PM »
0
So BM, if i understood right, basically it just needs the coords to look for?
Could it walk from Britain to cove? For example?
That certainly sounds great piece of ascii chars. If it works as i think, i might snag it to my current project :)

Offline BadManiac

  • Jr. Member
  • **
  • Posts: 61
  • Activity:
    0%
  • Reputation Power: 4
  • BadManiac has no influence.
  • Respect: 0
  • Referrals: 0
    • View Profile
Re: Follow sub
« Reply #28 on: March 11, 2010, 02:01:52 PM »
0
It CAN walk from anywhere to anywhere. Britain to Cove is certainly possible. However there's a lot of crap in the way so it'd take a while to get there, and getting through the swamp with a billion player houses and mobs spawning could be interesting...

It's not meant for quite such long range pathfinding, it can, but it definitely won't get you there in a hurry. I fact when I was testing it I frequently ran from the Skara ferry to east Brit bank. And from one side of Brit to the other. Takes a while for it to find the bridges and paths through mountains by completely random trial and error, but it eventually gets there.

Offline Katu

  • Jr. Member
  • **
  • Posts: 43
  • Activity:
    0%
  • Reputation Power: 2
  • Katu has no influence.
  • Respect: +5
  • Referrals: 0
    • View Profile
Re: Follow sub
« Reply #29 on: March 11, 2010, 02:39:10 PM »
0
Heh, its not like i would take that trip, i was just curious if it could handle that kind of distances.
Anyways! Sounds interesting and usefull script.

-Katu

Tags: