Chaos Project

RPG Maker => RPG Maker Scripts => RMXP Script Database => Topic started by: mad.array on March 23, 2013, 07:25:15 pm

Title: [XP] mad.array Mini add-ons
Post by: mad.array on March 23, 2013, 07:25:15 pm
mad.array Mini Add-ons
Authors: mad.array
Version: 1.0
Type: Snippets
Key Term: Misc Add-on



Introduction

A collection of bite sized add-ons that I've tinkered with. Look at the features a few dozen pixels down to see the list. Also ignore the fact that taking the hyphen into account, the acronym for this script is MaMa.


Features




Screenshots

As usual, I have none.


Script

Insert somewhere above Main.
Spoiler: ShowHide

#==============================================================================
# In Battle Event Removal
#------------------------------------------------------------------------------
#  Allows events to be deleted during a battle, not a frame before the
#  transition, not a frame afterwards.
#
#  To use it, use a 'Call Script' command before a battle. Then type:
#
#      $game_temp.battle_ids = [x,y,z, etc]
#
#  Inside the array, place the ids of the events to be deleted. When the battle
#  begins, the events will be removed. This works in the same way as the
#  'Erase Event' command, so make sure you set a switch or use some other method
#  to permanently remove the events.
#==============================================================================


class Game_Temp
 
 attr_accessor :battle_ids
 
 alias init_battle_ids initialize
 def initialize
   init_battle_ids
   @battle_ids = []
 end
end

class Scene_Map
 
 alias call_battle_ids call_battle
 def call_battle
   call_battle_ids
   for i in 0...$game_temp.battle_ids.length
     $game_map.events[$game_temp.battle_ids[i]].erase
   end
   $game_temp.battle_ids = []
   $game_map.need_refresh = true
 end
 
end

#==============================================================================
# Event Mover & Perma-Delete
#------------------------------------------------------------------------------
#  Allows you to set a new position for an event without running auto run scripts.
#
#  You can do this from a 'Set move route' command, but it will only work
#  for the event that is being controlled by the move route command. Just use
#  The 'script' option in the move route planner and type one of these:
#
#   'set_to_current_pos' - Sets the Events new position to where it currently is
#   so that next time the map loads, that's where the event will be.
#
#   'set_to_this_pos(x,y)' - This will set the position of the event to the
#   x and y coordinates specified.
#
#   'delete_event' - Permanently 'deletes' the event. Actually it doesn't, it
#   just erases it every time the map is loaded.
#
#
#==============================================================================

class Game_Map

 alias event_move_setup setup
 def setup(map_id)
   event_move_setup(map_id)
   for i in @map.events.keys
     key = [map_id, i]
     if $game_self_position != nil
       if $game_self_position[key] != nil
         stored_x = $game_self_position[key][0]
         stored_y = $game_self_position[key][1]
         stored_dir = $game_self_position[key][2]
         stored_del = $game_self_position[key][3]
         if stored_del == true
           @events[i].erase
         else
           @events[i].moveto(stored_x,stored_y)
           @events[i].direction = stored_dir
         end
       end
     end
   end
 end
 
end


class Game_Event
 
 attr_accessor :direction
   
 def set_to_current_pos
   if self != $game_player
     key = [$game_map.map_id, @id]
     $game_self_position[key] = [@x, @y, @direction, false]
   end
 end
 
 def set_to_this_pos(newx,newy)
   if self != $game_player
     key = [$game_map.map_id, @id]
     $game_self_position[key] = [newx,newy,@direction, false]
   end
 end
 
 def delete_event
   if self != $game_player
     key = [$game_map.map_id, @id]
     $game_self_position[key] = [@x,@y,@direction,true]
     self.erase
   end
 end
 
end

#==============================================================================
# ** Game_SelfStoredPos
#------------------------------------------------------------------------------
#  This class handles events stored locations.
#==============================================================================

class Game_SelfStoredPos

 def initialize
   @data = {}
 end

 def [](key)
   return @data[key]
 end

 def []=(key, value)
   @data[key] = value
 end
end

class Scene_Title
 
 alias stored_main main
 def main
   stored_main
   $game_self_position = Game_SelfStoredPos.new
 end
end

#==============================================================================
# Global Self Switch Control
#------------------------------------------------------------------------------
#  This script lets you control Self Switches on the current map from ANY event!
#  Using 'Call Script', just type 'SetSelfSwitch(e,s,v)' where e is the Event ID,
#  s is the Switch ("A","B","C" or "D") and v is true or false (no speech marks!)
#
#  Also, by typing 'InvertSelfSwitch(e,s)' you can turn a self switch off if it
#  is on and on if it is off.
#
#  Plus, as an added bonus, you can do this to normal switches by typing
#  'InvertSwitch(s)'
#==============================================================================
class Interpreter

 def SetSelfSwitch(e,s,v)
   key = [$game_map.map_id,e,s]
   $game_self_switches[key]= v
   $game_map.events[e].refresh
 end
 
 def InvertSelfSwitch(e,s)
   key = [$game_map.map_id,e,s]
   if $game_self_switches[key] == false
     $game_self_switches[key]=true
   else
     $game_self_switches[key]=false
   end
   $game_map.events[e].refresh
 end
 
 def InvertSwitch(s)
   if $game_switches[s] == false
     $game_switches[s]=true
   else
     $game_switches[s]=false
   end
 end
 
