MUSHclient Help Desk

2»

Comments

  • KerocKeroc A small cupboardMember, Administrator, Immortal Posts: 364 admin
    If making use of string matching functions is working for Mr NewCoder, I don't really see anything wrong continuing to use that. The important thing with a script at the end of the day is that it works.

    The reason I personally recommend using a JSON package is because it does everything for you already.

    require "json" local table = nil function decodeGMCP( params ) table = json.decode( params ) for k, v in ipairs( table ) print( k, v ) end end

    This is so much easier in the long run then setting up a str:gsub search or whatever other method that may be used.

    Reux
  • ReuxReux Member Posts: 251 ✭✭✭
    edited August 2015
    To better illustrate my problem.
    function TestDisplayStuff ()

    local TestGMCP = 'Char.Vitals { "hp": "6760", "maxhp": "5548", "mp": "5403", "maxmp": "4912", "ep": "29182", "maxep": "26400", "wp": "26400", "maxwp": "26400", "nl": "81", "xp": "17168261", "maxxp": "21072033", "blood": "100", "bleeding": "0", "blind": "0", "deaf": "0", "prone": "0", "cloak": "0", "fangbarrier": "0", "phased": "0", "elevation": "ground", "herb": "1", "salve": "1", "pipe": "1", "elixir": "1", "moss": "1", "tree": "1", "renew": "1", "affelixir": "1", "focus": "1", "writhing": "0", "fallen": "0", "soul": "100", "residual": "100", "madness": "0", "balance": "1", "equilibrium": "1", "ability_bal": "1", "left_arm": "1", "right_arm": "1", "wield_left": "empty", "wield_right": "empty", "mounted": "0", "vote": "1", "string": "H:6760/5548 M:5403/4912 E:29182/26400 W:26400/26400 NL:81/100 ", "charstats": [ "Level: 137" ] }'

    local ExampleTable = {}

    ExampleTable = json.decode(TestGMCP)

    tprint(ExampleTable)

    end
    Does not work. You get errors because of the Char.Vitals in front of the string. I'm thinking that JSON wants you to only interpret the {}, so I need to make that variable... without use of a trigger/catch like Me Newb wants to do it.

    Then I realized I was overthinking it completely and this works fine.
    function TestDisplayStuff ()

    local ExampleCharVitals = {}
    local t = {}

    local JSONed = rex.new ("([A-Za-z.]+) (\{.+\})", rex.flags().ANCHORED)

    local TestGMCP = 'Char.Vitals { "hp": "6760", "maxhp": "5548", "mp": "5403", "maxmp": "4912", "ep": "29182", "maxep": "26400", "wp": "26400", "maxwp": "26400", "nl": "81", "xp": "17168261", "maxxp": "21072033", "blood": "100", "bleeding": "0", "blind": "0", "deaf": "0", "prone": "0", "cloak": "0", "fangbarrier": "0", "phased": "0", "elevation": "ground", "herb": "1", "salve": "1", "pipe": "1", "elixir": "1", "moss": "1", "tree": "1", "renew": "1", "affelixir": "1", "focus": "1", "writhing": "0", "fallen": "0", "soul": "100", "residual": "100", "madness": "0", "balance": "1", "equilibrium": "1", "ability_bal": "1", "left_arm": "1", "right_arm": "1", "wield_left": "empty", "wield_right": "empty", "mounted": "0", "vote": "1", "string": "H:6760/5548 M:5403/4912 E:29182/26400 W:26400/26400 NL:81/100 ", "charstats": [ "Level: 137" ] }'

    s, e, t = JSONed:match (TestGMCP)

    if (t[1] == "Char.Vitals") then
    ExampleCharVitals = json.decode(t[2])
    tprint(ExampleCharVitals)
    end

    end
    So done; this journey has started apparently. You've converted one more person to using JSON.

    Edit

    I kinda want to dig through the implementation of this and figure if I can tonumber() all the number values as they're saved, or figure if they have to be saved as string initially at all.

    Edit #2

    Is there documentation for this implementation MUSHclient comes packaged to use? I'm reading all the .lua files in the folder and I'm not seeing the convenient help formatting I'm used to seeing.
    Post edited by Reux on
    I mean, you know, an amount.


  • ReuxReux Member Posts: 251 ✭✭✭
    edited August 2015
    Sorry for the double post, but I have a general question that'll get applied to issues in the future.

    How can I tell if a variable is a table?

    My thing for GMCP breaks because because charstat is saved as an itinerated table. I'm not sure how to look for tables.
    function Problem ()

    local T = {
    A = "ABC",
    B = "1",
    C = {"ABC", "1"}
    }

    for k, v in pairs(T) do
    if (string.find (T[k], "[^0-9]") == nil) then T[k] = tonumber(T[k]) end
    end

    end
    This demonstrates what I'm talking about.

    Also, if class information was taken out of Char.Vitals because you should be looking at Char.Status for it, should this charstatus field in Char.Vitals get removed? It only shows level, and level is in Char.Status currently.

    Edit

    And then I figure it out. I was looking for type. -_-
    local T = {
    A = "ABC",
    B = "1",
    C = {"ABC", "1"}
    }

    for k, v in pairs(T) do
    if (type(T[k]) == "string") then
    if (string.find (T[k], "[^0-9]") == nil) then T[k] = tonumber(T[k]) end
    end
    end

    end
    Post edited by Reux on
    I mean, you know, an amount.


  • AdaliAdali Member Posts: 32 ✭✭✭
    Is there anyone who can talk me through how to make a really simple autobasher that just keeps beating on one named target until that is dead? For example, I target nazetu, autobasher keeps striking nazetu until there are no nazetu in the room and I can move on or switch target.
  • AldricAldric Member Posts: 790 ✭✭✭✭✭
    edited September 2015
    I'm not exactly sure how MUSH syntax works, but if you've got a basic grasp on it hopefully the logic could help at the very least? This is pretty much as basic as it gets, but it's what I've used in the past:

    Variables you'll need (and you can change these to whatever you're comfortable with/want to name them):
    Bashing
    Target

    Aliases (same as above, name them whatever you'd like obviously):
    Bashon
    Bashoff
    T (target)

    Triggers:
    You have recovered balance on all limbs.
    You have recovered equilibrium.

    Explanation:

    Bashon - This alias would turn your auto basher on by setting the bashing variable to 1
    Bashoff - This alias would turn your auto basher off by setting the bashing variable to false
    T - This alias sets your target.

    From there you'd basically just use the following line on either the balance/equilibrium line, depending on what your bashing attack uses:

    If Bashing = 1 then (your attack here) Target

    Once there aren't any targets in the room that match your selected target, you'll get a line something along the lines of, "There is no X here" which would prompt you to either change targets or rooms!

    Caveats:
    Due to this being as basic as it gets, you might have to manually attack again if you're stunned by an NPC, or get afflicted with something that would interrupt your attack pattern. This is pretty easily taken care of by putting the same line from your 'You have recovered X' trigger into a trigger for when stun/etc. fades.

    You'll also have to remember to actually use your 'bashoff' (or whatever you name your bashing disable alias) when you're done. If you're bashing with an ambiguous target and head into a city without turning bashing off and do anything that uses EQ or Balance with it on, you might end up hitting something in there!

    EDIT: Also, you'll always have to initiate the first attack yourself for the basher to start if you do it this way, since it's dependent on balance/EQ. I'm lazy, so I always had an alias 'a' (because it's simple to type, easy to remember) that just sends whatever my bashing attack is at my target alias.
    image
    Feelings, sensations that you thought were dead. No squealin' remember, that it's all in your head.
2»
Sign In or Register to comment.