Author Topic: Attack closest?  (Read 6679 times)

0 Members and 1 Guest are viewing this topic.

Offline lob91Topic starter

  • Jr. Member
  • **
  • Posts: 25
  • Activity:
    0%
  • Reputation Power: 1
  • lob91 has no influence.
  • Respect: +3
  • Referrals: 0
    • View Profile
Attack closest?
« on: July 19, 2010, 09:38:29 PM »
0
I have my script to auto attack monsters, and I want it to switch to a monster if it is within striking distance, rather than the one 2-10 tiles away that it has previously targeted...

What am I doing wrong?

attack_loop:
wait 1
EVENT macro 27
FINDITEM %enemy g_8
IF #FINDKIND = 1
{
finditem %creature g_2
if #findkind = 1
set %enemy #findID
wait 2
goto attack_loop
}
goto loop
...

%enemy is the current target, and %creature is my list of monsters to search for.

Scrripty

  • Guest
Re: Attack closest?
« Reply #1 on: July 19, 2010, 11:34:28 PM »
0
The best way is to search from 1 to 10 tiles away.  Always search 1 tile out, then 2 then 3 then 4 then 5 until a monster is found.  That way it always attacks the closest monster first.  Remember that G_2 just makes it search for ANY creature within 2 tiles.  Not the one you want to attack.  So you should probly start by defining your search distance first.

for %searchDistance 1 10

That's going to be your for loop to search for %creatures.  It's just telling EUO that you want to create a variable and that you want it to loop 10 times increasing by 1 each time.  You always want to use brackets with for loops.  So go like this:

Code: [Select]
for %searchDistance 1 10
{
  put your code here to search for creatures
}

When you do that, anything within the brackets will be executed 10 times.  And that variable will be increased by one, so we'll use that as our distance like this:

Code: [Select]
for %searchDistance 1 10
{
  finditem %creature G_ , %searchdistance
  if #findcnt > 0
  {
    do your code here to the monster found
  }
}

That should do what you want if put inside a loop.  The way it sits now tho, if you JUST looped it, it would find ALL monsters from 1 to 10 eventually and do whatever it is you're gonna do.  Is this a spawn attack script to just draw them in?  Do you want it to wait until the attacked monster is dead?  You need to fill all that in and make sure those conditions are accounted for. :)

Offline lob91Topic starter

  • Jr. Member
  • **
  • Posts: 25
  • Activity:
    0%
  • Reputation Power: 1
  • lob91 has no influence.
  • Respect: +3
  • Referrals: 0
    • View Profile
Re: Attack closest?
« Reply #2 on: July 20, 2010, 06:30:17 AM »
0
Yeah, when it initially searches for %creature it searches tiles 1-2-3-4-5-6-7-8, and that works fine... It attacks the closest first like it should. My script loops attack, until it is dead. I want it to constantly be searching for a new %creature within 1 tile from me while killing the one I already found. If the one I am currently killing has a #finddist > 1 and there is a new creature to attack that is right next to me, it should switch to that target, but it doesnt.

I`ll tinker around with it tonight... I just couldnt figure out why it wont change targets to 1 that is right next to me if my current target is not!!

Thanks Twinkle McNugget

Scrripty

  • Guest
Re: Attack closest?
« Reply #3 on: July 20, 2010, 08:14:50 AM »
0
One more thing:  You have no real wait after attacking your monster... there's built in wait times for certain things.  I'm sure you can't attack faster than say wait 10 or 15?  Maybe event 20? :)  The more you go past the built in UO defaults for things, the more you risk crashing or having strange results.

Offline lob91Topic starter

  • Jr. Member
  • **
  • Posts: 25
  • Activity:
    0%
  • Reputation Power: 1
  • lob91 has no influence.
  • Respect: +3
  • Referrals: 0
    • View Profile
Re: Attack closest?
« Reply #4 on: July 20, 2010, 03:31:01 PM »
0
Yeah I have a wait in there...

I have written some pretty wicked scripts before, but I have been out of the game for a while now, and slowly remembering the code. The script I am writing is basically just me figuring out how/what my script will look like, and gettings timers correct.. (It is a auto sampie script) (I know you have a badass one, but I do not get enjoyment of just hitting "play" and being able to reap the rewards... I would rather do some work myself and be proud of it :) )

I know the code I gave you was pretty bad, but I won't be using it hehe. It just has me stumped on why it won't work... I am going to look at it after work tonight and maybe it was just me being tooo tired and stoned last night!! :P As far as I was reading it, it should loop attack on my selected monster until either it is dead, or it finds a new monster within 1 tile, and if it finds that monster it should attack it!!!

Anyways, thanks for your help Twinkle McNugget, I do appreciate it. I'll let you know how I find away for it to work.

Tags: