[XP] Script Helper

Started by nathmatt, August 23, 2010, 11:05:38 pm

Previous topic - Next topic

nathmatt

August 23, 2010, 11:05:38 pm Last Edit: August 24, 2010, 06:06:15 am by nathmatt
Script Helper
Authors: Nathmatt
Version: 1.5
Type: quick commands
Key Term: Scripting tool



Introduction

useful command calls


Features


  • wait
  • delay
  • map name
  • save
  • load
  • facing terrain tag



Screenshots

no screen shot needed


Demo

no demo


Script

Spoiler: ShowHide
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Script_Helper by Nathmatt
# Version: 1.5
# Type: quick commands
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
#  
#  This work is protected by the following license:
# #----------------------------------------------------------------------------
# #  
# #  Creative Commons - Attribution-NonCommercial-ShareAlike 3.0 Unported
# #  ( http://creativecommons.org/licenses/by-nc-sa/3.0/ )
# #  
# #  You are free:
# #  
# #  to Share - to copy, distribute and transmit the work
# #  to Remix - to adapt the work
# #  
# #  Under the following conditions:
# #  
# #  Attribution. You must attribute the work in the manner specified by the
# #  author or licensor (but not in any way that suggests that they endorse you
# #  or your use of the work).
# #  
# #  Noncommercial. You may not use this work for commercial purposes.
# #  
# #  Share alike. If you alter, transform, or build upon this work, you may
# #  distribute the resulting work only under the same or similar license to
# #  this one.
# #  
# #  - For any reuse or distribution, you must make clear to others the license
# #    terms of this work. The best way to do this is with a link to this web
# #    page.
# #  
# #  - Any of the above conditions can be waived if you get permission from the
# #    copyright holder.
# #  
# #  - Nothing in this license impairs or restricts the author's moral rights.
# #  
# #----------------------------------------------------------------------------
#
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Do not make any script require this one if you are making a script just add
# what your using to ur script or add this to ur script.
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
# Calls:
#
# $script_helper.wait(frames)                 waits set frames then returns true
# $script_helper.delay(frames)                freezes set frames
# $script_helper.map_name                     returns the map name
# $script_helper.transfer_player(m,x,y,d=2)   takes you to defined location
# $script_helper.save(name,i)                 saves in the configed folder
#                                             with the definmed name and index
# $script_helper.load(name,i)                 loads in the configed folder
#                                             with the definmed name and index
# $script_helper.get_facing_terrain_tag       return the tag yor facing
#:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=:=
module Script_Helper
 
 module Config
   Save_Path = 'Chapter_Saves'
 end
 
 class Processor
   
   def initialize
     @map_infos = load_data('Data/MapInfos.rxdata')
     @map_infos.keys.each {|key| @map_infos[key] = @map_infos[key].name}
     @common_events,@ov_maps,@title_screens = [],[],[]
   end
     
   def wait(frames)
     sec = frames*40
     return Graphics.frame_count % sec == sec - 1
   end
   
   def delay(frames)
     while !wait(frames)
       Graphics.update
       Input.update
     end
   end
   
   def map_name
     return @map_infos[$game_map.map_id]
   end
   
   def transfer_player(m,x,y,d=2)
     $game_temp.player_transferring = true
     $game_temp.player_new_map_id = m
     $game_temp.player_new_x = x
     $game_temp.player_new_y = y
     $game_temp.player_new_direction = d
     $scene = Scene_map.new
   end
     
   def save(name,i)
     filename = "#{Config::Save_Path}/#{name}#{i}.rxdata"
     file = File.open(filename, "wb")
     characters = []
     (0...$game_party.actors.size).each{|i|actor = $game_party.actors[i]
     characters.push([actor.character_name, actor.character_hue])}
     Marshal.dump(characters, file)
     Marshal.dump(Graphics.frame_count, file)
     $game_system.magic_number = $data_system.magic_number
     Marshal.dump($game_system, file)
     Marshal.dump($game_switches, file)
     Marshal.dump($game_variables, file)
     Marshal.dump($game_self_switches, file)
     Marshal.dump($game_screen, file)
     Marshal.dump($game_actors, file)
     Marshal.dump($game_party, file)
     Marshal.dump($game_troop, file)
     Marshal.dump($game_map, file)
     Marshal.dump($game_player, file)
     file.close
   end
   
   def load(name,i)
     filename = "#{Config::Save_Path}/#{name}#{i}.rxdata"
     file = File.open(filename, "rb")
     characters = Marshal.load(file)
     Graphics.frame_count = Marshal.load(file)
     $game_system        = Marshal.load(file)
     $game_switches      = Marshal.load(file)
     $game_variables     = Marshal.load(file)
     $game_self_switches = Marshal.load(file)
     $game_screen        = Marshal.load(file)
     $game_actors        = Marshal.load(file)
     $game_party         = Marshal.load(file)
     $game_troop         = Marshal.load(file)
     $game_map           = Marshal.load(file)
     $game_player        = Marshal.load(file)
     $Script_Helper      = $game_system.script_helper
     file.close
     $game_system.bgm_play($game_system.playing_bgm)
     $game_system.bgs_play($game_system.playing_bgs)
   end
   
 end
 
 def get_facing_terrain_tag
   g = $game_player
   x,y,d = g.x,g.y,g.d
   x += (d == 6 ? 1 : d == 4 ? -1 : 0)
   y += (d == 2 ? 1 : d == 8 ? -1 : 0)
   return terrain_tag(x,y)
 end
 
end

$script_helper = Script_Helper::Processor.new




Instructions

place above any script calling these commands
in script


Compatibility

no compatibility issues


Credits and Thanks


  • Nathmatt



Author's Notes

post here with any suggestions or feed back
Join Dead Frontier
Sorry, I will no longer be scripting for RMXP. I may or may not give support for my scripts. I don't have the will to script in RGSS anymore.
My script


Blizzard

I think this is kind of pointless. Both the map and the battle scene have waiting time already implemented and you don't really need it anywhere else. :/
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

SBR*

Quote from: Blizzard on August 24, 2010, 02:16:40 am
I think this is kind of pointless. Both the map and the battle scene have waiting time already implemented and you don't really need it anywhere else. :/


Plus this is really easy to make yourself. And more as a tip, this is even better:

def delay(frames, *args)
  frames.times {
  Graphics.update
  Input.update
  args.each {|i| i.update}
  }
end


I even added an *args, so other things can be updated during the delay.

Oh, and doesn't your

def wait(frames)
  Graphics.frame_count % frames == frames - 1
end


just return a boolean? Shouldn't it be something like this:

def wait(frames)
  frames.times {Graphics.update}
end


The Graphics.update is necessary to keep the delay.

And the methods delay and wait can be one method; just keep *args empty when you want wait.

Zeriab

Eek.

I am not sure I like adding a method to all objects which makes the game freeze for x number of frames.
What was the purpose of the wait method? I don't see the purpose as it is now  :???:

Since it doesn't use an information about the object you could just as well put it into a module:
module UselessUtil
  module_function
  def wait(frames)
    frames.times {
       Graphics.update
       Input.update
    }
  end
end


*hugs*

ForeverZer0

In the CBS I'm creating I made a delay method someting like this...

def delay(frames)
    frames.times {
        Graphics.update
        Input.update
        $scene.update (because it is being called from another class)
    }
end


This basically will just keep it from executing anything below this line in the method until the frame count is up, without freezing the game or anything.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.