Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ General ➜ Using split, lbound and ubound

Using split, lbound and ubound

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by David B   USA  (80 posts)  Bio
Date Mon 01 Sep 2003 03:11 AM (UTC)
Message
Its been a while since I've use the split command.
My trigger matches on this:
Text:
You knocked a powerful bebilith out cold!
Matchon:
You knock * out cold!


Currently I have it just attacking certain mobs. What I'd like to do is set it up so that it will attack all goblins. There are many different types of goblins. The one that you DON'T want to attack is the goblin healer... Now Knocking them out isn't considered an attack unless it fails, and I don't fail when it comes to knocking things out the same size as me(there are tiny, small, medium, large, huge, and giant sized mobs). Now, Once I knock them out, I don't want to backstab them because they're really strong for their level... Their maladictions last forever and land easily.

Now as I continue to explain this, I think of a different way to do this. I realize I could do it slightly differently. Instead of matching on the "sap" I could match it on the hunt trigger:
Text
A powerful bebilith is south from here.
match on:
A * is * from here.

What I'd like to do is split the first wild card, and if any of that array has healer in it then Ignore it, and hunt the next goblin... 2.goblin... 3.goblin.... 4.goblin...

Not sure how to do that exactly... Could I perhaps get a hand with this?

My code(with a LOT of Nicks help) to fame:

sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Mon 01 Sep 2003 08:01 AM (UTC)
Message
Can you post a sample line with the goblins in it?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by David B   USA  (80 posts)  Bio
Date Reply #2 on Mon 01 Sep 2003 06:04 PM (UTC)
Message
A sample line of several different goblins:

A goblin janitor is east from here.
An elite goblin guard is north from here.
A large goblin is north from here.
A goblin scout is up from here.
A goblin knight is east from here.
And the one I REALLY want to avoid:
A goblin healer is east from here.

I also want to be able to do the same thing if I hunt a goblin, and a goblin healer is here.

A goblin healer is here.

My code(with a LOT of Nicks help) to fame:

sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
Top

Posted by Ked   Russia  (524 posts)  Bio
Date Reply #3 on Mon 01 Sep 2003 10:50 PM (UTC)
Message
The following should do:


<triggers>
<trigger
 enabled="y"
 regexp="y"
 match="[A|An] (goblin \w+) is (east|west|south|north|northwest|northeast|southwest|southeast|up|down|in|out) from here\."
 script="HuntGoblin"
 sequence="100"
></trigger>

<trigger
 enabled="y"
 regexp="y"
 match="A (goblin healer) is here\."
 script="HuntGoblin"
 sequence="100"
></trigger>


And the script in vbs


sub HuntGoblin (name, output, wildcs)
 dim tempArray
 tempArray = split(wildcs(1), " ")
 select case tempArray(1)
  case "healer"
    exit sub
  case else
    world.send wildcs(2)     'go in goblin's direction
    world.send "attack goblin"
 end select
end sub


An alternative way of doing it doesn't involve using split() in script. You'd need to fix the triggers up:


<triggers>
<trigger
 enabled="y"
 regexp="y"
 match="[A|An] goblin (\w+) is (east|west|south|north|northwest|northeast|southwest|southeast|up|down|in|out) from here\."
 script="HuntGoblin"
 sequence="100"
></trigger>

<trigger
 enabled="y"
 regexp="y"
 match="A goblin (healer) is here\."
 script="HuntGoblin"
 sequence="100"
></trigger>
</triggers>


Now your sub would look like:


sub HuntGoblin (name, output, wildcs)
 select case wildcs(1)
  case "healer"
   exit sub
  case else
   world.send wildcs(2)       'go in goblin's direction
   world.send "attack goblin"
 end select
end sub


which is somewhat simpler. Of course, you could play around with the triggers some more, to perhaps make one trigger out of two, but if it works - why bother? :P
Top

Posted by David B   USA  (80 posts)  Bio
Date Reply #4 on Tue 02 Sep 2003 12:37 AM (UTC)
Message
Ok, that fine would work great if they were static, but they move around. that means they're always the first mob in the room... That in mind, I need to beable to attack 2.goblin.

My code(with a LOT of Nicks help) to fame:

sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
Top

