Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
lsoth
Newbie


Joined: 28 Jun 2010
Posts: 7

PostPosted: Mon Jun 28, 2010 2:40 am   

Delaying multiple commands in a trigger for autofight class
 
Hi, this is what I am trying to accomplish. Everything works fine except for the last couple of commands.

01. Raise an event when a mob is dead. --> works
02. Look --> works
03. If no mobs are in the room then I would like to scan. --> works
04. If I scan and don't see any mobs then I stay in room by default right now. I would then like to walk in a random direction based on the string list that I captured when I enterered into the room. I find that sometimes in the middle of battle I will try to move into another room. Here is the code in the onDeath event.
05. If I do find mobs when I scan then I will travel how many rooms in that direction to kill the mob. --> works

onDeath Event
Code:

// fightmode = autofight
// fighting = in the middle of fight

#IF (@fightMode = 1)
{
  // enable the fighting classes
  #T+ Fight
  #T+ FightWalk
  #T+ FightExits
 
  scannedMobs = 0;      // set the found mobs back to 0

  // delay looking by 10 seconds
  // 10 seconds seem to work well since most fights
  // I am backed up by 1-2 commands after mob is dead.
  // This will also give my other char's time to cast
  // a spell/skill before I resume fight.
  #ALARM {+1} {#RESUME lookformobs}
  #ALARM "lookformobs" {+9} {look}
  #SUSPEND lookformobs
 
  // delay by 15 seconds after mob death to scan
  // I would rather not use #WAIT but cannot find
  // a way for the #ALARM to work.  This works
  // 99% of the time correctly.
  #wait 15000

  // if i'm not in a fight then scan for mobiles
  #if (@fighting = 0)
  {
    scan
  }
 
  // delay by 20 seconds after mob death to scan
  // If i didn't find any mobs then this var should be set
  // at 0.  I need to pick a exit to move that is in this
  // string list.  ** this has problems ** in that it will
  // fire in the middle of the battle sometimes.
  #wait 20000
  #if (@scannedMobs = 0)
  {
    #exec %item( @exitdir, %random( 0, %numitems( @exitdir)))
  }
}
{
  save  // just issue save command
}


Here is the trigger when I enter into a room to capture the available exits.
Code:

^~[Exits: (%w) (%w) (%w) (%w) (%w) (%w)]$

Value

// loop through array and delete all items
#loop 1,%numitems(@exitdir) {#delitem exitdir %item(@exitdir, 1)}

// add items back to array
#ADDITEM exitdir %1
#ADDITEM exitdir %2
#ADDITEM exitdir %3
#ADDITEM exitdir %4
#ADDITEM exitdir %5
#ADDITEM exitdir %6

#wait 5000
#if (@fighting = 0)
{ #exec %item( @exitdir, %random( 0, %numitems( @exitdir))) }



Trigger when I scan after a fight.
Code:

// check to see if i'm in fight bot mode
#IF (@fightmode = 1)
{
  numdirection = %1        // assing how many rooms away mob is
  #LOO @numdirection {%2}  // loop through array and travel direction
  numdirection = 0         // reset value back to 0
  #T- FightWalk            // disable the FightWalk class
  #T- FightExits           // disable the FightExits Class
  scannedMobs = 1;

}



Thanks.[/code]
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Jun 28, 2010 4:31 am   
 
First question: is @exitdir a stringlist of directions which can be used as commands to the mud? That's what it looks like. If so, then don't use #EXEC, use #SEND instead. #EXEC is very slow, because it doesn't compile the command until execution time. In general, you should use #SEND, #CALL, or some other command instead of #EXEC.
Code:
#send %item( @exitdir, %random( 0, %numitems( @exitdir)))

Next: there's no reason to #LOOP through your @exitdir to delete all the items--just set @exitdir to {} to clear it.
Code:
exitdir = {}


Now, to the problem you are having. Here is part of your code:
Code:


  // if i'm not in a fight then scan for mobiles
  #if (@fighting = 0)
  {
    scan
  }
 
  // delay by 20 seconds after mob death to scan
  // If i didn't find any mobs then this var should be set
  // at 0.  I need to pick a exit to move that is in this
  // string list.  ** this has problems ** in that it will
  // fire in the middle of the battle sometimes.
  #wait 20000
  #if (@scannedMobs = 0)
  {
    #exec %item( @exitdir, %random( 0, %numitems( @exitdir)))
  }

Here, you test whether @fighting = 0. But if @fighting = 1, the event still goes on to the next part, where it checks whether @scannedmobs = 0. That whole thing should be within the first if statement, so that it doesn't bother checking @scannedmobs if you are fighting. Like so:
Code:

  // if i'm not in a fight then scan for mobiles
  #if (@fighting = 0)
  {
    scan

    // delay by 20 seconds after mob death to scan
    // If i didn't find any mobs then this var should be set
    // at 0.  I need to pick a exit to move that is in this
    // string list.  ** this has problems ** in that it will
    // fire in the middle of the battle sometimes.
    #wait 20000
    #if (@scannedMobs = 0)
    {
      #exec %item( @exitdir, %random( 0, %numitems( @exitdir)))
    }
  }

Basically, the problem stems from the fact that you are doing the lookformobs as an alarm. It would be very easy for you to end up with several of these alarms running at the same time, so you could end up having @scannedMobs not equal to zero at this point in the code, even though you are currently fighting. The above code will solve that little problem. Ultimately, I would recommend rethinking the whole thing. Using the alarms as you are looks pretty kludgy and prone to problems.
Reply with quote
robecks
Beginner


Joined: 22 Jun 2010
Posts: 17

PostPosted: Mon Jun 28, 2010 4:52 am   
 
would the best way to be just change it to a real alarm so that multiple threads are not created?
Code:

// if i'm not in a fight then scan for mobiles
  #if (@fighting = 0)
  {
    scan

    // delay by 20 seconds after mob death to scan
    // If i didn't find any mobs then this var should be set
    // at 0.  I need to pick a exit to move that is in this
    // string list.  ** this has problems ** in that it will
    // fire in the middle of the battle sometimes.
#alarm "exitdir" +20 {
    #if (@scannedMobs = 0)
    {
      #exec %item( @exitdir, %random( 0, %numitems( @exitdir)))
    }
  }
}
Reply with quote
lsoth
Newbie


