CMud Scripting

LionasLionas Member, Historian Posts: 765 ✭✭✭✭✭
edited October 2012 in Scripting
By request, a thread now exists to post cmud scripts and/or make requests for help with them. This probably isn't the place to ask someone to write you something from scratch, but {basic|advanced} code help is fine.

Justus asked for my autologging events, so here those are. OnConnect turns it on, OnDisconnect toggles it, effectively turning it off. It formats the filename as sessionname_month_day_year.txt

<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <event event="OnConnect" priority="38520" copy="yes">
    <value>#log %concat(%title,"_",%time(m),"_",%time(d),"_",%time(y))</value>
  </event>
</cmud>
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
  <event event="OnDisconnect" priority="38530" copy="yes">
    <value>#log</value>
  </event>
</cmud>

I am the righteous one... 
the claims are stated - it's the world I've created 
Post edited by Garryn on
«134

Comments

  • JuranJuran OhioMember, Beta Testers Posts: 909 ✭✭✭✭✭
    I have it on good authority that all cool people log Imperian.
  • KhizanKhizan Member Posts: 2,648 ✭✭✭✭✭
    Evidence indicates otherwise.

    "On the battlefield I am a god. I love war. The steel, the smell, the corpses. I wish there were more. On the first day I drove the Northmen back alone at the ford. Alone! On the second I carried the bridge! Me! Yesterday I climbed the Heroes! I love war! I… I wish it wasn’t over."

  • LionasLionas Member, Historian Posts: 765 ✭✭✭✭✭
    edited October 2012
    As an example of simple functions and regex being awesome, here's a function that employs a simple look-ahead assertion to add commas to large numbers. @comma(INPUT) to comma-ify. (1234567 turns int 1,234,567 for example)

    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <cmud>
      <func name="comma" copy="yes">
        <value>#return %subregex($num,"(?&lt;=.)(?=(?:.{3})+$)",",")</value>
        <arglist>$num</arglist>
      </func>
    </cmud>
    I am the righteous one... 
    the claims are stated - it's the world I've created 
  • JuranJuran OhioMember, Beta Testers Posts: 909 ✭✭✭✭✭
    Lionas not being cool doesn't prove a thing, you'd have to find a cool person that doesn't log.
  • LionasLionas Member, Historian Posts: 765 ✭✭✭✭✭
    edited October 2012
    Because it can apparently cause some confusion, I want to clarify that the xml above is just the output format generated by cmud for exporting. CMUD uses XML to import and export code, rather than just exporting raw zscript commands like zmud did. It allows for a bit more flexibility as far as element attributes are concerned.

    The code itself is in zscript (at least what I posted, cmud also supports lua), and importing the xml will yield settings in that language.

    So, for posterity, readability, etc, here are the things I've posted so far, in zscript format.

    #event OnConnect {#log %concat(%title,"_",%time(m),"_",%time(d),"_",%time(y))}
    #event OnDisconnect {#log}

    #func comma($num) {#return %subregex($num,"(?&lt;=.)(?=(?:.{3})+$)",",")}

    And for giggles:
    #func rot13($string) {$string = %subchar($string, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm")
    $string = %concat("Encoded: ",$string)
    #return $string}
    I am the righteous one... 
    the claims are stated - it's the world I've created 
  • SarciossisSarciossis Member Posts: 163 ✭✭✭
    I'm just easily confused.  :-/
  • LionasLionas Member, Historian Posts: 765 ✭✭✭✭✭
    edited November 2012
    Bare bones caravan runner, uses in game path finding to build path. It doesn't attack bandits or do anything but build a path and walk it.

    <caravanto ##> to start, <docaravan> to start walking to the next room if the automatic movement is prevented (say, by being off balance)

    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <cmud>
      <class name="impmapcaravan" copy="yes">
        <class name="buildpath" copy="yes">
          <trigger priority="792660" copy="yes">
            <pattern>^Path: (*)$</pattern>
            <value>#local $tempvar
    $tempvar = %1
    caravanpath = @caravanpath + %replace(%replace($tempvar,", ","|"),",","|")
    docaravan
    #T- impmapcaravan|buildpath</value>
          </trigger>
          <trigger priority="792670" copy="yes">
            <pattern>^Path: (*),{ |}$</pattern>
            <value>#local $tempvar
    $tempvar = %1
    caravanpath = @caravanpath + %replace(%replace($tempvar,", ","|"),",","|") + "|"</value>
          </trigger>
          <trigger priority="3900" copy="yes">
            <pattern>^(%w), (*),{ |}$</pattern>
            <value>$tempvar = %1 + ", " + %2
    caravanpath = @caravanpath + %replace(%replace($tempvar,", ","|"),",","|") + "|"</value>
          </trigger>
          <trigger priority="3980" copy="yes">
            <pattern>^(%w), (*)$</pattern>
            <value>$tempvar = %1 + ", " + %2
    caravanpath = @caravanpath + %replace(%replace($tempvar,", ","|"),",","|")
    docaravan
    #T- impmapcaravan|buildpath</value>
          </trigger>
        </class>
        <var name="caravanpath" type="StringList" copy="yes"/>
        <alias name="caravanto" copy="yes">
          <value>caravanpath = ""
    #class impmapcaravan|buildpath 1
    #send path find %1</value>
        </alias>
        <alias name="docaravan" copy="yes">
          <value>queue eqbal lead caravan %item(@caravanpath,1)</value>
        </alias>
    <trigger priority="3670" copy="yes">
        <pattern>You lead a caravan (%w).</pattern>
        <value>#call %pop(caravanpath)
    #echo Remaining path: %replace(@caravanpath, "|", ", ")
    #echo %numitems(@caravanpath) steps remaining.
    #if (%numitems(@caravanpath)) {docaravan}</value>
      </trigger>
      </class>
    </cmud>
    I am the righteous one... 
    the claims are stated - it's the world I've created 
    AhkanSarciossisNevore
  • SarciossisSarciossis Member Posts: 163 ✭✭✭
    edited January 2013
    http://pastebin.com/FNbdnUrD - my class for impale/disembowel. trying to get my ignore list to work.
  • LionasLionas Member, Historian Posts: 765 ✭✭✭✭✭
    Copied here in case it helps someone else.

    (Ring): You say, "Syntax for if is."
    (Ring): You say, "#if (condition) {true action} {false action}."
    (Ring): You say, "You're missing {}."
    I am the righteous one... 
    the claims are stated - it's the world I've created 
    Sarciossis
  • GurnGurn Member Posts: 787 ✭✭✭✭
    Is there an 'elseif' function for Cmud? I can't seem to find one.
  • SelthisSelthis Member Posts: 524 ✭✭✭✭✭
    Gurn said:
    Is there an 'elseif' function for Cmud? I can't seem to find one.
    Look into #SWITCH
  • LionasLionas Member, Historian Posts: 765 ✭✭✭✭✭
    edited January 2013
    You can either use #switch (which is easier but only works if all the checks are based on the same variable's value) or chain ifs together like this:

    #if (condition) {true stuff} {#if (second condition) {else if stuff} {else stuff}}


    EDIT: It looks like my caveat above regarding switch statements may not be true in cmud, so that may be your cleanest bet.
    I am the righteous one... 
    the claims are stated - it's the world I've created 
  • DiceneDicene Member Posts: 913 ✭✭✭✭
    Anyone had any luck with the GMCP commands Char.Items.Inv or IRE.Rift.Request? I'm using "#sendgmcp Char.Items.Inv" and expecting to receive the Char.Items.List in return. I've got a trigger to echo all GMCP data received and I'm not receiving the Char.Items.List that should be shot back at me. Also, I think I've read from people that you need to send a blank line or something and the server sends it with the next prompt, but I'm not receiving anything apart from Char.Vitals of the next prompt.
    image
  • NevoreNevore Member Posts: 20
    edited January 2013

    Looking for a little bit of help backward engineering something. I've been trying to make myself a prettified elixlist table. I had one before but damned if I can find it or remember the workaround I'm having.

    Basically I've been using %tab to space things out, but two digit vial amounts are screwing it up.

    I found the below after searching for answers, and it does exactly what I want, but I don't know how. Whether with single or double or triple digit numbers in the vial, the display structure is maintained.

    #SAY | %format( "&s &8.0f", Frost:, @frostvial) | %format( "&s &8.0f", Venom:, @venomvial) | %format( "&s &8.0f", Speed:, @speedvial) |;#SAY | %format( "&s &3.0f", Levitation:, @levitationvial) | %format( "&s &6.0f", Caloric:, @caloricvial) | %format( "&s &9.0f", Mass:, @massvial) |

    I've read the file for %format and it isn't explaining anything. The &s &8.0f is obviously the part working the magick but I can't find where in the documentation to explain how or why.

    Basically I could finish the script I want by swapping out my own variables etc but I'd like to understand why the damn thing works. :/

    Edit: And I don't know how I broke the forum display either now. :D
  • LionasLionas Member, Historian Posts: 765 ✭✭✭✭✭
    edited January 2013
    &s, and it's cousin &f, represent pattern characters. S stands for string, F is floating-point number. &8.0f means right-align a number up to 8 digits, with no specific precision after the decimal.

    Since you're dealing with whole numbers exclusively, I'd suggest switching to &d instead of &f.

    As for the other special pattern characters, the help file for %format does give information (any typos below are from the documentation, not from me!):

    Format strings consist of a string of characters, with special format specifiers of the type &w.dx where w is the width of the field, d is the number of decimal places, and x is the format type.



    Valid format types:

    e: scientific notation(full format)
    f: floting point (defaults to 2 decimal places)
    g: scientific notation(abbreviated)
    m: money (defaults to 2 decimal places)
    n: number (commas every 3 digits, defaults to 2 decimal places)
    s: string
    d: integer (decimal). Same as n but without the commas

    -----------------------end documentation-----------------------
    If that isn't helpful, here's an example.

    %format("This is a pattern string containing within it a string: %s and a number right-aligned to 6 digits: %6d", @replacesthepercents, @replacesthepercentd)

    In that example I use % instead of &, because I'm used to printf, but either symbol will work.
    If you want to left-align something instead of right-align it, you can do this: %-15s
    That will left-align the string used to replace it up to 15 characters, and truncate the rest.

    The important thing to remember is that the replacements occur left-to-right, so the first argument after the format string replaces the first %something, the second argument the second %something, etc.
    I am the righteous one... 
    the claims are stated - it's the world I've created 
    Nevore
  • NevoreNevore Member Posts: 20
    If I could give your more awesomes, I would. Thanks, that makes a lot more sense now.
  • GurnGurn Member Posts: 787 ✭✭✭✭
    Not so much a scripting question as a Mudbot Cmud related question: When I'm playing with Mudbot, my exp and health and such never show right.

     <553/0h 349/0m 2536e 1581w 0x <ebpp> <bd>

    What's up with that? How do I get it to show max health/exp properly?
  • AzefelAzefel SingaporeMember Posts: 730 ✭✭✭✭
    open Prefs, go to Session.  Uncheck GMCP and ATCP emulation if either are checked. Apply/save/ok. Close cmud close mudbot, start again.
    image
  • NevoreNevore Member Posts: 20
    I'm cobbling together something to dstab with a range of venoms.

    I've figured out one way to do what I want (envenom with a 2 random toxins from a list) but the only way I could think to deal with doubling up was to use paired toxins, so the string looks like for ex. |noctec mebaral|noctec vitriol|vitriol mebaral| etc, six in total entries for the smoke toxins. I'll have another @variable for smoke tox without vitriol, one for tlock, one for kelp, one for etc etc.

    I'm using #send dstab @target {%item(@smoketox,%random(1,6))} for example, to pull the toxins from the string list.

    What I'd like instead to do is have the string list just contain noctec|mebaral|vitriol|iodine but I can't figure an easy way to prevent doubling up of toxins.

    So I'd #send dstab @target {random toxin from list} {random toxin from same list but not the first one used}

    I thought maybe of making a new list every dstab and using %delitem to strip the first toxin, but that seems overly clunky and I feel like there is/should be a simpler way.
  • DelrayneDelrayne Member Posts: 457 ✭✭✭
    It'd probably be best to let @Lionas take a stab at this, I can do it Lua but zscript not so much.

  • LionasLionas Member, Historian Posts: 765 ✭✭✭✭✭
    edited January 2013
    I'll start by saying that picking a random toxin is almost never a good idea. In the absence of a toxin tracker, though, I guess it's a thing you can do.
    Making a new list is certainly one way to do it, and probably more efficient than this. Just make sure it's a local var.

    #local $toxin1, $toxin2
    $toxin1=%item(@toxinlist, %random(%numitems(@toxinlist))
    $toxin2=%item(@toxinlist, %random(%numitems(@toxinlist))
    #while ($toxin1 = $toxin2) {$toxin2=%item(@toxinlist, %random(%numitems(@toxinlist))}
    #send dstab @target $toxin1 $toxin2


    I am the righteous one... 
    the claims are stated - it's the world I've created 
  • SarciossisSarciossis Member Posts: 163 ✭✭✭
    Mine works off of a list, in the same way that Lionas is doing here, except minus the randomness.
    #var {dostack} {#if (@curstack = sleep) {tstack=opium|opium}}
    #alias {op} {curstack = sleep; dostack}
    and then 
    #var {curstack} {}

    And then for application during attacks, for example with Ranger:
    {queue eqbal quickjab @target %pop( tstack) %pop( tstack)}

    Samiel helped me set this up, so if that helps you, I hope so. I like it because I can edit the dostack variable with a list of toxins I'd like to apply, but I'm trying to work in an affliction tracker to this so it'll be a bit more responsive. Though, it's not exactly what you're looking for because you want a random toxin from the list rather than the first two.
  • LionasLionas Member, Historian Posts: 765 ✭✭✭✭✭
    edited January 2013
    Yeah. @Nevore didn't want to make a new list, so I didn't, and did want randomness, so I did.

    Instead of using #var, use #local. Local variable references are slightly faster. You can still use a local var as a stringlist.
    I am the righteous one... 
    the claims are stated - it's the world I've created 
    Sarciossis
  • NevoreNevore Member Posts: 20
    edited January 2013
    Ok, I think I've made an incorrect assumption. I kind of imagined that tracking what your enemy has healed was impossible. I don't specifically want to envenom randomly, just thought that's what I should be doing, within a narrow range of afflictions.
    Soooo, I think I need to go back to square one. I will be back, with much more basic questions (like, wtf should I start with?!) tomorrow :embarassed:
  • LionasLionas Member, Historian Posts: 765 ✭✭✭✭✭
    For some sets of afflictions (those with the same cure and no third-party cure message), knowing what was healed is impossible. For everything else, there's mastercard.
    I am the righteous one... 
    the claims are stated - it's the world I've created 
    SarciossisKyrock
  • DelrayneDelrayne Member Posts: 457 ✭✭✭
    Yeah, you can make educated guesses in some cases. Sure it's not perfect, but it gets the job done for the most part.

  • AzefelAzefel SingaporeMember Posts: 730 ✭✭✭✭
    edited January 2013

    image
  • SelthisSelthis Member Posts: 524 ✭✭✭✭✭
    Okay, I'm missing something and I can't figure out what it is. 

    Trying to make a highlight for single shardfall notifications.  I've every version of the trigger I can think of but it will not fire.

    ^Your keen senses notice a single shard flying towards

    Is like the  most general pattern I could come up with.  All I want to do is color that single line red. Am I missing something super simple here?
  • AulaniAulani Member Posts: 199 ✭✭✭
    That trigger with

    #CO red

    should work.

    Though I went back to zmud after cmud ate my system twice.
  • SelthisSelthis Member Posts: 524 ✭✭✭✭✭
    edited January 2013
    That's just it.  Its not firing at all.   That is what I can't figure out

    Edit:

    <trigger priority="2380" id="238">
      <pattern>^Your keen senses notice a single shard flying towards</pattern>
      <value>#EC Hi
    #Co 492
    </value>
    </trigger>

    Is the XML
«134
Sign In or Register to comment.