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 ➜ Jscript ➜ A bit more difficult script this time i think...

A bit more difficult script this time i think...

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


Posted by NC99   USA  (17 posts)  Bio
Date Fri 03 Jan 2003 08:23 AM (UTC)
Message
OK.. first off thanks Nick and Demon for helping me with that simple script. :P This one i think is a bit more complex.. Basically.. im looking for a way to keep a 'log' of the last 20 says on my Clan Channel. Is there anyway i can make a script so when i type in 'Showclan' it brings up a list of the last 20 clan talks?

Here is some example output from my MUD:

[CLAN]: <player> says, 'MUSHClient owns MudMaster.'.
[CLAN]: <player> says, 'yeah, Nick is uber.'.

:)

Ideas?

thanks again in advance..

Im a minster of death...Praying for war!

NC
Top

Posted by Meerclar   USA  (733 posts)  Bio
Date Reply #1 on Fri 03 Jan 2003 06:36 PM (UTC)
Message
Are you doing this as a player or as an imm project for potential log use? As a player you could send all clan convo to a text file and have a call function to read back the last however many lines. As an imm function to see whats been said while you were away, Id recommend expanding replay to cover the last X lines of any channel with a level check for immortal use restrictions.

Meerclar - Lord of Cats
Coder, Builder, and Tormenter of Mortals
Stormbringer: Rebirth
storm-bringer.org:4500
www.storm-bringer.org
Top

Posted by Shadowfyr   USA  (1,791 posts)  Bio
Date Reply #2 on Fri 03 Jan 2003 07:28 PM (UTC)
Message
Your mud doesn't have a 'last clan' command? Hmm..
sub ClanChan(tname, output, wilds)
  'First lets get the number of lines we are keeping.
  dim Keep
  Keep = world.getvariable("ClanKeep")
  'Retrieve last traffic.
  dim Buffer
  Buffer = split(world.getvariable("ClanChan"),",")
  'Find a blank spot, if there is one.
  dim count, fnd
  fnd = -1
  for count = 0 to Keep
    if Buffer(count) = "-1" or Buffer(count) = "Empty" then
      fnd = count
      exit for
    end if
  next
  if fnd = -1 then
    'We already have the maximum, so shift them all and add the new on into
    'the last possition.
    for count = 1 to Keep
      Buffer(count - 1) = Buffer(count)
    next
    'Note: We use 'now' to get the time and date to time stamp it. ;)
    Buffer(Keep) = now & " " & wilds(1)
  else
    'This is if we found a blank.
    Buffer(fnd) = now & " " & wilds(1)
  end if
  world.setvariable "ClanChan", join(Buffer,",")
end sub

sub SetClanBuffer (aname, output, wilds)
  dim Keep
  Keep = wilds(1)
  if isnumeric(Keep) then
    if Keep < 2 then
      world.note "Clan buffer cannot be less than two lines."
    else
      'Since arrays start at 0, we need one less than our setting or 10 lines would end up as 11.
      Keep = Keep - 1
    end if
    'Retrieve last traffic.
    dim Buffer
    Buffer = split(world.getvariable("ClanChan"),",")
    if Keep > ubound(Buffer) then
      'We will need a new array, since split does not create one you can change the size of. :p
      dim NewAr(Keep)
      dim count
      'Put existing data in the new one.
      for count = 0 to unbound(Buffer)
        NewAr(count) = Buffer(count)
      next
      'Fill the rest.
      for count = ubound(Buffer) + 1 to Keep
        NewAr(count) = "-1"
      next
      world.setvariable "ClanChan", join(NewAr,",")
    else
      if Keep = ubound(Buffer) then
        world.note "New size for clan buffer is the same as last."
        world.note "Command ignored."
        exit sub
      end if
      'We will need a new array, since split does not create one you can change the size of. :p
      dim NewAr(Keep)        
      dim count, oldlen, strt
      oldlen = ubound(Buffer)
      strt = oldlen - Keep
      'Store what we can.
      for count =  strt to oldlen
        NewAr(count - strt) = Buffer(count)
      next
      world.setvariable "ClanChan", join(NewAr,",")
    end if
    world.note Keep & "lines of clan messages will now be stored."
  else
    world.note "Must be a number! >" & Keep & "<"
  end if
