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 ➜ Lua ➜ Curing System

Curing System

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


Pages: 1 2  

Posted by Noctem   (9 posts)  Bio
Date Mon 20 Aug 2007 11:44 PM (UTC)
Message
Well, I come for help. Lots and lots of help. I'm trying to set up my curing system on IRE's game Lusternia. It needs to be an advanced system, and try as I might, I can't figure it out on my own. To begin with, to create a working script for the game, what is some suggested reading? Should I just bloody learn the whole language disjoint from MUSHclient, or should I be looking somewhere specific with instructions about HOW to program Lua in MUSHClient? Next I need to actually figure out how to get it to work. The idea of my system is this:

Receive affliction 1:
script starts, checks anything that could stop the curing of this affliction, checks to see if it is a priority affliction

sets variable for affliction to 1. Goes through the process of getting the cure from wherever it is in my inventory, using it, and then setting the variable back to 0.



This is a basic outline, but I'm getting quite flustered at my lack of skill, even though I try very hard.
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #1 on Mon 20 Aug 2007 11:58 PM (UTC)
Message
This is a rather complex script that you are trying to make here. If you are new to Lua scripting, then you might want to try out a few simpler scripts first. Or, if you want to make progress in this script, break it into smaller chunks and deal with them one at a time.

1) Having some sort of flag system set up to show what affects you have on at the current time is a good place to start.

2) Next, build a priority queue and have it dump the most important affect to the screen.

3) An inventory scanner for the curatives can be extremely tricky, and it is usually very specific to each mud. Being able to scan in how much of each item you have is useful, but sometimes unnecessary. If the items can be kept track of through purchase, usage, and looting messages, you might just be able to keep a tally of all the items in a table. That would simplify things greatly. Have the counter for the item displayed each time something is purchased or used.

4) Set up another script to check the priority queue periodically and see if anything in the inventory table matches up with an affect. Then send a use message, and set a flag noting that this is in progress. Reset the flag on a use message.


Each one of these isn't too terribly bad on it's own, but it would be very complicated for a non-Lusternia player to make. Some information could be provided here by the general MUSHclient userbase, but some more information on the actual mud output would be needed. I'm planning on making a little potion tracker for the mud I play on, so I'll post it (or at least a link to it) on the forums.

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Simimi   (40 posts)  Bio
Date Reply #2 on Tue 21 Aug 2007 02:51 AM (UTC)

Amended on Tue 21 Aug 2007 02:58 AM (UTC) by Simimi

Message
If you look in the Mechanics section of the Lusternia forum, you can see many many threads started by myself that cover every little aspect of system making within Lusternia. To get you started I recommend adding the php.Lua file to your /lua dir for mush client, to let you build Lua tables that are forced to be compiled the way you want (for easily prioritizing affliction curing). Here is the file for you.


function phpTable(...)
    local newTable,keys,values={},{},{}
    newTable.pairs=function(self) -- pairs iterator
        local count=0
        return function()
            count=count+1
            return keys[count],values[keys[count]]
        end
    end
    setmetatable(newTable,{
        __newindex=function(self,key,value)
            if not self[key] then table.insert(keys,key)
            elseif value==nil then -- Handle item delete
                local count=1
                while keys[count]~=key do count = count + 1 end
                table.remove(keys,count)
            end
            values[key]=value -- replace/create
        end,
        __index=function(self,key) return values[key] end
    })
    return newTable
end

return phpTable


You would use it like this... in theory.


require "phptable"

salveaffs = phpTable()
salveaffs["asthma"] = "apply melancholic to chest"
salveaffs["concussion"] = "apply regeneration to head"

for affs,cure in salveaffs:pairs() do
   if affs[aff] then
     if (string.find(cure, "apply") and able_apply()) then
	   Execute(cure)
	   break
	 end
    end
 end 


Note that each of those three things are not together in my script, but they are separated by other code. That is one example of how you could go about it.
==========================================================

Also, as for the inventory sort thing, I have been working on that for almost a week and I have gotten no where. I think a Rift sorter would be more useful, as well as a better example of how something like this might be done.

A 'rift' is a place where we can store (herbs|commodities|tinictures|gems) etc etc. The issue here is as your rift gets fuller, the text gets longer. Here is an example.

3289h, 3106m, 2740e, 10p, 15345en, 14430w elrx-
ir
Glancing into the Rift, you see:
  [ 125] amethyst           [  40] arnica             [  86] bluetint
  [ 159] calamus            [  59] chervil            [   2] coal
  [  10] colewort           [   3] coltsfoot          [ 225] faeleaf
  [  10] flax               [   7] galingale          [  40] gems
  [  34] gold               [  34] goldtint           [ 130] greentint
  [ 120] kafe               [   6] kombu              [ 144] leather
  [  38] marjoram           [  10] merbloom           [  10] mistletoe
Type MORE to continue reading. (59% shown)
3289h, 3106m, 2740e, 10p, 15345en, 14430w elrx-
more
  [   1] myrtle             [  21] pennyroyal         [ 110] purpletint
  [ 127] redtint            [   4] reishi             [   1] rope
  [  15] rosehips           [  10] sage               [   5] sargassum
  [ 136] sparkleberry       [  59] weed               [  17] wood
  [  27] wormwood           [  83] yarrow             [ 127] yellowtint
3289h, 3106m, 2740e, 10p, 15345en, 14430w elrx-


Many people using Mush have asked for a way to catch your rift, and reprint it more ordered, like;


ir
Glancing into the Rift, you see:
*(TINTS)*
[ 127] yellowtint [ 127] redtint
*(HERBS)*
[ 136] sparkleberry [ 27] wormwood [ 83] yarrow
*(COMMODITIES)*
[ 17] wood [ 50] gems [ 10] rope [ 77] gold

And so on and So forth. If we can figure this out, we cold apply the same to other similar systems, like inventories, rune bags, tarot decks, dream catchers, etc etc etc.
Top

Posted by Worstje   Netherlands  (899 posts)  Bio
Date Reply #3 on Tue 21 Aug 2007 06:38 AM (UTC)
Message
I've written a curingsystem for Aetolia, although that is in Python. In any case, it is of the IRE family and I can assure you it is a lot of work, but also very rewarding if you like scripting. My curingsystem alone just crossed the 700 triggers barrier, and there are no noticable slowdowns yet.

I don't play Lusternia so can't give any exact advice, however...

1. Save data in a logical way. Don't be afraid to make it more abstract. Doing so will make it easier to make the various balances (eating herbs, applying salves etc) work on their own.
2. Triggering the prompt and doing your curing actions from there has its advantages over directly curing on an affliction message. It also makes it more painful when you have a bug somewhere, since your entire prompt and thus all of your curing will cease to be executed.
3. Don't be afraid to omit stuff from output if you know you can afford it. Or, gag and echo something more useful in return. It is a nasty balance between making it easier for yourself while in mid-combat and figuring out why your system is not working the way you want to.

I wanted to mention a few more things, but I kind of forgot.. Oh well.
Top

Posted by Isthiriel   (113 posts)  Bio
Date Reply #4 on Tue 21 Aug 2007 11:49 AM (UTC)
Message
Quote:
Also, as for the inventory sort thing, I have been working on that for almost a week and I have gotten no where. I think a Rift sorter would be more useful, as well as a better example of how something like this might be done.

I'm not sure where your problem is?

I can see a couple of ways of doing it, the hardest part is coping with the "Type MORE to continue reading. (59% shown)" and working out where the end is.

I think the important parts are (1) the initial trigger on "Glancing into the Rift, you see:" that EnableTriggerGroups
the actual processing and EnableTimers the 5 (10? 15?) second watchdog timer that DisableTriggerGroups everything and does the processing on the data collected, (2) the aforementioned watchdog timer, (3) the actual trigger(s) that trap the data.

It _looks_ like each line is 1, 2 or 3 repetitions of:
[ nn] item
Where " nn" = 4 characters (can you get more than 9999 of an item?) and "item" is always lowercase and one word.

So... regexes look like:
^\s+[([ 0-9]{4})] ([a-z]+)$
^\s+[([ 0-9]{4})] ([a-z]+)\s+[([ 0-9]{4})] ([a-z]+)$
^\s+[([ 0-9]{4})] ([a-z]+)\s+[([ 0-9]{4})] ([a-z]+)\s+[([ 0-9]{4})] ([a-z]+)$

And they each fire a function that caches the data for the watchdog timer to reprocess.
Top

Posted by Simimi   (40 posts)  Bio
Date Reply #5 on Tue 21 Aug 2007 05:38 PM (UTC)
Message
Well I had just started working on a rift trigger, and Noc was asking about an inventory trigger.

Each line in the mud output has 3 lines of [ nn] item, and only 2000 of any one item at a time.

My problem with doing things like this is that I can capture things with regex, but I do not know how to reprint it as something else. In the rift example, I would like it to reprint the data organized by what the item is, which I guess would need a masterlist of all commodities that can be put into the rift, by type?
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #6 on Tue 21 Aug 2007 06:45 PM (UTC)

Amended on Tue 21 Aug 2007 07:00 PM (UTC) by Shaun Biggs

Message
Here's how I would do the capture:
^  (?:\[([ \d]{4})\] (\w+)\s*){1,3}

This way all the odd numbered wildcards are the count of the following wildcard, which is an item. Just need one trigger sending to a script which loops through the wildcards grabbing the information to put into some sort of table.

