Author Topic: While loops!  (Read 4240 times)

0 Members and 1 Guest are viewing this topic.

Scrripty

  • Guest
While loops!
« on: September 18, 2009, 08:13:46 AM »
0
Ok so I have this snipper here, and when it loops, the charghost part loops nonstop right.  It wont EVER stop looping unless you die.  Then the enemy id part loops when an enemy attacks you.  What I need it to do, is if you find an enemy BEFORE one attacks, it will honor it, and attack it, and wont stop until THAT monster is dead.  But if you get attacked I want it to go into that second while, and since it didn't find a monster to attack, I want it to try to honor the monster that attacked you but wasn't in the monster type list, because it most likely didn't find it in it's monster type list and not stop till THAT monster is dead.  And I need it to be reliable... I also want both to set !EOO to #sysTime if the TYPE of the last monster doesn't match the type of the new monster found but I've been having nothing but problems with everything I've tried.  Basically I want it to search for monsters, if found, honor, if not, but attacked, honor that one.  Any good ways to do this reliably?

Code: [Select]
repeat

   while #charghost <> yes
   {
       gosub findenemy
       if #findtype <> !lasttype
          SET !eootimer #scnt

       while #enemyid <> n/a
       {
           if !attackedbeforemonsterfound = #true
              honor #enemyid
              kill till dead
           else
              kill till dead
              {MAIN PART OF SCRIPT}
       }

   }
return

Offline Cerveza

  • 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: While loops!
« Reply #1 on: September 18, 2009, 08:20:43 AM »
0
While is a good command, I like it a lot. Most round these parts prefer Repeat/Until though.

Since you are doing the "checking" inside the sub, it might be better for you to run with repeat/until. Or even a combination of both.

I'd suggest changing out that #enemyID <> N/A as well. It won't work correctly because you might have 2 things attacking you, and after you kill the first, you'll still have #enemyID listed. I've also found that it doesn't reset itself automatically.

Better to do a count for the enemy... find it's ID then use finding it as an indicator of if it's still alive.

repeat
{
findItem %mosterID
if #findCnt > 0
{
do your stuff
}
}
until #findCnt < 1
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: While loops!
« Reply #2 on: September 18, 2009, 08:41:15 AM »
0
So maybe do this:  Does that look better?  The only thing I'm not getting with this, is I'd LIKE to have some form of backup attacking when a monster attacks you that is not in your monster id list...

Code: [Select]
repeat

   while #charghost <> yes
   {
       
       find enemy loop

       while #findcnt > 0
       {
          repeat
          {
              if !attackedbeforemonsterfound = #true
              honor #enemyid
              kill till dead
                else
              kill till dead
              {MAIN PART OF SCRIPT}
          }
          until #fndcnt < 1
       }
   }
return

Offline Cerveza

  • 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: While loops!
« Reply #3 on: September 18, 2009, 08:49:09 AM »
0
It looks like it would work. Since you do the count outside the while it should work alright. I'd just be concerned about finding a different ID within the "while" area and what that would do to that "while #findcnt > 0"

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 Xclio

  • Officially "The MAN"
  • Elite
  • *
  • *
  • Posts: 981
  • Activity:
    0%
  • Reputation Power: 9
  • Xclio has no influence.
  • Gender: Male
  • Respect: +56
  • Referrals: 1
    • View Profile
Re: While loops!
« Reply #4 on: September 18, 2009, 08:49:50 AM »
0
Your probably going to want to just eliminate the enemyid stuff all together, it has been pretty broken for a while know from what I have been able to tell.

Scrripty

  • Guest
Re: While loops!
« Reply #5 on: September 18, 2009, 09:07:09 AM »
0
Your probably going to want to just eliminate the enemyid stuff all together, it has been pretty broken for a while know from what I have been able to tell.

Maybe I could set the #enemyid n/a after killing a monster in the list.  That way it starts fresh with every search?  Then if it goes to <> #enemyid = n/a you KNOW it's a new monster, and that something hasn't been found in the enemyid list...  That sounds more reliable...  I've actually found that #enemyid can be helpfull for things in loops.  It's one extra check for a possible way to leave a loop when you have a lot going on.  Say like you're fighting a bunch of monsters in while loops, if I take the #enemy = n/a's out of my script it sometimes will continue through the whole script until it gets out of the "loop".  But with the || #enemyid = n/a in there... it's just an extra check to see if you're done doing what you're doing.  Even if it "persists" the actuall monster you were fighting is dead, so it will eventually leave the loop anyways.  Does that make sense?  The #enemyid is still helpfull to me.
« Last Edit: September 18, 2009, 09:14:42 AM by Scripty »