Joined: 28 Jun 2010
Posts: 7

PostPosted: Mon Jun 28, 2010 5:41 am   
 
Thanks guys. I've taken some of the suggestions and already implemented them such as the #send and to empty out the array. I still believe there is probably an easier way to accomplish this. I can have it kill, look(kill if mobs in there) if not then scan and walk to the mob and kill np at all. When I throw in the part where if I dont find any mobs after scanning I need to move in another room is basically the big problem here.

I could stop there, but I want to learn more and better techniques. I've tried the #if inside the alarm, but that didn't compile for some reason.

Once I get this ironed out I will go back and re-think the whole strategy to try and make it more efficient hopefully.

Thanks
Reply with quote
lsoth
Newbie


Joined: 28 Jun 2010
Posts: 7

PostPosted: Mon Jun 28, 2010 5:03 pm   
 
After looking at the script and re-writing some of it, it's condensed down now. The only trouble i'm having is sometimes when it is suppose to do this command.

Code:

#send %item(@exitdir, %random(0, %numitems(@exitdir)))

Data is in the variable @exitdir. When it goes to fire this command probably 1/10 times it will just send a blank line (like hitting the enter key). Other than that it seems to be working pretty well. I did take the sample bot in the finished scripts and get an idea of how that was done and modify that one to my needs.

Thanks[/code]
Reply with quote
Arminas
Wizard


Joined: 11 Jul 2002
Posts: 1265
Location: USA

PostPosted: Mon Jun 28, 2010 5:16 pm   
 
It looks like then that your @exitdir variable could contain a null value. Before the send command try adding #delitem exitdir "".
Code:
#delitem exitdir ""
#send %item(@exitdir, %random(0, %numitems(@exitdir)))
_________________
Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Reply with quote
lsoth
Newbie


Joined: 28 Jun 2010
Posts: 7

PostPosted: Mon Jun 28, 2010 5:44 pm   
 
Arminas wrote:
It looks like then that your @exitdir variable could contain a null value. Before the send command try adding #delitem exitdir "".
Code:
#delitem exitdir ""
#send %item(@exitdir, %random(0, %numitems(@exitdir)))


Will give it a shot and report back.

Thanks
Reply with quote
lsoth
Newbie


Joined: 28 Jun 2010
Posts: 7

PostPosted: Mon Jun 28, 2010 5:54 pm   
 
Looks like it could be within that command. It still does it, but when I put in <east> and comment out those two lines i've not had any trouble with it for the past 10 minutes or so. I'll keep testing.
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Jun 28, 2010 6:06 pm   
 
Even better, don't add the nulls into @exitdir to begin with. When adding the values to @exitdir, do this:
Code:
#if (%1) {#ADDITEM exitdir %1}

etc. That way it won't add it if %1 is null.
Reply with quote
lsoth
Newbie


Joined: 28 Jun 2010
Posts: 7

PostPosted: Mon Jun 28, 2010 6:16 pm   
 
Rahab wrote:
Even better, don't add the nulls into @exitdir to begin with. When adding the values to @exitdir, do this:
Code:
#if (%1) {#ADDITEM exitdir %1}

etc. That way it won't add it if %1 is null.


That makes logical sense. Changed and testing :)

Thanks.
Reply with quote
lsoth
Newbie


Joined: 28 Jun 2010
Posts: 7

PostPosted: Tue Jun 29, 2010 3:04 pm   
 
So far so good. Thanks everyone!
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net