Author Topic: Writing my first script  (Read 7044 times)

0 Members and 1 Guest are viewing this topic.

Offline the surfaceTopic starter

  • Jr. Member
  • **
  • Posts: 12
  • Activity:
    0%
  • Reputation Power: 1
  • the surface has no influence.
  • Respect: +9
  • Referrals: 0
    • View Profile
Writing my first script
« on: July 10, 2023, 04:41:10 AM »
+1
My goal or what IM attempting to do is to follow my other character using pathfinding. Its harder than I thought... Thank you all for any suggestions or help. I wanted to keep it simple.

 %moveDelay 500

mainloop:
   sub chooseTarget
   sub followTarget
   wait 1s
   goto mainloop

sub chooseTarget
   display ok "Click on the player you want to follow."
   set #targcurs 1
   wait 5s
   return

sub followTarget
   set %targetID #ltargetid
   if %targetID = 0
   {
      display ok "No target selected. Retargeting."
      wait 1s
      return
   }

   set %targetX $x[%targetID]
   set %targetY $y[%targetID]
   set %targetZ $z[%targetID]

   event rightclick %targetX %targetY %targetZ
   wait %moveDelay
   event rightclick %targetX %targetY %targetZ
   wait %moveDelay
   return

Offline Scotch_Tape

  • Jr. Member
  • **
  • Posts: 55
  • Activity:
    0%
  • Reputation Power: 1
  • Scotch_Tape has no influence.
  • Respect: +7
  • Referrals: 0
    • View Profile
Re: Writing my first script
« Reply #1 on: July 15, 2023, 09:14:18 AM »
+1
Did you figure this all out bud?

Offline the surfaceTopic starter

  • Jr. Member
  • **
  • Posts: 12
  • Activity:
    0%
  • Reputation Power: 1
  • the surface has no influence.
  • Respect: +9
  • Referrals: 0
    • View Profile
Re: Writing my first script
« Reply #2 on: July 21, 2023, 05:42:22 AM »
+1
I have weekends to tinker with scripting. So far im still at this juncture. Thanks, cheers!

Offline Scotch_Tape

  • Jr. Member
  • **
  • Posts: 55
  • Activity:
    0%
  • Reputation Power: 1
  • Scotch_Tape has no influence.
  • Respect: +7
  • Referrals: 0
    • View Profile
Re: Writing my first script
« Reply #3 on: July 21, 2023, 12:33:35 PM »
+1
I was going to just give you hints to see if you were actually willing to work on this, but I ended up just doing it.  This is pretty basic and could be improved but you'll have to ask questions about it if you want something more and I'll try to show you how.  Tried to comment so you'd see why I did certain things.  Took some liberties with what I was guessing you were trying to do.  I added a hotkey to change who you are following.  OnHotKey works regardless of what client you're playing on or if the client is minimized so keep that in mind when setting it to something. Currently set to the "HOME" Key

Some things you may consider adding:
     
-If your character you are following dies you pause script so when you switch clients it won't screw you up trying to follow the ghost or keep you from running   away. You could also try to cast Invisibility or use hiding skill.

-Cast spells on your main character or cross heal. Heal and cure yourself if you're not currently pathfinding.  If you use bandages on follow character you could just apply a bandage on the run.

-Accept trade if you drop something on your slave character. 

-Move 1 tile off your character instead of always being right on top.

This may just be all you wanted and so enjoy but if you want to actually learn I suggest adding more and asking or looking up anything in this small script that doesn't make sense to you. 

There are many ways of doing these kinds of scripts so keep that in mind if you had a different idea on what you wanted to do I just assumed a lot from what little you had. 



Code: [Select]
set %Hotkey Home ;Follow someone Else on the fly change to any key

   gosub chooseTarget
mainloop:
   Onhotkey %Hotkey     ;Follow Someone Else
    gosub chooseTarget  ;Need "gosub" not sub.
   gosub followTarget   ;Need "gosub" not sub.
   goto mainloop

sub chooseTarget
   event ExMsg #CHARID 3 0 Click on the player you want to follow.
   set #targcurs 1
   while #TARGCURS = 1  ; This will just wait for
    wait 20                       ; the target cursor to change
   set %targetID #ltargetid
return
   
sub followTarget
    findItem %targetID G_16 ;Got to find X and Y of what you want to follow
    Wait 1
    set %Timer #SCNT + 3    ;Timer so it doesn't get stuck if X and Y no good
    If #CHARPOSX <> #FindX || #CHARPOSY <> #FindY
     {
     event PathFind #FindX #FindY ;This is how you get your dude to move to coords
      while #CHARPOSX <> #FindX && #CHARPOSY <> %CharY  ;waiting for you to get there
      {
       wait 10
       if %Timer < #SCNT
        break             ;Break you out of the while loop if it's taking too long
      }
     }
Return

Some documentation:
While Loop
http://wiki.easyuo.com/index.php?title=While

Break
http://wiki.easyuo.com/index.php?title=Break

If Statement
http://wiki.easyuo.com/index.php?title=If

Gosub
http://wiki.easyuo.com/index.php?title=Gosub

Hotkey

http://wiki.easyuo.com/index.php?title=OnHotKey


Event Pathfind
http://wiki.easyuo.com/index.php?title=Event_PathFind

Variables
http://wiki.easyuo.com/index.php?title=Variables

Offline the surfaceTopic starter

  • Jr. Member
  • **
  • Posts: 12
  • Activity:
    0%
  • Reputation Power: 1
  • the surface has no influence.
  • Respect: +9
  • Referrals: 0
    • View Profile
Re: Writing my first script
« Reply #4 on: July 23, 2023, 05:17:39 AM »
+1
Wow, incredible... you really were spot on in what I wanted to achieve. I tested it out and it worked so well... if I wanted to integrate anything else all of your suggestions were good ideas. The heal and cure yourself if you're not currently pathfinding and dropping/accepting trades on the slave character are two things I would love to integrate or learn how. THANK YOU Scotch Tape!!!!

Also, thank you for including the references broken down at the end. That helps me a lot.
« Last Edit: July 23, 2023, 05:47:14 AM by the surface »

Tags: