PDA

View Full Version : [Essentials script] My Script Library


Umbreon
October 3rd, 2012, 10:13 AM
Intro:

As it is soon my birthday, I shall share some scripts (and programs) I have made for anyone to use, I will slowly upload them as I get the chance.


Current Scripts/Programs:

World Map Generator (program): Generates realistic looking world maps in seconds!
Class To String (rgss script): Convert any class to a string (also supports compression)
LoadFileToString (rgss script): Ummm this can load .png files (actually any file type) into a string in rmxp.
DLC script (rgss script): only 4 lines of code, this can download any file to a proper file (as long as you have the exact link of it and it's not too big)
Json reader (rgss script): Creates and parses Json data

Scripts:


################################################################################
# Class To String and String To Class
# By Hansiec
# Safely Converts a class to a compressed string and vise-versa
# If it failed it returns "Failed to convert" and also popups up a message.
# Uses:
# Fast compression (and storage) of classes (no need to input any data)
# Fast decompression of classes (never fails to load properly!)
# This could be used in some systems which requires to send sensitive data (or
# otherwise difficult to handle data) Example: Pokemon, Trainers, Ect.
################################################################################

def class_to_string(class_var)
save_data(class_var,"Temp_File")
data = ""
file = File.open("Temp_File", 'rb')
data += file.read() while !file.eof?
file.close
File.delete("Temp_File")
return compress(data)
rescue
print "Failed to convert #{class_var}"
return "Failed to convert #{class_var}"
end

def string_to_class(string)
file = File.open("Temp_File", 'wb')
file.write(decompress(string))
file.close
ret = load_data("Temp_File")
File.delete("Temp_File")
return ret
rescue
print "Failed to convert #{string}"
return "Failed to convert #{string}"
end


def compress(string)
z = Zlib::Deflate.new(2)
dst = z.deflate(string, Zlib::FINISH)
z.close
dst
end

def decompress(string)
zstream = Zlib::Inflate.new
buf = zstream.inflate(string)
zstream.finish
zstream.close
buf
end

################################################################################
# LoadFileToString
# By Hansiec
# Uses:
# Can load and save files from/to your computer and also allows you to compress
# or decompress
################################################################################

def loadFile(file,compress_d=0)
return if file == ""
data = ""
file = File.open(file, 'rb')
data += file.read() while !file.eof?
file.close
data = compress(data) if compress_d == 1
data = decompress(data) if compress_d == 2
return data
end

def saveFile(file,data,compress_d=0)
return if file == "" || data == ""
data = compress(data) if compress_d == 1
data = decompress(data) if compress_d == 2
file = File.open(file, 'wb')
file.write(data)
file.close
end

def compress(string)
z = Zlib::Deflate.new(2)
dst = z.deflate(string, Zlib::FINISH)
z.close
dst
end

def decompress(string)
zstream = Zlib::Inflate.new
buf = zstream.inflate(string)
zstream.finish
zstream.close
buf
end

################################################################################
# Downloaded Content Script
# By Hansiec
# Uses:
# Not really any since this is actually a 4 lined script which almost anyone can
# make. You cannot yet download HUGE files as of the hangup will uccor.
################################################################################


def pbDownloadContent(url, filename="")
filename = url.split("/")[url.split("/").length-1] if filename == ""
pbDownloadData(url,filename)
end

################################################################################
# Json Reader/Writer
# By Hansiec
# Uses:
# Converts data to the Json format and loads data from the Json format
# Input any normal data type (String,Integer,Array,Hash, or Boolean) and my
# System converts it into Json!
################################################################################


def toJson(data,name="")
ret = ""
ret = name+"=" if name != ""
if data.is_a?(String)
ret+="\""+data+"\""
elsif data.is_a?(Numeric)
ret+=data.to_s
elsif data.is_a?(Array)
ret+="["
data2=""
for i in 0..data.length-1
if data2 == ""
data2=toJson(data[i])
else
data2+=","+toJson(data[i])
end
end
ret+=data2+"]"
elsif data.is_a?(Hash)
ret+="{"
data2=""
for i in data.keys
if data2 == ""
data2='"'+i+'"'+"=>"+toJson(data[i])
else
data2+=","+'"'+i+'"'+"=>"+toJson(data[i])
end
end
ret+=data2+"}"
elsif data == false
ret+="false"
elsif data == true
ret+="true"
elsif data == nil
ret+="nil"
else
return 'Cannot convert!'
end
return ret
end

def fromJson(data)
return eval(data)
end



Programs:

World Map Generator: https://rapidshare.com/files/4008392752/World%20Map%20Generator.zip

More scripts and programs to come soon!

Credits:
Hansiec -- Creator of all scripts
Game Maker -- Program used to create the World Map Generator

Umbreon
October 4th, 2012, 07:31 AM
Alright script pack 2:

Encryption
Ini reader
Pseudo Generator

~Angel~
October 4th, 2012, 08:30 AM
Hansiec this is great work as usual :D

Umbreon
October 4th, 2012, 10:42 AM
Hansiec this is great work as usual :D

thanks, I still have some more I can release tomorrow and for a few days actually, so check in daily.

~Angel~
October 4th, 2012, 12:24 PM
thanks, I still have some more I can release tomorrow and for a few days actually, so check in daily.

I will :D ;D You really should make a GTS system for Pokemon essentials xD

Umbreon
October 4th, 2012, 01:04 PM
I will :D ;D You really should make a GTS system for Pokemon essentials xD

I have one pending currently.

~Angel~
October 4th, 2012, 03:50 PM
I have one pending currently.

Nice :D Happy early birthday btw I will forget xD

Umbreon
October 5th, 2012, 07:30 AM
Mouse testing


################################################################################
# Simple mouse Testing
# By Hansiec
# Uses:
# Shows some usage of Essentials' built in mouse functions
################################################################################

def is_pressing_mouse_left?
return Input.pressex?(Input::LeftMouseKey)
end

def is_clicking_mouse_left?
return Input.pressex?(Input::LeftMouseKey)
end

def is_pressing_mouse_right?
return Input.pressex?(Input::RightMouseKey)
end

def is_clicking_mouse_right?
return Input.pressex?(Input::RightMouseKey)
end

def get_mouse_position
pos = Mouse.getMousePos
if pos == nil
print "Mouse is not on the screen!"
else
print "Your mouse is at X: #{pos[0]} Y: #{pos[1]}"
end
return pos
end

get_mouse_position


And some other scripts:
https://rapidshare.com/files/3556486514/Scripts.zip

venom12
October 5th, 2012, 08:47 AM
Thanks for scripts, i like the one wich reads script from url, i needed one like that thanks.

Umbreon
October 5th, 2012, 08:50 AM
Yeah, I thought that people would like that one, also for safety you can also encrypt the url's script!

Umbreon
October 6th, 2012, 09:04 AM
Alright today I got something new, a socket handler!

It's easy to use but needs some serious updates to actually work properly:


################################################################################
# Sockets Extension
# By Hansiec
# Uses:
# Connections though networking Includes basic functions
# Comes alongside with a few basic functions that could be helpful to some people
# Features:
# *Connect to any server
# *Choose a "Host" which is a player not a server (which means you do not need
# to handle your servers as people will need to setup their own)
# *Easy to use data sharing (by using the send_data(receiver,data) function)
# *Comes with a few functions built it such as item handling
# *Specify this player only messages.
# *Easily add data (by using the add_data(data) function)
# *Easily specify a player to send data to (by using the specify_player(player,
# data) function)
# TODO:
# * Add usernames
# * Add passwords
# * Add permanent user ids
# * Add functions to get a player's id
################################################################################

class SocketHandler
attr_accessor :socket
attr_accessor :data
attr_accessor :connection_handle
attr_accessor :host
attr_accessor :new_data

# Startup the system
def initialize(host, port, host2)
@socket=TCPSocket.new(host, port)
@data = []
@connection_handle = rand(9999999)
@host = host2
@new_data = ""
end

# so you want to send some data? specify a user and data (-1 is for everyone)
def send_data(receiver,data)
@socket.send(data)
end

# Update the system
def update
data=@socket.recv(0xfff).split("\n")
parse_data(data)
if @host
send_data(-1, @new_data)
reset_data
end
end

def parse_data(data)
for line in data
# First we must check if we may access the data
if line.include?("p=#{get_handle}") || line.include?("p=-1")
if line.include?("#{get_handle}")
line=line.split("p=#{get_handle}")[1]
else
line=line.split("p=-1")[1]
end
if !edit_variable(line)
if !edit_items(line)
if !edit_pokemon(line)
edit_misc(line)
end
end
end
# End of checks
end
end
end

# Handles variable/switch data
def edit_variable(line)
if line.include?("var")
line=line.split("var")[1]
$game_variables[line.replace("var").split(",")[0].to_i]=line.split(",")[1].to_i
return true
elsif line.include?("swt")
line=line.split("swt")[1]
$game_switches[line.replace("swt").split(",")[0].to_i]=split(",")[1].to_i
return true
end
return false
end

# Handles item data
def edit_items(line)
if line.include?("give_item")
line=line.split("give_item")[1]
eval("pbReceiveItem("+line+")")
return true
elsif line.include?("delete_item")
line=line.split("delete_item")[1]
eval("$PokemonBag.pbDeleteItem("+line+")")
return true
end
return false
end

# Handles pokemon data
def edit_pokemon(line)
if line.include?("give_pokemon")
line=line.replace("give_pokemon")
if line.include?("silent")
line=line.split("give_pokemon")[1]
pbAddPokemonSilent(line.split(",")[0], line.split(",")[1])
else
pbAddPokemon(line.split(",")[0], line.split(",")[1])
end
return true
elsif line.include?("take_pokemon")
line=line.split("take_pokemon")[1]
pbRemovePokemonAt(line.replace("take_pokemon").to_i)
return true
end
return false
end

# Handles un-classed data
def edit_misc(line)
if line.include?("message")
Kernel.pbMessage(_INTL(line.split("message ")[1]))
return true
end
return false
end

# resets the data to the default settings
def reset_data
@new_data = ""
end

# adds data to send
def add_data(data)
@new_data+="\n"+data
end

# adds player specifics on the data (use once per data)
def specify_player(player,data)
return "p=#{player} data"
end

# Returns the player's connection handle
def get_handle
return @connection_handle
end

end

# You may delete these lines below! REALLY DO SO!
$s=SocketHandler.new("localhost", 3306, true)
$s.parse_data(["p=-1 message This is a test socket!", "p=#{$s.get_handle} message Testing specific player only!"])


the update function is rather bare for now, I hope you all enjoy this one!

FL
October 6th, 2012, 03:36 PM
Nice script, I can't believe that I can't think of class_to_string/string_to_class before.

The PokemonBoxManager script section (only in older versions) had a Json reader (I am not sure).

Umbreon
October 7th, 2012, 10:06 AM
Nice script, I can't believe that I can't think of class_to_string/string_to_class before.

The PokemonBoxManager script section (only in older versions) had a Json reader (I am not sure).

I mainly made the class_to_string to ease the use of systems such as gts, the others I made either a while ago, randomly (the Json script for example), or I thought it could help people (World Map Generator for example).

Also, I had no idea the PokemonBoxManager script had a Json reader.