Thread: [Essentials Script] Ruby Helper, scripting made easier!
View Single Post
Old July 1st, 2012 (6:28 PM).
Umbra's Avatar
Umbra Umbra is offline
Platinum Tier
Join Date: Aug 2009
Location: Nearby my feet.
Age: 19
Gender: Female
Nature: Calm
Posts: 1,729

Ruby helper is a script made to help people to script in xp much easier, instead of saying:


you can say:

give pokemon PBSpecies::BULBASAUR 1

but that's not all, you may input code from: strings, files, and urls!

you may add custom vars/phrases!

phrases are small lines of code to use (give as an example goes to a function call pbAddScene which takes 3 arguments, type1, arg1, arg2 pokemon is the first argument in my example and bulbasaur is the second then lastly 1 the level)

vars are variables (pokemon is a variable as an example again) pokemon = 'pokemon'


Version: 1.0
Author: Hansiec
Allows you to store very commonly stored data into a smaller string executable
by my Script Helper.

Help: phrases: a phrase usually calls a small code/function threads: stored scripts that were recently called custom_vars: like phrases but can be used alongside functions

Features: make preset codes/functions to help make scripts easier reads, stores, and executes threads reads threads from files reads threads from webpages allow in-game adding of phrases (best option for in-game updates through various features) build in encrypter (not the best) threads/phrases are saved alongside variables removes any unwanted data (like putting in: aaa will have no effect unless there is an argument needing aaa) but this means that you cannot have spaces in your variables, x = 10 will not work but x=10 will work

Apps: addPhrase(phrase, value) -- adds a new phrase into the list removePhrase(phrase) -- removes a phrase readUrl(url) -- executes a script from a url readFile(file name) -- executes a script from a file readThread(thread) -- executes a script from string encrpyt(string or integer, enc number) -- encrypts a string or integer decrypt(string or integer, enc number) -- decrypts a string or integer


Q: How do I call the main functions? A: For the main function: $RubyHelper.readThread(thread) for other functions: $RubyHelper.function

Q: Why should I use this script? A: You can make more advanced scripts easier (like mystery gift): "url_get url_here gift = url.split('\n'); give pokemon gift[0] gift[1]" Note that this does not check against multipul gifts, but it does work.

Q: How do I make a newline? (for something like an if statement) A: use either 2 functions: ~~ or ; (this is auto added with phrases only applied to threads not files/urls)

Q: How do I use functions? A: simmilar to normal but slightly different: functionName(argument amount), the argument amount indicates the amount of arguments in the function. (this only takes effect in the phrases section otherwise it is normal usage.)

Q: What are phrases? A: Phrases are preset codes/functions which can reduce the amount of work needed to make a script.

Q: What are threads? A: Threads are code inside strings (example: "phrase arg1" is a thread) threads can also include phrases and code together (example: "pl print('Bob')" will work)

Q: How do I use the encrypter? A: "encrypt string integer", the same arguments for decrypting

Q: What is the ~ in the threads? A: This is mostly for variables, what it does though is to notify not to add the ; at the end of the phrase.

Q: I get an error with the url functions! A: Insert the socket functions included in the demo (poke essentials also includes this)

Q: I get an error with using phrases! A: Many things can go wrong here but try these: spelling (string still need a '' or "" with them), you can't use phrases as arguments examples: (encrypt url_get '' 10) is wrong use this: (url_get '' encrypt url 10), you may however use custom vars


# var_name => value (no spaces in the name) $custom_vars = { "url" => "$url", # url variable "latest_thread" => "getThread($threads.length-2)", # the last thread besides this thread "pokemon" => "'pokemon'", "badge" => "'badge'", "item" => "'item'", "egg" => "'egg'", "money" => "'money'" # "var_name" => "value (strings still need to be defined with '' or "")" }

# sample: "give_pokemon PBSpecies::BULBASAUR 2" $phrases = { "give" => "pbAddScene(3)", "makes" => "==~", # used with an if "done" => "end", # another addition, this allows you to put in done "give_pokemon" => "pbAddPokemon(2)", # give's a pokemon "give_item" => "Kernel.pbReceiveItem(1)", # give's an item "give_egg" => "pbGenerateEgg(1)", # give's an egg "encrypt" => "encrypt(2)", # encrypt's string/integer "decrypt" => "decrypt(2)", # decrypt's a string/integer "url_get" => "$url = pbDownloadToString(1)", # gets a url "url_post" => "$url = pbPostDataToString(2)", # sends post to a url and get's the output "url_to_file" => "pbPostToFile(2)", # same as post but saves the text in a file "print" => "print~", # print function 0 = string "p" => "print~", # print function # these are test functions, they may be delted at your own will "pl" => "print('This is a test to show you how this works!')", "pl2" => "print('source code of thread: '+getThread())", # "phrase" => "function or code (argument amount)" } $threads = [] # used to store scripts that were called PHRASEVAR = 24 THREADVAR = 25 class ScriptHelper

def addPhrase(phrase,value) # Adds a new phrase to the list $phrases[phrase] = value end

def saveStatus() # save the Phrase/Thread status $game_variables[THREADVAR] = $threads $game_variables[PHRASEVAR] = $phrases end

def loadStatus() # load the Phrase/Thread status if $game_variables[PHRASEVAR] != 0 $phrases = $game_variables[PHRASEVAR] $threads = $game_variables[THREADVAR] end end

def removePhrase(phrase) # delete a phrase $phrases[phrase]=nil end

def saveThread(thread) # saves a thread saveStatus() $threads.push(thread) end

def getThread(id=-1) # get's a thread from the saved list return $threads[id] if $threads.length-1 >= id and id > -1 return $threads[$threads.length-1] end

def splitThread(thread) # splices the thread into readable strings saveThread(thread) # save's the thread str = thread.split(" ") # split the thread into different strings return str end

def readUrl(url) act=pbDownloadToString(url).split("\n") string=act[0] for i in 0..act.length-2 string+="; #{act[i+1]}" end self.readThread(string) end

def readFile(fname) act=IO.readlines(fname) string=act[0] for i in 0..act.length-2 string+="; #{act[i+1]}" end self.readThread(string) end

def readThread(thread) # reads the thread then executes the thread. for i in $custom_vars.keys eval(i+" = "+$custom_vars[i]) end loadStatus() str = splitThread(thread) for i in 0..str.length-1 oth=str[i].split(".") if $phrases[str[i]] != nil str[i] = $phrases[str[i]] nx = "o" nx[0] = str[i][str[i].length-1] if nx == "~" str[i]=str[i].split("~")[0] else str[i]="#{str[i]};" end num=0 for y in 0..str[i].length-1 x="a" x[0]=str[i][y] for xx in 0..9 if x == "#{xx}" num = xx break end end end if num != 0 ary=str[i].split("(") new=ary[0]+"("+str[i+1].to_s for j in 0..num-2 if str[i+(j+2)] == nil break else new+=","+str[i+(j+2)].to_s end end new+=")" str[i]=new end elsif $phrases[oth[0]] != nil nx = "o" str[i]=$phrases[oth[0]] nx[0] = str[i][str[i].length-1] if nx == "~" str[i]=$phrases[oth[0]]+"."+oth[1] str[i]=str[i].split("~")[0]+str[i].split("~")[1] else str[i]=$phrases[oth[0]]+"."+oth[1] str[i]+=";" end end end code="" string = false string2 = false _if = false for k in str for s in 0..k.length # string testing must be done before testing the rest. x="1" x[0]=k[s] if k[s] != nil if x == "'" if string == true string = false else string = true end break end if x == '"' if string2 == true string2 = false else string2 = true end break end if x == ";" or k == "~~" or k == "\n" or k == "then" _if = false end end for l in 0..k.length x="1" x[0]=k[l] if k[l] != nil allow = false for aaa in $phrases.keys if $phrases[aaa] == k or $phrases[aaa] == k+"~" allow = true break end end if k == "if" _if = true end if _if == true or allow == true or string == true or string2 == true or x == "$" or k == "~~" or x == ";" or x == "=" or x == "(" or x == ")" or x == "{" or x == "}" or x == "[" or x == "]" or x == "'" or x == '"' if k == "~~" or k == "\n" k = " ;" end code = "#{code} #{k}" break end end end eval(code) return true #rescue return false end


# not the best encrypter but it does somewhat encrypt stuff (only string/integers)

def encrypt(str,val) val = val.to_i if str.is_a?(String) new="" for i in 0..str.length-1 new+=str[i]+val+((i/2).floor) end else new = str * val + 17 / 8 * 88 - val + str * 1142 - 987 - (val+str*2) end return new end

def decrypt(str,val) val = val.to_i if str.is_a?(String) new="" for i in 0..str.length-1 new+=str[i]-val-((i/2).floor) end else new = (val+str*2) + 987 + 1142 / str - val + 88 / 8 * 17 - val / str end return new end

# some extras

def pbAddScene(type, arg1, arg2) if type == "pokemon" # pokemon pbAddPokemon(arg1, arg2) elsif type == "item" # item Kernel.pbReceiveItem(arg1) elsif type == "egg" # egg if $ < 6 pbGenerateEgg(arg1) else Kernel.pbMessage(_INTL("Not enough space in your party for the egg.")) end elsif type == "badge" # badge $Trainer.badges[arg1] == arg2 elsif type == "money" # money $ += arg1 end end

# finally we set the variable

$RubyHelper =

Reply With Quote