• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Forum moderator applications are now open! Click here for details.
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

My Script Library

1,748
Posts
14
Years
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:

Code:
################################################################################
# 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 Map Generator.zip

More scripts and programs to come soon!

Credits:
Hansiec -- Creator of all scripts
Game Maker -- Program used to create the World Map Generator
 
Last edited:
1,748
Posts
14
Years
Mouse testing

Code:
################################################################################
# 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

Pokemon Crystal Rain Relased
476
Posts
17
Years
  • Age 33
  • Seen Dec 28, 2023
Thanks for scripts, i like the one wich reads script from url, i needed one like that thanks.
 
1,748
Posts
14
Years
Alright today I got something new, a socket handler!

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

Code:
################################################################################
# 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
    [email protected](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

Pokémon Island Creator
2,434
Posts
13
Years
  • Seen today
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).
 
1,748
Posts
14
Years
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.
 
Back
Top