end

#==============================================================================
# Advanced Timer Controls
#------------------------------------------------------------------------------
#  Adds a few functions to the timer.
#
#  Use the 'call script' command and type one of the following:
#
#   timer_add(x)   -  Where x is the number of seconds you want to add to the
#                     timer.
#   timer_minus(x) -  Where x is the number of seconds you want to take away
#                     from the timer
#   pause_timer    -  If you want to pause the timer (Can be set before you
#                     start a timer so that it doesn't start until you tell
#                     it to.
#   unpause_timer  -  Unpauses a paused timer(Can again be set when a timer
#                     isn't running.
#==============================================================================


class Interpreter
 
 def timer_add(seconds)
   return if !$game_system.timer_working
   $game_system.timer += (seconds * Graphics.frame_rate)
 end
 
 def timer_minus(seconds)
   return if !$game_system.timer_working
   $game_system.timer -= (seconds * Graphics.frame_rate)
   $game_system.timer = 0 if $game_system.timer < 0
 end

 def pause_timer
   $game_system.timer_paused = true
 end

 def unpause_timer
   $game_system.timer_paused = false
 end

end


class Game_System
 
 attr_accessor :timer_paused
 
 alias matimerinit initialize
 def initialize
   matimerinit
   @timer_paused = false
 end

 alias timerupdate update
 def update
   timerupdate if @timer_paused == false
 end

end
 
end



Instructions

Insert above Main. Follow the half-hearted copy-paste job that is my set of instructions.

In Battle Event Deletion

Erases specified events DURING a battle. Not a frame before, not a frame afterwards. Use a 'Call Script' command before a battle. Then type:

   $game_temp.battle_ids = [x,y,z, etc]

Inside the array, place the ids of the events to be deleted. When the battle
begins, the events will be removed. This works in the same way as the
'Erase Event' command, so make sure you set a switch or use some other method
to permanently remove the events.

Event Mover & Perma-Delete

Permanently moves or 'deletes' events. Whenever the map is reloaded, it will remember the new location and whether the event is permanently deleted. Choose a 'Set move route' command and select the event you want to move or delete, then use the 'script' option in the move route planner and type one of these:

 'set_to_current_pos' - Sets the Events new position to where it currently is
 so that next time the map loads, that's where the event will be.

 'set_to_this_pos(x,y)' - This will set the position of the event to the
 x and y coordinates specified.

 'delete_event' - Permanently 'deletes' the event. Actually it doesn't, it
 just removes it every time the map is loaded.

Global Self Switch Controller & Switch Invert

This lets you control Self Switches on the current map from ANY event!
Using 'Call Script', just type 'SetSelfSwitch(e,s,v)' where e is the Event ID,
s is the Self Switch to alter ("A","B","C" or "D") and v is the boolean (true or false)

Also, by typing 'InvertSelfSwitch(e,s)' you can turn a self switch off if it
is on and on if it is off.

Plus, as an added bonus, you can do this to normal switches by typing
'InvertSwitch(s)'

Advanced Timer Controls

Adds a few functions to the timer. With it you can pause/unpause a timer, or add/take away time. Use the 'call script' command and type one of the following:

 timer_add(x)   -  Where x is the number of seconds you want to add to the timer.

 timer_minus(x) -  Where x is the number of seconds you want to take away from the timer

 pause_timer    -  If you want to pause the timer (Can be set before you start a timer so that it doesn't start until you tell it to.

 unpause_timer  -  Unpauses a paused timer(Can again be set when a timer isn't running.


Compatibility
None as far as I'm aware. Let me know if you encounter any.


Credits and Thanks

Mikey, for bombarding me with script requests and keeping me thinking.
Hayley, for putting up with the pre-release insomnia and post-release grouches.


Author's Notes

Credit is appreciated, but not needed.
Title: Re: mad.array Mini add-ons
Post by: Zexion on March 23, 2013, 07:53:29 pm
Very nice add-ons! I love scripts that add to the default features :) Lvl++
Title: Re: [XP] mad.array Mini add-ons
Post by: mad.array on March 23, 2013, 08:07:08 pm
Thanks! I'm always open to suggestions for improvements to the default features, though I'll admit my time with XP is limited these days. I hope you get some use out of the script.