The PokéCommunity Forums  

Go Back   The PokéCommunity Forums > Creative Discussions > Game Development > Scripts & Tutorials
Sign Up Rules/FAQ Live Battle Blogs Mark Forums Read

Notices

Scripts & Tutorials This forum is for scripts and code, as well as all kinds of tutorials, software, tools and so forth. Remember to give credit!
The thread revival limit does not apply here.


Reply
 
Thread Tools
  #1    
Old October 3rd, 2012, 10:13 AM
Umbreon's Avatar
Umbreon
Community Supporter
 
Join Date: Aug 2009
Location: Nearby my feet.
Age: 17
Gender: Male
Nature: Calm
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/4008392...0Generator.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 by Umbreon; October 3rd, 2012 at 10:21 AM.
Reply With Quote
  #2    
Old October 4th, 2012, 07:31 AM
Umbreon's Avatar
Umbreon
Community Supporter
 
Join Date: Aug 2009
Location: Nearby my feet.
Age: 17
Gender: Male
Nature: Calm
Alright script pack 2:

Encryption
Ini reader
Pseudo Generator
Attached Files
File Type: zip Script Pack.zip‎ (39.0 KB, 27 views) (Save to Dropbox)
Reply With Quote
  #3    
Old October 4th, 2012, 08:30 AM
Rick1234's Avatar
Rick1234
Hidden in the shadows, for now
 
Join Date: Mar 2010
Location: Ponyville, Equestria
Age: 16
Gender: Male
Nature: Quiet
Hansiec this is great work as usual :D
Reply With Quote
  #4    
Old October 4th, 2012, 10:42 AM
Umbreon's Avatar
Umbreon
Community Supporter
 
Join Date: Aug 2009
Location: Nearby my feet.
Age: 17
Gender: Male
Nature: Calm
Quote:
Originally Posted by Rick1234 View Post
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.
Reply With Quote
  #5    
Old October 4th, 2012, 12:24 PM
Rick1234's Avatar
Rick1234
Hidden in the shadows, for now
 
Join Date: Mar 2010
Location: Ponyville, Equestria
Age: 16
Gender: Male
Nature: Quiet
Quote:
Originally Posted by hansiec View Post
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
Reply With Quote
  #6    
Old October 4th, 2012, 01:04 PM
Umbreon's Avatar
Umbreon
Community Supporter
 
Join Date: Aug 2009
Location: Nearby my feet.
Age: 17
Gender: Male
Nature: Calm
Quote:
Originally Posted by Rick1234 View Post
I will :D ;D You really should make a GTS system for Pokemon essentials xD
I have one pending currently.
Reply With Quote
  #7    
Old October 4th, 2012, 03:50 PM
Rick1234's Avatar
Rick1234
Hidden in the shadows, for now
 
Join Date: Mar 2010
Location: Ponyville, Equestria
Age: 16
Gender: Male
Nature: Quiet
Quote:
Originally Posted by hansiec View Post
I have one pending currently.
Nice :D Happy early birthday btw I will forget xD
Reply With Quote
  #8    
Old October 5th, 2012, 07:30 AM
Umbreon's Avatar
Umbreon
Community Supporter
 
Join Date: Aug 2009
Location: Nearby my feet.
Age: 17
Gender: Male
Nature: Calm
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
Reply With Quote
  #9    
Old October 5th, 2012, 08:47 AM
venom12's Avatar
venom12
Pokemon Crystal Rain Relased
 
Join Date: Sep 2006
Age: 23
Gender: Male
Nature: Adamant
Send a message via Windows Live Messenger to venom12
Thanks for scripts, i like the one wich reads script from url, i needed one like that thanks.
__________________



Reply With Quote
  #10    
Old October 5th, 2012, 08:50 AM
Umbreon's Avatar
Umbreon
Community Supporter
 
Join Date: Aug 2009
Location: Nearby my feet.
Age: 17
Gender: Male
Nature: Calm
Yeah, I thought that people would like that one, also for safety you can also encrypt the url's script!
Reply With Quote
  #11    
Old October 6th, 2012, 09:04 AM
Umbreon's Avatar
Umbreon
Community Supporter
 
Join Date: Aug 2009
Location: Nearby my feet.
Age: 17
Gender: Male
Nature: Calm
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
    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!
Reply With Quote
  #12    
Old October 6th, 2012, 03:36 PM
FL's Avatar
FL
Pokémon Island Creator
 
Join Date: Sep 2010
Gender: Male
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).
__________________
Reply With Quote
  #13    
Old October 7th, 2012, 10:06 AM
Umbreon's Avatar
Umbreon
Community Supporter
 
Join Date: Aug 2009
Location: Nearby my feet.
Age: 17
Gender: Male
Nature: Calm
Quote:
Originally Posted by FL . View Post
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.
Reply With Quote
Reply
Quick Reply

Sponsored Links
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Minimum Characters Per Post: 25



All times are UTC -8. The time now is 10:07 AM.


Style by Nymphadora, artwork by Sa-Dui.
Like our Facebook Page Follow us on Twitter © 2002 - 2014 The PokéCommunity™, pokecommunity.com.
Pokémon characters and images belong to The Pokémon Company International and Nintendo. This website is in no way affiliated with or endorsed by Nintendo, Creatures, GAMEFREAK, The Pokémon Company or The Pokémon Company International. We just love Pokémon.
All forum styles, their images (unless noted otherwise) and site designs are © 2002 - 2014 The PokéCommunity / PokéCommunity.com.
PokéCommunity™ is a trademark of The PokéCommunity. All rights reserved. Sponsor advertisements do not imply our endorsement of that product or service. User generated content remains the property of its creator.