end sub

sub ShowClan(aname, output, wilds)
  dim Buffer, count
  Buffer = split(world.getvariable("ClanChan"),",")
  for count = 0 to ubound(Buffer)
    if Buffer(count) <> "-1" then
      world.note "[CLAN]: " & Buffer(count)
    end if
  next
end sub

Now..

Trigger - 
  Match: '[CLAN]: *'
  Name: ClanChan
  Script: ClanChan

Alias 1 -
  Match: Showclan
  Name: Showclan
  Script: Showclan

Alias 2 -
  Match: Clanset *
  Name: Clanset
  Script: SetClanBuffer

I would also suggest that this be in a plugin and you add the following:

sub OnPluginInstall
  dim Keep
  Keep = world.getvariable("Keep")
  if isnumber(Keep) and Keep > 0 then
    exit sub
  end if
  world.setvariable "Keep" , "10"
  world.setvariable "ClanChan", "Empty,-1,-1,-1,-1,-1,-1,-1,-1,-1"
end sub

This is untested, but it should let you track your clan channel with the last 10 lines by default, but also allow you to change the number of lines to be anything you want (as long as it is at least 2 lines).
Top

Posted by NC99   USA  (17 posts)  Bio
Date Reply #3 on Sat 04 Jan 2003 07:52 AM (UTC)
Message
OK.. the first part of the script works fine.. it logs the clan talk into the variable.. the second part is getting an error..

when it reaches this line:
dim NewAr(Keep)

it says it is looking for an expected integer constant. :/

Im a minster of death...Praying for war!

NC
Top

Posted by NC99   USA  (17 posts)  Bio
Date Reply #4 on Sat 04 Jan 2003 07:54 AM (UTC)
Message
another thing i just noticed.. all the clan says are logged by me.. even when different people talk.. is there no way to log it down to what each person says?

Im a minster of death...Praying for war!

NC
Top

Posted by Shadowfyr   USA  (1,791 posts)  Bio
Date Reply #5 on Sat 04 Jan 2003 06:41 PM (UTC)
Message
Heh... I did say that it wasn't tested. ;) lol
Lets try this again..


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE muclient>
<!-- Saved on Saturday, January 04, 2003, 11:44 AM -->
<!-- MuClient version 3.32 -->

<!-- Plugin "ClanChan" generated by Plugin Wizard -->

<muclient>
<plugin
   name="ClanChan"
   author="kagehi"
   id="47c87a3b66afba3264f8fc23"
   language="VBscript"
   save_state="y"
   date_written="2003-01-04 11:43:32"
   requires="3.32"
   version="1.0"
   >

</plugin>


<!--  Get our standard constants -->

<include name="constants.vbs"/>

<!--  Triggers  -->

<triggers>
  <trigger
   enabled="y"
   match="[CLAN]: *"
   name="ClanChan"
   script="ClanChan"
   sequence="100"
  >
  </trigger>
</triggers>

<!--  Aliases  -->

<aliases>
  <alias
   name="Showclan"
   script="Showclan"
   match="Showclan"
   enabled="y"
  >
  </alias>
  <alias
   name="Clanset"
   script="SetClanBuffer"
   match="Clanset *"
   enabled="y"
  >
  </alias>
</aliases>

<!--  Script  -->


