List Creation, Management and Checking against them.

Posted by Boca on Thu 09 Aug 2001 12:58 AM — 4 posts, 17,321 views.

#0

In ZMUD they had an "#additem" command to add an item to a list, a "#delitem" to remove an item, and an "ismember" function which let you check against a list. Does MushClient support anything like this?


I need to do 3 things:
1. Create and manage a group list.


When I join or re-follow in a group, I want to clear the group list and re-create it. To do this I would input the "group" command which gives me this type of info:

You are a member of group say DL for atk.
It consists of :
[ W 50 ] Ohio [Not present ] (Head of group)
[ M 50 ] Baud [100.00 % XP-share]
[ M 50 ] Belrab [Not present ]
[ C 50 ] Flake [100.00 % XP-share] (AFK)
[ M 50 ] Thrilla [100.00 % XP-share] (AFK)
[ M 50 ] LabKeeper [100.00 % XP-share] (AFK)
[ M 50 ] Cleopatra [100.00 % XP-share] (AFK)
[ C 50 ] Thingol [100.00 % XP-share] (AFK)
[ C 50 ] Solace [100.00 % XP-share]
[ M 50 ] Bursar [100.00 % XP-share] (AFK)
[ T 50 ] Telstar [100.00 % XP-share] (AFK)
[ C 50 ] Murky [100.00 % XP-share] (AFK)
[ C 50 ] Buggs [100.00 % XP-share] (AFK)
[ M 50 ] Djax [100.00 % XP-share] (AFK)
[ M 50 ] Erin [100.00 % XP-share] (AFK)
[ C 50 ] Galadriel [100.00 % XP-share] (AFK)
[ C 50 ] Topgun [100.00 % XP-share] (AFK)
[ C 50 ] Iny [100.00 % XP-share] (AFK)
[ M 50 ] Bimbo [100.00 % XP-share] (AFK)
[ C 50 ] Lizy [100.00 % XP-share] (AFK)
[ M 50 ] Razor [100.00 % XP-share] (AFK)
[ M 50 ] Duke [100.00 % XP-share] (AFK)

Present : 20 Total : 22

and use it to pick up each player name here.


To add or delete players, these are samples of my trigger lines:

Toda now follows Ohio.
Murky stops following Ohio.


2. Create a list of spell names (these will be the alias names for the spells) that I will cast for group members.

3. Finally, if the requesting player is on the group list, and the requested spell is on the spell list, I will cast the requested spellusing the alais.

an example would be: Toda asks you 'heal'. If Toda is on the group list and heal is on the spell list, I want to send heal toda to the mud. (Heal is the alias for cast 'heal').

Can this be done?

Thanks,
Boca
Australia Forum Administrator #1
I think I can do that easily enough with a bit of scripting. Which language do you prefer it to be in? (VBscript, Jscript, PerlScript?)
#2
VBScript please :)
Boca
Australia Forum Administrator #3
OK, here are four subs/functions in VBscript to do that.

The comments before each one explain how to use them.

The lists are kept in MUSHclient variables, so they will persist (if you save the world file) between MUSHclient sessions.


'
'  See if memberName is in listName
'
'  eg.  if IsMember ("spell_list", "fiery blast") then
'          ... do something ...
'
'

Function IsMember (listName, memberName)
dim ListContents
dim theList
dim WantedMember
dim i

' Default to not found
IsMember = False

' Fix up member to remove surrounding spaces and make lower case
WantedMember = Trim (LCase (memberName))

' Can't find blank items
If WantedMember = "" Then
  Exit Function
End If

' Get list
ListContents = World.GetVariable (listName)

' If no list, the member can't be in it
If IsEmpty (ListContents) or IsNull (ListContents) then
  Exit Function
End If

' Split list at commas
theList = split (ListContents, ",")

' Loop through list, seeing if wanted member is in it
If Not IsEmpty (theList) then
  For i = lbound (theList) to ubound (theList)
  If theList (i) = WantedMember then
    IsMember = True
    Exit Function
  End If      ' end of found it
  Next        ' end of loop
End If        ' end of any items in list

End Function

'
'  Add memberName to listName
'
'  eg.  AddItem  "spell_list", "fiery blast"
'
'  Note - it is up to you to test if the item is already
'         in the list (using IsMember) or it will be added 
'         twice.
'
'

Sub AddItem (listName, memberName)
dim ListContents
dim theList
dim NewMember
dim i

' Get existing list
ListContents = World.GetVariable (listName)

' Make sure new member is lower case with no spaces around it
NewMember = Trim (LCase (memberName))

' Don't add blank items
If NewMember = "" Then
   Exit Sub
End If

' Need comma after previous member, if any
If ListContents <> "" Then
  ListContents = ListContents & ","
End If
 
' Add new item
ListContents = ListContents & NewMember

World.SetVariable listName, ListContents

End Sub

'
'  Delete memberName from listName
'
'  eg. DeleteItem "spell_list", "fiery blast"
'
'

Sub DeleteItem (listName, memberName)
dim ListContents
dim theList
dim WantedMember
dim i
dim NewContents

' Fix up member to remove surrounding spaces and make lower case
WantedMember = Trim (LCase (memberName))

' Can't delete blank items
If WantedMember = "" Then
  Exit Sub
End If

' Get list
ListContents = World.GetVariable (listName)

' If no list, the member can't be in it
If IsEmpty (ListContents) or IsNull (ListContents) then
  Exit Sub
End If

' Split list at commas
theList = split (ListContents, ",")

' New contents are empty now
NewContents = ""

' Loop through list, copying across all but delete item
If Not IsEmpty (theList) then
  For i = lbound (theList) to ubound (theList)
  If theList (i) <> WantedMember then
    If NewContents <> "" Then
       NewContents = NewContents & ","
    End If
  NewContents = NewContents & theList (i)
  End If      ' end of not deleted item
  Next        ' end of loop
End If        ' end of any items in list

' Store new list contents
World.SetVariable listName, NewContents

End Sub


'
'  Delete the entire list called listName
'
'  eg. DeleteList "spell_list"
'
'
Sub DeleteList (listName)

World.DeleteVariable listName

End Sub