[XP]Map Specific Variables

Map Specific Variables Version: 1
By: Creative_AUG

Introduction

Basically this is a simple script that sets a variable up for each map. Depending on which in-game variable you choose to correspond to it, you can manipulate that variable using the event commands. The variable will retain it's value when you switch maps and return but a new map's variable will always be zero.

So simply put, each map will have it's own variable that you can manipulate, allowing you to cut back on usage of the in-game variables and simplifying events and event conditions. The script allows you link maps as well, allowing you to be able to retain values within a certain map group. This is useful if you map a village for example. Events inside the house maps in those villages can respond to the map specific variable and even manipulate it.

Features
  • Allows Map Specific Variables that are unique to the map.
  • Allows you to link maps that you want to share a variable with.
  • Can be manipulated easily through regular in-game variable-based event calls

Screenshots

none.

Demo

none.

Script

Script Spoiler
  1. MAP_SPECIFIC_VARIABLE_ID = [99,100]
  2. LINKED_MAPS = [[10,9,3]]
  3. class Game_Map
  4.   attr_accessor :variable
  5.   attr_accessor :map_id
  6.   alias map_specific initialize
  7.   alias map_specific2 setup
  8.   def initialize
  9.     @variable = []
  10.     map_specific
  11.   end
  12. end
  13. class Game_Variables
  14.   def [](variable_id)
  15.     id = $game_map.map_id
  16.     if variable_id <= 5000 and @data[variable_id] != nil
  17.       if MAP_SPECIFIC_VARIABLE_ID.include?(variable_id)
  18.         if $game_map.variable[id] != nil
  19.           return $game_map.variable[id]
  20.         else
  21.           $game_map.variable[id] = 0
  22.           return 0
  23.         end
  24.       else
  25.         return @data[variable_id]
  26.       end
  27.     else
  28.       return 0
  29.     end
  30.   end
  31.   def []=(variable_id, value)
  32.     id = $game_map.map_id
  33.     if variable_id <= 5000
  34.       if MAP_SPECIFIC_VARIABLE_ID.include?(variable_id)
  35.         @data[variable_id] = value
  36.         maps = []
  37.         LINKED_MAPS.each {|link|
  38.         if link.include?(id)
  39.           for i in 0...link.size
  40.             maps.push(link[i])
  41.           end
  42.         else
  43.           maps = false
  44.         end
  45.         }
  46.         #print(maps.to_s)
  47.         if maps == false
  48.           $game_map.variable[id] = value
  49.         else
  50.           for i in 0...maps.size
  51.             $game_map.variable[maps[i]] = value
  52.           end
  53.         end
  54.       else
  55.         @data[variable_id] = value
  56.       end
  57.     end
  58.   end
  59. end
Expand to see the code.


Instructions

The first two lines of the script:
Content Hidden Spoiler
  1. MAP_SPECIFIC_VARIABLE_ID = [99,100]
  2. LINKED_MAPS = [[10,9,3]]
Expand to see the code.


MAP_SPECIFIC_VARIABLE_ID specifies which in-game variables manipulate the map specific ones. In-Game Variable 99 and 100 can be used to manipulate the map specific ones. to add more, simply add a comma, followed by another variable ID number.
LINKED_MAPS specifies the maps that are linked together. Map IDs 10,9 and 3 are linked together and share the same map specific variable. to add more links, be careful to add a separate array. for example:

LINKED_MAPS = [[1,2,3],[4,5],[7,3,4]]

This would indicate that map ID 1,2 & 3 are linked together. Map ID 4 and 5 are linked together and 7, 3 and 4 are linked together. Remember that having 1 map linked with 2 separate groups may cause your game to be buggy. Be careful to use separate variables for maps that are shared like that.

FAQ

none.

Compatibility

This script completely rewrites the Game_Variables class. Any script that manipulates the class or uses it, may not work.

Credits and Thanks

none.

Author's Notes

none.

Terms and Conditions

Have fun with this. I pray it's helpful.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=78892