<script>
<![CDATA[

sub ClanChan(tname, output, wilds)
  'First lets get the number of lines we are keeping.
  dim Keep
  Keep = world.getvariable("Keep")
  'Retrieve last traffic.
  dim Buffer
  Buffer = split(world.getvariable("ClanChan"),"^`")
  'Find a blank spot, if there is one.
  dim count, fnd
  fnd = -1
  for count = 0 to ubound(Buffer)
    if Buffer(count) = "-1" or Buffer(count) = "Empty" then
      fnd = count
      exit for
    end if
  next
  if fnd = -1 then
    'We already have the maximum, so shift them all and add the new on into
    'the last possition.
    for count = 1 to ubound(Buffer)
      Buffer(count - 1) = Buffer(count)
    next
    'Note: We use 'now' to get the time and date to time stamp it. ;)
    Buffer(ubound(Buffer)) = now & " [CLAN]: " & wilds(1)
  else
    'This is if we found a blank.
    Buffer(fnd) = now & " [CLAN]: " & wilds(1)
  end if
  world.setvariable "ClanChan", join(Buffer,"^`")
end sub

sub SetClanBuffer (aname, output, wilds)
  'We will need a new array for later, since split does not create one you can change the size of. :p
  dim Keep
  Keep = wilds(1)
  if isnumeric(Keep) then
    if Keep < 2 then
      world.note "Clan buffer cannot be less than two lines."
    else
      'Since arrays start at 0, we need one less than our setting or 10 lines would end up as 11.
      Keep = Keep - 1
      redim NewAr(Keep)
    end if
    'Retrieve last traffic.
    dim Buffer
    Buffer = split(world.getvariable("ClanChan"),"^`")
    if Keep > ubound(Buffer) then
      dim count
      'Put existing data in the new one.
      for count = 0 to ubound(Buffer)
        NewAr(count) = Buffer(count)
      next
      'Fill the rest.
      for count = ubound(Buffer) + 1 to Keep
        NewAr(count) = "-1"
      next
      world.setvariable "ClanChan", join(NewAr,"^`")
    else
      if Keep = ubound(Buffer) then
        world.note "New size for clan buffer is the same as last."
        world.note "Command ignored."
        exit sub
      end if
      dim count2, oldlen, strt
      oldlen = ubound(Buffer)
      strt = oldlen - Keep
      'Store what we can.
      for count2 =  strt to oldlen
        NewAr(count2 - strt) = Buffer(count2)
      next
      world.setvariable "ClanChan", join(NewAr,"^`")
    end if
    world.note Keep + 1 & " lines of clan messages will now be stored."
  else
    world.note "Must be a number! >" & Keep & "<"
  end if
  world.setvariable "Keep", Keep
end sub

sub ShowClan(aname, output, wilds)
  dim Buffer, count
  Buffer = split(world.getvariable("ClanChan"),"^`")
  for count = 0 to ubound(Buffer)
    if Buffer(count) <> "-1" then
      world.note Buffer(count)
    end if
  next
end sub

sub OnPluginInstall
  dim Keep
  Keep = world.getvariable("Keep")
  if isnumeric(Keep) and Keep > 0 then
    exit sub
  end if
  world.setvariable "Keep", "10"
  world.setvariable "ClanChan", "Empty^`-1^`-1^`-1^`-1^`-1^`-1^`-1^`-1^`-1"
end sub
]]>
</script>
</muclient>


A number of bugs I failed to note. Here is a list:

All -
Replaced ',' with '^`' to seperate lines. Lines with ',' in them would have produced nasty results otherwise. A combination of '^`' is probably never going to come up by accident in channel traffic.

ClanChan -
1. Was using 'ClanKeep' instead of 'Keep' like everyplace else. This meant it never saved more than one line at a time.
2. Discovered another bug when I fixed this and decided to use the size of the existing channel list to do things instead.
3. Changed the time stamp to be 'time [CLAN]: message'.

SetClanBuffer -
1. Was using 'dim NewAr(Keep)', only you can 'redim' arrays using a variable, but not 'dim' them. :p
2. Was trying to define the NewAr in two places. You can do this using redim, but it didn't make much sense to do it twice anyway, so moved it.
3. Couldn't figure out why the storage size of the clan list was changing, but Keep stayed at 10. Decided maybe I should have actually stored 'Keep' someplace. ;) Oops! lol

Showclan -
1. Was adding the CLAN bit before the time stamp, which looked odd imho. It wouldn't work in this spot anyway, so moved it.

OnPluginInstall -
1. Surprised this didn't generate an error.. Used isnumber, instead of isnumeric.

Anyway.. I think I got all the bugs out now and it will store and resize correctly. As to your comment about all messages showing up as being by you... Since the trigger grabs everything after the [CLAN]: part, it should also be storing the correct name. However, the fact that I used ',' to seperate things before means a line like [CLAN]: <player> says, 'yeah, Nick is uber.' would have produced two lines instead of one. Otherwise, I don't see why this would be happening.
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.


20,868 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.