Luxie

multi.lic for GemStoneIV and DragonRealms with Lich

Sep 11th, 2019
158
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. =begin
  2. Helps to sell gem jars, purchase items, etc. It lets you string together multiple commands
  3. to repeat the specified multiple times.
  4.  
  5. Put the number of times first, a COMMA seperate each command after that for each iteration.
  6. No spaces, just a comma.
  7.  
  8.     author: Luxelle
  9.     game:   any
  10.     tags:   multifput, input, buy, repeating, multiple command entry, empty jars, etc
  11.  
  12.     Usage:  ;multi 6,shake my jar,sell diamond
  13.             ;multi 10,order 1,buy,stow potion
  14.         It will also work with a script:
  15.             ;multi 3,get something,;scripname,stow something
  16.  
  17.     Note:   Thank you to to Mister Xanlin for the suggestion and code to make it work with scripts, too.
  18.  
  19.     Changelog:
  20.           Version 1.1 - Prettied up help  ;multi help
  21.           Version 1.0 - initial release. Xanlan MADE me do it. 9 July 2018
  22. =end
  23.  
  24. if script.vars[0] == "help"
  25.     respond "Use a comma to separate number of times,command 1,command 2,etc"
  26.     respond " "
  27.     respond "For example:"
  28.     respond ";multi 2,order 1,buy,stow amulet"
  29.     respond "Will do the specified commands 2 times: order 1, buy, stow"
  30.     respond " "
  31.     respond "It will launch a script for you, too:"
  32.   respond ";multi 2,get diamond in pouch,;loresing,put diamond in sack"
  33.     respond " "
  34. end
  35.  
  36. unless script.vars[0]
  37.     respond "Use a comma to separate number of times,command 1,command 2,etc"
  38.     respond " "
  39.     respond "For example:"
  40.     respond ";multi 2,order 1,buy,stow amulet"
  41.     respond "Will do the specified commands 2 times: order 1, buy, stow"
  42.     respond " "
  43.     respond "It will launch a script for you, too:"
  44.   respond ";multi 2,get diamond in pouch,;purify,put diamond in sack"
  45.     respond " "
  46. else
  47.  
  48. #Mister Xanlin's contribution to make it better:
  49.  #in case the user uses a semicolon
  50.   script.vars[0] = script.vars[0] =~ /,/ ? script.vars[0] : script.vars[0].gsub(';',',')
  51.   indiv = script.vars[0].split(',')
  52.   #in case the user puts the num of times at the end instead of the beginning
  53.   num = indiv[0] =~/^\d+$/ ? indiv.shift.to_i : indiv.pop.to_i
  54.   #num.times {multifput indiv}
  55.   num.times {
  56.     indiv.each{ |thing|
  57.       if thing !~ /^;/
  58.         fput thing
  59.       else
  60.         scriptything = thing[1..-1].split(' ')
  61.         Script.run(scriptything[0], scriptything[1..-1].join(" "))
  62.       end
  63.       }
  64.   }
  65.  
  66. end
RAW Paste Data