Posted by Ked   Russia  (524 posts)  Bio
Date Reply #5 on Tue 02 Sep 2003 06:48 AM (UTC)
Message
Hmm, after a second look at the sample lines I noticed that the above won't actually work, since the words in the first wildcard are not always in the order 'goblin <type>'. So here's the amended version (again without split()'ing):


<triggers>
<trigger
 enabled="y"
 regexp="y"
 match="[A|An] (goblin \w+|\w+ goblin) is (east|west|south|north|northwest|northeast|southwest|southeast|up|down|in|out) from here\."
 script="HuntGoblin"
 sequence="100"
></trigger>

<trigger
 enabled="y"
 regexp="y"
 match="A (goblin \w+|\w+ goblin) is here\."
 script="HuntGoblin"
 sequence="100"
></trigger>
</triggers>


And the sub changes to use InStr(), as we don't have a way of predicting where the type of goblin will appear in the wildcard string:


sub HuntGoblin (name, output, wildcs)
dim goblinHealer
goblinHealer = instr(wildcs(1), "healer")

 if goblinHealer then
   exit sub
 else
   world.send wildcs(2)
   world.send "attack goblin"
 end if
end sub


Also, I don't exactly understand what you mean; what's a '2.goblin'? And what difference does it make in what order the mobs are in a room? I suspect we are talking about some specifics of hunting in your MUD, and as I am not aware of those you need to explain this part of a problem in a bit more detail.

Top

Posted by Ked   Russia  (524 posts)  Bio
Date Reply #6 on Tue 02 Sep 2003 07:02 AM (UTC)
Message
Doh! Think first, do later... I just realized that the second trigger ('the goblin is here.' thing) will cause an array out of bounds exception as soon as it fires. So we'll amend the sub again:


sub HuntGoblin (name, output, wildcs)
dim goblinHealer
goblinHealer = instr(wildcs(1), "healer")

 if goblinHealer then
   exit sub
 else
  if ubound(wildcs) > 1 then
   world.send wildcs(2)
  end if
   world.send "attack goblin"
 end if
end sub


Also, I think I understood what you meant. The healer is always the first in the group of goblins, so 'attack goblin' would attack the healer goblin? Then to attack any goblin other than the healer you'd need to figure out how to attack a specific goblin in the room. I can't help you here as I am not familiar with how things work in your MUD, so again - give more specifics.
Top

Posted by David B   USA  (80 posts)  Bio
Date Reply #7 on Tue 02 Sep 2003 06:22 PM (UTC)
Message
I'm terribly sorry to waste your time with this, I've come to the conclusion that it is just too difficult to accomplish... I appreciate your assistance.

My code(with a LOT of Nicks help) to fame:

sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
Top

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #8 on Tue 02 Sep 2003 07:05 PM (UTC)
Message
Compared to some things we have coded, this is not difficult at all, just hard to do without actually being there to work with the actual input. It would help to have specific examples of the rooms, not just a line here or there. It may for instance be possible to trigger on the title and color of the room, have that clear an array of available goblins, then start capturing them. If the first one captured was a healer, it would be skipped or marked in the array to prevent you from attacking it. Then you could make an alias like:

kg *

Which took a number. If you pick a number corresponding to the healer, it would simply be ignored. But to do this requires knowing more about how your rooms are displayed than we now know. It is definitely not impossible though.
Top

Posted by David B   USA  (80 posts)  Bio
Date Reply #9 on Tue 02 Sep 2003 11:40 PM (UTC)

Amended on Wed 03 Sep 2003 07:18 PM (UTC) by David B

Message
What makes this too difficult to accomplish is several factors. 1. Healers are just totally evil. 2. All goblins autoassist other goblins(meaning even if I didn't attack a healer it'd still attack me). 2. The only way to do something like this would be to sap(knock out) the healer then attack. That might be easier to do... I'll post again in a little while with various rooms. I think this would be a helpful script for anyone who wants to script an area that has mobs you want to avoid...

My code(with a LOT of Nicks help) to fame:

sub OnAutoCombo (TriggerName, TriggerLine, arrWildCards)
dim AutoCombo
AutoCombo = split (arrWildCards (1))
Dim i, attack
for i=lbound (AutoCombo ) to ubound (AutoCombo )
Select Case AutoCombo (i)
case "rp" attack = "punch right"
case "lp" attack = "punch left"
case "s" attack = "sweep"
case "r" attack = "roundhouse"
case else attack = "" ' unknown attack type
End Select
if i = ubound (AutoCombo ) then
world.send "throw " + world.getvariable ("attacker") + " down"
else
world.send attack + " " + world.GetVariable ("attacker")
end if
next
end sub
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


28,944 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.