Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » Finished MUD Scripts
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Wed Aug 29, 2007 2:01 am   

Achaea GiveHandler
 
Some of the features include automatic handling for selfishness, doing a list such as "give a1|b2|c3|d4 vijilante" or like "give a1 b2 c3 d4 vijilante", and using aliases. The aliases can contain some interesting scripting items to help integrate with your current data structures. Alias can be used for any portion to the give except who to give it to, but you could do "give vijilante" to give the contents of a vijilante alias to vijilante. Cool As with all my scripts I suggest turning off the Script Parser preferences "Use [] for evaluation" and "Use <> for expansion".

As long as the GiveAliases variable imports right it has some examples of the wacky syntax support for the aliases in the handler and here is the explaination of the syntaxes here in order of each attempted operation.
The keys are the alias names, keep them simple since they are what you will likely type.
a1|a2|a3|a4 Lists are accepted, and these will actually be rechecked for yet more aliases
: This is a direct replacement when the alias is first expanded. It becomes the alias name
:\## Extra syntax for colon, modifies the replacement with the word ## using an '_' as the seperator
?[regex] You might have problems with using further brackets in the regex, but most everything else should work. The regex is checked again a variable named Inventory. It is assumed this variable is a record variable with keys of itemID and values of item name. The return value is a list of all the itemID's that made a match. Matching checks both the ID and the name information.
$[variable] Does a lookup of @variable this supports an extra syntax
$[variable]\## The variable lookup is further checked by %item
#[alias] Since aliases might need to be embedded in other text, this one will return the value portion of the named GiveAlias
- This is a modifier for when another anything above returns a list this one will allow removing items. It requires an exact match of something after the '-' for an item in the list before the first minus.

All of these syntaxes are tested in a psuedo recusive fashion. If something doesn't work out the whole thing will just be returned. This lets everything that works get done then it will try again. The attempts to further improve and adjust the aliases ends when no change is managed in a single pass. Speed wise it seems pretty decent, and all processing is done before it issues "generosity".
Code:
#CLASS {GiveHandler}
#ALIAS gq {GiveTemp=1;GiveTemp5=%replace("%-1"," to "," ");GiveTemp6=%word(@GiveTemp5,%numwords(@GiveTemp5));#IF (%numwords(@GiveTemp5)>1) {GiveTemp5=%leftback(@GiveTemp5,%eval(%len(@GiveTemp6)+1))};#WHILE (@GiveTemp<=%numwords(@GiveTemp5)) {GiveTemp11=%word(@GiveTemp5,@GiveTemp);#IF (%numitems(@GiveTemp2)>1) {GiveTemp11=@GiveTemp2;#WHILE (@GiveTemp11) {GiveTemp2=%pop(GiveTemp11);GiveTemp3="";GivingParse;#IF (%numitems(@GiveTemp3)>1) {GiveTemp2=%pop(@GiveTemp3);GiveTemp11=%concat(@GiveTemp11,"|",@GiveTemp3);GiveTemp3=@GiveTemp2;GiveTemp3=""};#WHILE (@GiveTemp2!=@GiveTemp3) {GiveTemp2=@GiveTemp3;GivingParse;#IF (%numitems(@GiveTemp3)>1) {GiveTemp2=%pop(@GiveTemp3);GiveTemp11=%concat(@GiveTemp11,"|",@GiveTemp3);GiveTemp3=@GiveTemp2;GiveTemp3=""}};#IF (@GiveTemp3) {#ADDKEY Giving {@GiveTemp3} {@GiveTemp6}}};#ADD GiveTemp 1} {#IF (@GiveTemp11="all") {#ADD GiveTemp 1;GiveTemp11=%word(@GiveTemp5,@GiveTemp);#WHILE (@GiveTemp11) {GiveTemp2=%pop(GiveTemp11);GiveTemp3="";GivingParse;#IF (%numitems(@GiveTemp3)>1) {GiveTemp2=%pop(@GiveTemp3);GiveTemp11=%concat(@GiveTemp11,"|",@GiveTemp3);GiveTemp3=@GiveTemp2;GiveTemp3=""};#WHILE (@GiveTemp2!=@GiveTemp3) {GiveTemp2=@GiveTemp3;GivingParse;#IF (%numitems(@GiveTemp3)>1) {GiveTemp2=%pop(@GiveTemp3);GiveTemp11=%concat(@GiveTemp11,"|",@GiveTemp3);GiveTemp3=@GiveTemp2;GiveTemp3=""}};#IF (@GiveTemp3) {#ADDKEY Giving {all @GiveTemp3} {@GiveTemp6}}};#ADD GiveTemp 1} {#IF (%isnumber(@GiveTemp11)) {GiveTemp11=%word(@GiveTemp5,%eval(@GiveTemp+1));#WHILE (@GiveTemp11) {GiveTemp2=%pop(GiveTemp11);GiveTemp3="";GivingParse;#IF (%numitems(@GiveTemp3)>1) {GiveTemp2=%pop(@GiveTemp3);GiveTemp11=%concat(@GiveTemp11,"|",@GiveTemp3);GiveTemp3=@GiveTemp2;GiveTemp3=""};#WHILE (@GiveTemp2!=@GiveTemp3) {GiveTemp2=@GiveTemp3;GivingParse;#IF (%numitems(@GiveTemp3)>1) {GiveTemp2=%pop(@GiveTemp3);GiveTemp11=%concat(@GiveTemp11,"|",@GiveTemp3);GiveTemp3=@GiveTemp2;GiveTemp3=""}};#IF (@GiveTemp3) {#ADDKEY Giving {%word(@GiveTemp5,@GiveTemp) @GiveTemp3} {@GiveTemp6}}};#ADD GiveTemp 2} {#WHILE (@GiveTemp11) {GiveTemp2=%pop(GiveTemp11);GiveTemp3="";GivingParse;#IF (%numitems(@GiveTemp3)>1) {GiveTemp2=%pop(@GiveTemp3);GiveTemp11=%concat(@GiveTemp11,"|",@GiveTemp3);GiveTemp3=@GiveTemp2;GiveTemp3=""};#WHILE (@GiveTemp2!=@GiveTemp3) {GiveTemp2=@GiveTemp3;GivingParse;#IF (%numitems(@GiveTemp3)>1) {GiveTemp2=%pop(@GiveTemp3);GiveTemp11=%concat(@GiveTemp11,"|",@GiveTemp3);GiveTemp3=@GiveTemp2;GiveTemp3=""}};#IF (@GiveTemp3) {#ADDKEY Giving {@GiveTemp3} {@GiveTemp6}}};#ADD GiveTemp 1}}}}}
#ALIAS give {#IF (@Giving) {#IF (%numparam) {gq %-1} {#IF (@Selfishness=1) {#T+ GiveGenerosity;generosity} {DoGiving}}} {#IF (%numparam) {gq %-1};#IF (@Selfishness=1) {#T+ GiveGenerosity;generosity} {DoGiving}}}
#ALIAS DoGiving {#IF (@Giving) {#LOOPDB @Giving {#IF (%db(@Wearing,%key)) {unwear %key};#IF (%pos("*",%key)) {#LOOP %word(%key,2,"*") {#SEND {give %word(%key,1,"*") to %val}}} {#SEND {give %key to %val}};#DELKEY Giving {%key}}};#IF (@Selfishness=-1) {selfishness};#T- GiveGenerosity}
#ALIAS GivingParse {#IF (%iskey(@GiveAliases,@GiveTemp2)) {GiveTemp3=%db(@GiveAliases,@GiveTemp2);GiveTemp4=%regex(@GiveTemp3,"(\:(?:\\d+|))",@GiveTemp7);GiveTemp9="";#WHILE (@GiveTemp4) {GiveTemp8=@GiveTemp2;#IF (%pos("\",@GiveTemp7)) {GiveTemp8=%word(@GiveTemp8,%word(@GiveTemp7,2,"\"),"_")};#IF (@GiveTemp8) {GiveTemp3=%replace(@GiveTemp3,@GiveTemp7,@GiveTemp8)} {GiveTemp9=%concat(@GiveTemp9,%copy(@GiveTemp3,1,@GiveTemp4));GiveTemp3=%right(@GiveTemp3,@GiveTemp4)};GiveTemp4=%regex(@GiveTemp3,"(\:(?:\\d+|))",@GiveTemp7)};GiveTemp3=%concat(@GiveTemp9,@GiveTemp3)} {#IF (@GiveTemp2!=%subchar(@GiveTemp2,"^!+-#$&|!=\[]*.?:","")) {GiveTemp3=@GiveTemp2;GiveTemp4=%regex(@GiveTemp3,"\?\[(.*?)\]",@GiveTemp7);GiveTemp9="|";#WHILE (@GiveTemp4) {GiveTemp10=%expanddb(@Inventory,"|","=");#IF (%regex(@GiveTemp10,%concat("\|([^|]*",@GiveTemp7,".*?)(?:\||\z)"),@GiveTemp8)) {#ADDITEM GiveTemp9 {%word(@GiveTemp8,1,"=")};GiveTemp10=%replace(@GiveTemp10,@GiveTemp8,"");#WHILE (%regex(@GiveTemp10,%concat("\|([^|]*",@GiveTemp7,".*?)(?:\||\z)"),@GiveTemp8)) {#ADDITEM GiveTemp9 {%word(@GiveTemp8,1,"=")};GiveTemp10=%replace(@GiveTemp10,@GiveTemp8,"")};GiveTemp3=%replace(@GiveTemp3,%concat("?[",@GiveTemp7,"]"),"");GiveTemp9=%concat(@GiveTemp9,"|")} {GiveTemp9=%concat(@GiveTemp9,%copy(@GiveTemp3,1,@GiveTemp4));GiveTemp3=%right(@GiveTemp3,@GiveTemp4)};GiveTemp4=%regex(@GiveTemp3,"\?\[(.*?)\]",@GiveTemp7)};#DELITEM GiveTemp9 {};GiveTemp3=%concat(@GiveTemp9,@GiveTemp3);GiveTemp4=%regex(@GiveTemp3,"(\$\[.*?\](?:\\d+|))",@GiveTemp7);GiveTemp9="";#WHILE (@GiveTemp4) {GiveTemp8=%expand(@{%subchar(%word(@GiveTemp7,1,"\"),"${}","")});#IF (%pos("\",@GiveTemp7)) {GiveTemp8=%item(@GiveTemp8,%word(@GiveTemp7,2,"\"))};#IF (@GiveTemp8) {GiveTemp3=%replace(@GiveTemp3,@GiveTemp7,@GiveTemp8)} {GiveTemp9=%concat(@GiveTemp9,%copy(@GiveTemp3,1,@GiveTemp4));GiveTemp3=%right(@GiveTemp3,@GiveTemp4)};GiveTemp4=%regex(@GiveTemp3,"(\$\[.*?\](?:\\d+|))",@GiveTemp7)};GiveTemp3=%concat(@GiveTemp9,@GiveTemp3);GiveTemp4=%regex(@GiveTemp3,"\#\[(.*?)\]",@GiveTemp7);GiveTemp9="";#WHILE (@GiveTemp4) {GiveTemp8=%replace(%db(@GiveAliases,@GiveTemp7),":",@GiveTemp7);#IF (@GiveTemp8) {GiveTemp3=%replace(@GiveTemp3,%concat("#[",@GiveTemp7,"]"),@GiveTemp8)} {GiveTemp9=%concat(@GiveTemp9,%copy(@GiveTemp3,1,@GiveTemp4));GiveTemp3=%right(@GiveTemp3,@GiveTemp4)};GiveTemp4=%regex(@GiveTemp3,"\#\[(.*?)\]",@GiveTemp7)};GiveTemp3=%concat(@GiveTemp9,@GiveTemp3);GiveTemp3=%replace(@GiveTemp3,"^","|");#IF (%pos("|",@GiveTemp3)) {#IF (%pos("-",@GiveTemp3)) {GiveTemp9=%word(@GiveTemp3,1,"-");#LOOP 2,%numwords(@GiveTemp3,1,"-") {#IF (%pos(%word(@GiveTemp3,%i,"-"),@GiveTemp9)) {GiveTemp3=%replace(@GiveTemp3,%word(@GiveTemp3,%i,"-"),"")}};#DELITEM GiveTemp3 {};GiveTemp3=%subchar(@GiveTemp3,"|-","^|");#DELITEM GiveTemp3 {};#IF (%numitems(@GiveTemp3)=1) {GiveTemp3=%replace(@GiveTemp3,"^","|")} {GiveTemp3=%replace(@GiveTemp3,"|","-")}}}} {GiveTemp3=@GiveTemp2}}}
#VAR Selfishness {0} {0}
#VAR Giving {} {}
#VAR GiveAliases {VPipepipe$[VPipe.number]EPipepipe$[EPipe.number]SPipepipe$[SPipe.number]pipe?[pipe\d+]-#[VPipe]-#[EPipe]-#[SPipe]monkArt?[knuckles]|?[crown]|?[armband]|?[collar]|?[diadem]mring?[Lucretian]epidermal$[Vials.:]\1refill_epidermal$[ElixRefill.:\2]ebralirthakhring?[Draconic]statArt?[bracelet]|?[girdle]|?[sash]|?[gauntlets]|?[boots]ering?[endurance]regenArt?[circlet]|ering|hring|mring}
#VAR GiveTemp {} {}
#VAR GiveTemp2 {} {}
#VAR GiveTemp3 {} {}
#VAR GiveTemp4 {} {}
#VAR GiveTemp5 {} {}
#VAR GiveTemp6 {} {}
#VAR GiveTemp7 {} {}
#VAR GiveTemp8 {} {}
#VAR GiveTemp9 {} {}
#VAR GiveTemp10 {} {}
#VAR GiveTemp11 {} {}
#TRIGGER "GiveGenerosity" {^{A feeling of generosity spreads throughout you.|No worries. You're not a selfish bastard as is.}$} {Selfishness=-1;#IF (%line="No worries. You're not a selfish bastard as is.") {#STATE GiveGenerosity 0;DoGiving}} "" {disable}
#COND {^You have recovered equilibrium.$} {DoGiving} {disable}
#TRIGGER {^You rub your hands together greedily.$} {Selfishness=1} "" {case|notrig}
#CLASS 0
_________________
The only good questions are the ones we have never answered before.
Search the Forums

Last edited by Vijilante on Sun Sep 23, 2007 5:28 pm; edited 2 times in total
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Wed Aug 29, 2007 3:37 am   
 
I forgot to mention some of the other syntaxes for the main Give alias in the first post. I did mention that both list formats are supported, this was done to handle the 'all' keyword and numbers. It works like this:
give book all myrrh|lobelia 100 moss|bloodroot|kola vijilante
Results in the following set of commands, without any special aliases:
Quote:
give book to vijilante
give all myrrh to vijilante
give all lobelia to vijilante
give 100 moss to vijilante
give 100 bloodroot to vijilante
give 100 kola to vijilante
I consider that pretty nifty.

Another feature is that if you have a record named Wearing formatted like I described the Inventory record above, then it will check for exact ID matches there. On a match it will "unwear" the item before giving. Since an exact match is required in the current coding I don't think that is a bad thing. If you feel differently you could change the logic in the DoGiving to stop that behavior.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Sep 23, 2007 5:33 pm   
 
New changes in:

I think there was abug in the old post where it wasn't handling inventory look ups properly, so that is fixed. The example aliases of monkArt work correctly now.

New syntax of "give thing*x vijilante" will now produce x "give thing to vijilante" commands.

And I also made it strip the word "to" when used in the command to make it a little more compatible with scripts that aren't aware of its presence.

Enjoy.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Salaric
Beginner


Joined: 10 Jun 2008
Posts: 17

PostPosted: Thu Jul 24, 2008 3:09 pm   
 
Any way to adjust it so it automatically tries to outr herbs? I'm looking at your script and just have no idea where I'd add that in
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Thu Jul 24, 2008 11:58 pm   
 
Wow, this is a blast from the past. I forgot I posted this script.

If you want to make it check for out rifting that would be done in the DoGiviing alias, and you would have to supply a list of words to check as riftable items.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Salaric
Beginner


Joined: 10 Jun 2008
Posts: 17

PostPosted: Fri Jul 25, 2008 3:33 pm   
 
awesome, thank you
Reply with quote
Salaric
Beginner


Joined: 10 Jun 2008
Posts: 17

PostPosted: Tue Jul 29, 2008 9:22 pm   
 
I've been trying and I can't get it to work, with outrifting items. Can you give a one item example of how you would add in the list in the dogiving?
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » Finished MUD Scripts All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

© 2009 Zugg Software. Hosted by Wolfpaw.net