Offline Cerveza

  • 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: While loops!
« Reply #6 on: September 18, 2009, 09:14:16 AM »
0
#enemyID is a one way, you can't set it reliably.

I used it for a while with a recall lumberjack and it was too hokey to use. I would get attacked, setting #enemyID to the mongbat that was attacking me, I would recall away and at the new location it would still have that ID.

If your just looking for something thats attacking you, you can use it to see (by counter) if it's still there. Thats about all I'd use #enemyID for.
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: While loops!
« Reply #7 on: September 18, 2009, 09:21:56 AM »
0
So what's the best way to find ONE monster, attack it, kill it, THEN move on to the next? 

Offline Cerveza

  • 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: While loops!
« Reply #8 on: September 18, 2009, 09:29:52 AM »
0
If you are hunting it, then look at the "honor and attack" script.

Basically you have a list you are looking for.

If you are just wanting to know when you are attacked, then you'll have to stick with #enemyID, but I'd use a counter with it.

Code: [Select]
findItem #enemyID
if #findCnt > 0
{
set %enemyID #enemyID
while #findCnt > 0
{
do your killing stuff
}

Something along that nature. That way your not relying on the ID of the creature, but the NUMBER of those ID's that are found. Since everything has a unique ID, there should only be 1 of them ever, and when it's dead, you'll find 0 of them.
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: While loops!
« Reply #9 on: September 18, 2009, 09:54:56 AM »
0
If you are hunting it, then look at the "honor and attack" script.

Basically you have a list you are looking for.

If you are just wanting to know when you are attacked, then you'll have to stick with #enemyID, but I'd use a counter with it.

Code: [Select]
findItem #enemyID
if #findCnt > 0
{
set %enemyID #enemyID
while #findCnt > 0
{
do your killing stuff
}

Something along that nature. That way your not relying on the ID of the creature, but the NUMBER of those ID's that are found. Since everything has a unique ID, there should only be 1 of them ever, and when it's dead, you'll find 0 of them.

Gotcha.  I just haven't worked with a lot of this stuff, so I'm having to learn it as I go.  Probly should have STARTED with attacking and such but I was having so much fun with timings. :)

Offline borno

  • Newbie
  • *
  • Posts: 3
  • Activity:
    0%
  • Reputation Power: 0
  • borno has no influence.
  • Gender: Male
  • Respect: 0
  • Referrals: 1
    • View Profile
    • Uo Redemption Website
Re: While loops!
« Reply #10 on: December 11, 2009, 07:14:07 PM »
0
I know this is kind of old, but i use this to determine that the mob is still alive...

Code: [Select]
finditem #enemyid
if #findcnt = 0 || #finddist > 10
 gosub find_new_target
if #enemy id <> N/A && #enemyhits <> N/A
 gosub enemy_still_alive

I dont know if the enemy id issue is server specific in regards to osi vs runuo, but I've noticed on RunUO that even after you kill or move a significant distance away, the enemyid can stay unless something else attacks you.  We all know thats bad when you rely on enemyid.  If you look for enemyhits at the same time, however, this can tell you if the thing is still alive or in your range to attack.


Scrripty

  • Guest
Re: While loops!
« Reply #11 on: December 11, 2009, 07:24:51 PM »
0
I know this is kind of old, but i use this to determine that the mob is still alive...

Code: [Select]
finditem #enemyid
if #findcnt = 0 || #finddist > 10
 gosub find_new_target
if #enemy id <> N/A && #enemyhits <> N/A
 gosub enemy_still_alive

I dont know if the enemy id issue is server specific in regards to osi vs runuo, but I've noticed on RunUO that even after you kill or move a significant distance away, the enemyid can stay unless something else attacks you.  We all know thats bad when you rely on enemyid.  If you look for enemyhits at the same time, however, this can tell you if the thing is still alive or in your range to attack.



Thanks guys this was all really helpfull.  I'm still trying to find a way to reliably do some stuff where there's multiple monsters on the screen and you have one tame to attack them and they are all different monsters with the same id.  Kind of a pain, but #findcol and #findindex seemed to be the key here. :)

Tags: