 |
Dyron Apprentice
Joined: 08 Apr 2004 Posts: 103 Location: USA
|
Posted: Mon Jan 05, 2009 5:47 pm
Line sequence obtain |
I am looking for a way to take a line and be able to do multiple adds from it.
So lets say this is the line
Person wants to buy: tumor, kidney, liver, ovary
#additem selling "%1|%2|%3|%4"
But this needs to work no matter how many items they give me.. So lets say they do this
Person wants to buy: tumor
#additem selling "tumor" |
|
|
 |
Progonoi Magician
Joined: 28 Jan 2007 Posts: 430
|
Posted: Mon Jan 05, 2009 6:12 pm |
Hmm, I'd do it like this.
Code: |
#regex {Person wants to buy\: (.+)$} {$BuyData=%replace(%1,",","|");#forall $BuyData {#additem selling %i}}
|
Untested, but that's the gist of it what I got with a first thought. I'm sure the code could be even more shorted with
var=%subregex.. etc scenario, though.
Hope this helps. |
|
_________________ The Proud new owner of CMud.
--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
-------------------------------- |
|
|
 |
Fang Xianfu GURU

Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Jan 05, 2009 7:53 pm |
I dunno, I'd stay away from %subregex for something this simple. Your trigger is spot on, but you need to replace the spaces as well - I'd do it with the whole code of the trigger being #forall %subchar(%1,", ","|") {#additem selling %1}, which looks pretty awful but hopefully makes more sense when you see it highlighted in the package editor.
|
|
|
 |
Dyron Apprentice
Joined: 08 Apr 2004 Posts: 103 Location: USA
|
Posted: Thu Feb 12, 2009 2:38 am |
Hrmm.. never could get this code to work, but I also needed to give more information.. so figured I'd try again..
Person tells you, "Buy: tumor, kidney, liver, ovary."
#additem selling "%1|%2|%3|%4" |
|
|
 |
charneus Wizard

Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Thu Feb 12, 2009 3:06 am |
First of all, you couldn't do the "%1|%2|%3|%4" simply because it's quoting the %'s instead of putting it in literal. This works:
#TRIGGER {Person tells you, "Buy:(*)."} {#FORALL %subregex(%1,", ","|") {#ADDITEM selling %i}}
This has been tested and hasn't failed yet. If it doesn't work for you, please do a debug so we can see where it's failing for you.
Charneus |
|
|
 |
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Thu Feb 12, 2009 8:54 am |
How about
#TRIGGER {Person tells you, "Buy:(*)."} {selling = %concat(@selling, "|", %subchar(%1,", ","|")}
Although that does depend on the pattern of text you're getting, there's quite a lot of difference between "Person wants to buy: blah" and "Person tells you, "Buy: blah."". |
|
|
 |
Dyron Apprentice
Joined: 08 Apr 2004 Posts: 103 Location: USA
|
Posted: Thu Feb 12, 2009 8:20 pm |
hrmm.. had someone try to use a different divider.. What if they use | instead of ,
basically
Person tells you, "Buy: tumor | kidney | liver | ovary." |
|
|
 |
Progonoi Magician
Joined: 28 Jan 2007 Posts: 430
|
Posted: Thu Feb 12, 2009 9:44 pm |
Well, with pipe it's even easier then, you just have to trim the spaces and pipes remain for the string list.
#trigger {Person tells you, ~"Buy: (*)~.~"} {selling=%replace(%subchar(%1,",;:-_","")," ","|")}
I'm pretty sure the above works although I haven't tested it. Subchar takes care of all the stuff you don't want and replace function
replaces spaces with pipes for the string list. |
|
_________________ The Proud new owner of CMud.
--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
-------------------------------- |
|
|
 |
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Fri Feb 13, 2009 5:21 pm |
You probably don't want to replace spaces with pipes, because if there are spaces on either side of the punctuation, you end up with extra pipes.
|
|
|
 |
Progonoi Magician
Joined: 28 Jan 2007 Posts: 430
|
Posted: Fri Feb 13, 2009 7:35 pm |
I wondered about it a bit and while below code is definitely hokey, it does the job on removing the non-needed spaces and
eventually formatting the whole thing to a string list.
Code: |
#show %replace(%replace(%subchar("overy | liver | heart | stomach",";:_-","")," |","|")," ","")
|
Anyway, I'm completely sure there's a nicer way to obtain all this but I've been actively gone from CMud for long enough for it to escape me. |
|
_________________ The Proud new owner of CMud.
--------------------------------
Intel Core i5-650 3,2GHz
4 DD3 RAM
GTX 460 768MB
Win 7 Home Premium 64x
-------------------------------- |
|
|
 |
Vijilante SubAdmin

Joined: 18 Nov 2001 Posts: 5187
|
Posted: Fri Feb 13, 2009 10:27 pm |
I am a little bit unclear about your use of the "selling" variable. How else is it referenced? What happens if you receive 2 tells in rapid succession? What do you want to actually happen?
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
 |
gamma_ray Magician
Joined: 17 Apr 2005 Posts: 496
|
Posted: Sat Feb 14, 2009 10:23 am |
I think extra pipes would be preferable, you can then either replace \|\|+ with | or you can just remove all empty items from the list.
|
|
|
 |
Dyron Apprentice
Joined: 08 Apr 2004 Posts: 103 Location: USA
|
Posted: Sat Feb 21, 2009 10:00 pm |
The selling variables takes what all they are wanting to buy.. Like lets say 100 livers... It then checks for the item in a price list.. multiplies it by the right number.. Basically.. I use it to give a price cost
|
|
|
 |
|
|