[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  VBscript
. . -> [Subject]  bit of a bot... *Sort of*

bit of a bot... *Sort of*

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


Posted by Chronoti   USA  (27 posts)  [Biography] bio
Date Mon 22 Sep 2003 05:14 PM (UTC)
Message
Alright, here I am just working on a bit of a bot, yes i know in some muds they are illegal, etc.. but this mud, as long as you can respond to certain 'tests', then its alright, even if you are using scripts... here we go..

One thing I can't figure out is.. how would I go about doing a "list", I thought about using arrays, but lets say, like in zmud, or anything, I always did something like... When i ran into a monster, I added it to the list, when that monster died, I removed it from the list (always going by the first mob)... well lets give an example..

I add these to the list:

orc, troll, dragon, cat, chicken, dog

ok, the first being "orc", so I kill orc, once i see:

* is dead!

I delete the first item in the list, and then go on to the second one, etc... until the list is empty, they I can go on to the next room or whatever or loot all the corpses...etc.. now how would I work with this in VBScript using i guess... arrays? (Just need some functions of some sort, or a bit of a "push") Thanks for the help again!
[Go to top] top

Posted by Chronoti   USA  (27 posts)  [Biography] bio
Date Reply #1 on Mon 22 Sep 2003 05:23 PM (UTC)
Message
a friend of mine, just said something about 'collections' but out of all the stuff I've been reading, I can't find anything about that.. maybe he is right, but *shrugs* still nothing on the subject...
[Go to top] top

Posted by Ked   Russia  (524 posts)  [Biography] bio
Date Reply #2 on Tue 23 Sep 2003 04:23 AM (UTC)
Message
Collections are the most mysterious area of Vbscript, if you ask me. I think they are somehow hardcoded into the script host and can't be tempered with directly, or at least that's what the docs seem to imply. The closest thing to lists in Vbscript are dynamic arrays, but you can't use those for your purposes either, since you can't redimension an array by popping an index in the middle. What I'd do is use string operations - Left(), Right(), Instr(), etc. - and following are a couple of functions that might come usefull. Actually I'd move to Python or something that supports lists, but that's a different story :) Anyways, here it goes...



'Appends newItem to the end of strList, using the 'delim' delimiter
'doesn't perform any checks, returns the new list
'
function ListAppend(strList, newItem, delim)
 ListAppend = strList & delim & newItem
end function


'Adds newItem to the end of the list, using the 'delim' delimiter, only if newItem
'isn't already in the list. Returns the new list if the item was added, original list 
'if the item was already present
'
function ListAdd(strList, newItem, delim)
  if instr(strList, newItem) then
    ListAdd = strList
  else
    strList = strList & delim & newItem
    ListAdd = strList
 end if
end function


'Removes the removeItem from the list if it is present there,
'returns the new list if the item was removed, original list if the item wasn't
'found.
'
function ListRemove(strList, removeItem, delim)
dim startPos, endPos, resultList
startPos = instr(strList, removeItem)

 if startPos then
  endPos = instr(startPos, strList, delim)
   if endPos then
    resultList = Left(strList, startPos - 1) + Right(strList, len(strList) - endPos)
    ListRemove = resultList
  else 
    resultList = Left(strList, startPos - 1)
    ListRemove = resultList
  end if
 else
  ListRemove = strList
 end if
end function


'Example of usage:

dim mobList
mobList = "orc_dragon_cat"

sub TestLists(name, output, wildcs)
  'Add "dog" to the mobList
  mobList =  ListAdd(mobList, "dog", "_") 
  world.Note mobList
  'Remove "cat" from the mobList
  mobList = ListRemove(mobList, "cat", "_")
  world.Note mobList
  'Add "cat" back to the list
  mobList = ListAdd(mobList, "cat", "_")
  world.Note mobList
  'Remove "urchin" from the list, it's not there so the list isn't changed
  mobList = ListRemove(mobList, "urchin", "_")
  world.Note mobList
  'Appends another "cat" to the end of the list
  mobList = ListAppend(mobList, "cat", "_")
  world.Note mobList
end sub



These took about 15 minutes to write, and although I tested them (using the TestLists sub above) there might be some quirks left.
[Go to top] top

Posted by Nick Gammon   Australia  (22,982 posts)  [Biography] bio   Forum Administrator
Date Reply #3 on Tue 23 Sep 2003 05:11 AM (UTC)

Amended on Tue 23 Sep 2003 05:14 AM (UTC) by Nick Gammon

Message
A quick way of managing things like that would be to store them in a single variable, separated by commas, and use Split to get at the individual items.

Here is an example you can type into the Immediate window to get the idea ...




v = "orc, troll, dragon, cat, chicken, dog"

mylist = split (v, ",")

for each m in mylist
  Note trim (m)
next


Output orc troll dragon cat chicken dog



Now inside the for loop you could test to see if a word was there (eg. "orc") and if so you know he is a known mob, if not you could add him.

eg.

v = v & ", gorilla"


Another approach is to use Join to turn an array into a variable. For instance, adding onto the earlier example:




k = join (mylist, ",")
Note k

Output orc, troll, dragon, cat, chicken, dog


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Chronoti   USA  (27 posts)  [Biography] bio
Date Reply #4 on Tue 23 Sep 2003 05:51 PM (UTC)
Message
Ok cool, Thanks both of you very much!! Alright, another question... sort of on the same subject I suppose, is there a way to create custom "windows"? Sort of like other mud clients, where you can have things displayed in there, or buttons or anything like that? thanks for the help again!
[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Reply #5 on Tue 23 Sep 2003 06:00 PM (UTC)
Message
No

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] top

Posted by Poromenos   Greece  (1,037 posts)  [Biography] bio
Date Reply #6 on Tue 23 Sep 2003 06:01 PM (UTC)
Message
You can have a notepad window with ASCII text though...

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
[Go to top] top

Posted by Nick Gammon   Australia  (22,982 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Tue 23 Sep 2003 08:23 PM (UTC)
Message
You can if you use VB and the COM interface. I did an example a little while back of a plugin that showed HP, Mana, Movement in three gauges in a separate window.

If you have access to VB (the full version) anything is possible.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Chronoti   USA  (27 posts)  [Biography] bio
Date Reply #8 on Wed 24 Sep 2003 04:05 AM (UTC)
Message
*shakes his fist* You are trying to make me learn VB, I think everyone is plotting to make me learn vb... You mean mean... semi-mean people... *hugs you all* i love you bastards...
[Go to top] 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.


17,057 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]