riftitems={}
function riftcapture( sTrig, sLine, wildcards )
  riftitems[ wildcards[2] ] = tonumber( wildcards[1] )
  if wildcards[4] then
    riftitems[ wildcards[4] ] = tonumber( wildcards[3] )
    if wildcards[6] then
      riftitems[ wildcards[6] ] = tonumber( wildcards[5] )
    end
  end
end

riftsort = { { "tints", {"yellowtint", "redtint"} }
             { "herbs", {"sparkleberry", "wormwood", "yarrow" },
             { "commodities", {"wood","gems","rope","gold" }
           }
function showrift()
  for _,i in riftsort do
    Note( "*("..string.upper(i[1])..")*")
    for k,v in i[2] do
      Tell( string.format( "  [%4d"] %-15s", riftitems[i], i ) }
    end
    Note( "" )
  end
end

edit: someday I will remember to use convert to forum codes before saving the message.

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Simimi   (40 posts)  Bio
Date Reply #7 on Wed 22 Aug 2007 04:21 AM (UTC)

Amended on Wed 22 Aug 2007 06:45 AM (UTC) by Nick Gammon

Message
Playing with it, it keeps asking me to close something on line 12, on line 16. So I closed it, and it said close it on line 17, so I did, then line 18, and so on and so forth...


[string "Script file"]:18: '}' expected (to close '{' at line 12) near 'function'




riftitems={}
function riftcapture( sTrig, sLine, wildcards )
  riftitems[ wildcards[2] ] = tonumber( wildcards[1] )
  if wildcards[4] then
    riftitems[ wildcards[4] ] = tonumber( wildcards[3] )
    if wildcards[6] then
      riftitems[ wildcards[6] ] = tonumber( wildcards[5] )
    end
  end
end

riftsort = { { "tints", {"yellowtint", "redtint"},
             { "herbs", {"sparkleberry", "wormwood", "yarrow" },
             { "commodities", {"wood","gems","rope","gold" },
           }

function showrift()
  for _,i in riftsort do
    Note( "*("..string.upper(i[1])..")*")
    for k,v in i[2] do
      Tell( string.format( "  [%4d"] %-15s", riftitems[i], i ) }
    end
    Note( "" )
  end
end
end
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #8 on Wed 22 Aug 2007 04:41 AM (UTC)
Message
Bah, forgot a comma and put a brace where a parenthesis goes. Sorry, I kind of haphazardly ripped this out of a potion tracking plugin I made and tried hacking it back together too quickly. Just as a side note, if not all the things for sale have there own categories, then there should be some way to make a table of all the unclassified items in the rift.

riftitems={}
function riftcapture( sTrig, sLine, wildcards )
  riftitems[ wildcards[2] ] = tonumber( wildcards[1] )
  if wildcards[4] then
    riftitems[ wildcards[4] ] = tonumber( wildcards[3] )
    if wildcards[6] then
      riftitems[ wildcards[6] ] = tonumber( wildcards[5] )
    end
  end
end

riftsort = { { "tints", {"yellowtint", "redtint"} },
             { "herbs", {"sparkleberry", "wormwood", "yarrow" },
             { "commodities", {"wood","gems","rope","gold" }
           }
function showrift()
  for _,i in riftsort do
    Note( "*("..string.upper(i[1])..")*")
    for k,v in i[2] do
      Tell( string.format( "  [%4d"] %-15s", riftitems[i], i ) )
    end
    Note( "" )
  end
end

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Simimi   (40 posts)  Bio
Date Reply #9 on Wed 22 Aug 2007 05:00 AM (UTC)

Amended on Wed 22 Aug 2007 06:45 AM (UTC) by Nick Gammon

Message
I do not think I know this syntax, because I apparently have never done anything cool or radical with my scripts because most of this I am seeing is new to me (it is a great study aid though!).


[string "Script file"]:17: '}' expected (to close '{' at line 14) near 'function'



riftitems={}
function riftcapture( sTrig, sLine, wildcards )
  riftitems[ wildcards[2] ] = tonumber( wildcards[1] )
  if wildcards[4] then
    riftitems[ wildcards[4] ] = tonumber( wildcards[3] )
    if wildcards[6] then
      riftitems[ wildcards[6] ] = tonumber( wildcards[5] )
    end
  end
end

riftsort = { { "tints", {"yellowtint", "redtint", "bluetint", "purpletint", "greentint", "goldtint" } },
             { "herbs", {"sparkleberry", "wormwood", "yarrow", "pennyroyal", "sargassum", "weed", "arnica", "calamus", "chevril", "colewort", "coltsfoot", "faeleaf", "flax", "galingale", "kafe", "kombu", "marjoram", "merbloom", "mistletoe", "myrtle", "reishi", "rosehips", "sage" },
             { "commodities", {"wood", "gems", "rope", "gold", "coal", "leather" },
			 { "gems", {"moonstone", "ruby", "emerald", "amethyst", "coral", "pearl", "beryl", "bloodstone", "garnet", "jade", "onyx", "opal", "sapphire", "turquoise" }
		   }
function showrift()
  for _,i in riftsort do
    Note( "*("..string.upper(i[1])..")*")
    for k,v in i[2] do
      Tell( string.format( "  [%4d"] %-15s", riftitems[i], i ) )
    end
    Note( "" )
  end
end


That is most of the rift items, though... things like "ruby" would be "rubies" in the rift, so would I need to add those to the list also? It is not a complete list, but it covers everything in -my- rift. A friend is sending something of everything possible for me to add.
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #10 on Wed 22 Aug 2007 05:06 AM (UTC)

Amended on Wed 22 Aug 2007 05:43 AM (UTC) by Shaun Biggs

Message
Text editors that match {}, (), and [] are an invaluable tool. When adding the extra items, you forgot the underlined "}". This, as well as how I screwed up with having a "}" where a ")" should have been are easy to check for when your editor makes note of where the paired mark is.

riftsort = { { "tints", {"yellowtint", "redtint", "bluetint", "purpletint", "greentint", "goldtint" } },
             { "herbs", {"sparkleberry", "wormwood", "yarrow", "pennyroyal", "sargassum", "weed",
	                 "arnica", "calamus", "chevril", "colewort", "coltsfoot", "faeleaf", "flax",
			 "galingale", "kafe", "kombu", "marjoram", "merbloom", "mistletoe", "myrtle",
			 "reishi", "rosehips", "sage" } },
             { "commodities", {"wood", "gems", "rope", "gold", "coal", "leather" } },
             { "gems", {"moonstone", "ruby", "emerald", "amethyst", "coral", "pearl", "beryl", "bloodstone",
	                "garnet", "jade", "onyx", "opal", "sapphire", "turquoise" } }
           }

Also, since Lua allows for tables to be defined over several lines, I broke up the assigment into a few lines. Mostly so I could see where the pairs of braces were. If you don't like it, it's easy to convert back.

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Simimi   (40 posts)  Bio
Date Reply #11 on Wed 22 Aug 2007 05:16 AM (UTC)
Message
I just use LuaEdit. If you can recommend something better, please do. Thanks for all the help by the by! Let's see if I can get this working now. Why is it always the same error?

[string "Script file"]:24: '}' expected (to close '{' at line 14) near 'function'


line 14 is the line with 'function' on it, obviously.


riftsort = { { "tints", {"yellowtint", "redtint", "bluetint", "purpletint", "greentint", "goldtint" } },
             { "herbs", {"sparkleberry", "wormwood", "yarrow", "pennyroyal", "sargassum", "weed",
	                 "arnica", "calamus", "chevril", "colewort", "coltsfoot", "faeleaf", "flax",
			 "galingale", "kafe", "kombu", "marjoram", "merbloom", "mistletoe", "myrtle",
			 "reishi", "rosehips", "sage" },
             { "commodities", {"wood", "gems", "rope", "gold", "coal", "leather" } },
             { "gems", {"moonstone", "ruby", "emerald", "amethyst", "coral", "pearl", "beryl", "bloodstone",
	                "garnet", "jade", "onyx", "opal", "sapphire", "turquoise" }
           }


function showrift()
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #12 on Wed 22 Aug 2007 05:41 AM (UTC)

Amended on Wed 22 Aug 2007 06:01 AM (UTC) by Shaun Biggs

Message
I'm just going back and editing the posts now... getting to be too long of a thread just for typos.

As for editors, I use Textpad, but I don't believe it's free. I haven't used a Windows system in ages, so I don't really remember. Crimson is what Nick recommended to me for Windows, and from the screenshots, it looks like it's a great program. Free to use, to boot.

It is much easier to fight for one's ideals than to live up to them.
Top

Posted by Simimi   (40 posts)  Bio
Date Reply #13 on Wed 22 Aug 2007 05:44 AM (UTC)

Amended on Wed 22 Aug 2007 06:42 AM (UTC) by Nick Gammon

Message
I agree, good idea!


Tell( string.format( "  [%4d"] %-15s", riftitems[i], i ) )



[string "Script file"]:27: ')' expected near ']'
Top

Posted by Shaun Biggs   USA  (644 posts)  Bio
Date Reply #14 on Wed 22 Aug 2007 06:01 AM (UTC)

Amended on Wed 22 Aug 2007 06:43 AM (UTC) by Nick Gammon

Message
Tell( string.format( "  [%4d] %-15s", riftitems, i ) )

Hopefully that's it... pretty much the end of the script anyway.

It is much easier to fight for one's ideals than to live up to them.
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.


75,812 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

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.