v1.2
Introduction
Another very little script, and the first real scripting tool of mine. It's purpose is to practically use the note fields in the database, effectively returning it's contents to a hash. Check the instructions section for a more in-depth explanation of that.
Bottom line is: All of us who are using element tags to set non-default aspects to database elements can now not only choose between true or false (element_set.include? boolean), but also assign any integer, string or array you want for further usage.
- Returns any requested, predefined object in string, integer, array, hash, boolean, float or nil form
- Works with all note-capable database tabs (Skills, Items, Weapons, Armors, Enemies, States)
- Allows default values for easier setup and reduced error probability 1.2 and above
[rgss]#==============================================================================
# Database Flag Reader v1.2
#------------------------------------------------------------------------------
# Script by BlueScope
#==============================================================================
module RPG
#--------------------------------------------------------------------------
DefaultFlags = {}
#--------------------------------------------------------------------------
class BaseItem
def flags(identifier)
return RPG.flaglist(@note, identifier)
end
end
#--------------------------------------------------------------------------
class Enemy
def flags(identifier)
return RPG.flaglist(@note, identifier)
end
end
#--------------------------------------------------------------------------
class State
def flags(identifier)
return RPG.flaglist(@note, identifier)
end
end
#--------------------------------------------------------------------------
def self.flaglist(note, identifier)
elements = note.split(/\r\n/)
flags = {}
for i in 0...elements.size
temp = elements.to_s.split(' = ')
flags[temp[0]] = RPG.decrypt_string(temp[1])
end
if flags.include?(identifier)
return flags[identifier]
elsif DefaultFlags.include?(identifier)
return DefaultFlags[identifier]
else
return nil
end
end
#--------------------------------------------------------------------------
def self.decrypt_string(value)
if value.to_i != 0 or value == '0'
# integer and float
value.include?('.') ? result = value.to_f : result = value.to_i
elsif value == 'true'
# boolean true
result = true
elsif value == 'false'
# boolean false
result = false
elsif value.include?('[') and value.include?(']')
# array
result = []
value.delete!('[ ]')
array = value.split(',')
for i in 0...array.size
result = decrypt_string(array)
end
elsif value.include?('{') and value.include?('}')
# hash
result = {}
value.delete!('{ }')
hash = value.split(',')
for i in 0...hash.size
temp = hash.split('=>')
result[temp[0]] = decrypt_string(temp[1])
end
elsif value == 'nil'
# nil
result = nil
else
# string
result = value
end
return result
end
#--------------------------------------------------------------------------
end
[/rgss]
To use this script, you have to do two things: Pre-set flags with values in the database, and trigger those from somewhere in your script library. You can't possibly change anything in your game with this script alone, hence it's a scripting tool. In other words, you have to script whatever script be working with this by yourself, it's just a bridge from the Database to the scripts editor.
You can set flags easily by following this layout:
FlagName can be anything really, but I'd suggest using descriptive names for your further reference.
value can be any
Here's a practical example of how the note area in your database would look like:
This would return the following hash:
To check for either of those flags, you can use the regular way, using a reference to the game element, as well as the method identifier, with the flag name as an additional attribute.
You can also set default values to not input generic values into every single item note, for example. So if you let the majority of your items have UseCount = 1, for example, put this in the DefaultFlags constant instead:
Whenever you don't define a value for UseCount in your database now, every referencing script will automatically assume it's set to 1 (Integer) when there's no respective Database entry. Note that now you have to use proper syntax for the key (no quotation marks needed in database edit).
You can set flags easily by following this layout:
Code:
FlagName = value
FlagName can be anything really, but I'd suggest using descriptive names for your further reference.
value can be any
- string (without quotation marks of any kind),
- integer (again without quotation marks, as usual),
- float (no quotation marks, and of course needs the "." there or else it'll be recognized as integer),
- boolean ("true" or "false", no quotation marks),
- array (use same rules as before for contents),
- hash (use typical "key => value" addression, again, same rules as above for both key and value),
- or nil (just the word, no quotation marks).
Here's a practical example of how the note area in your database would look like:

This would return the following hash:
Code:
{
"Test"=>true,
"Health"=>600,
"Prerequisite"=>"FACT",
"OriginMaps"=>[2, 4, 5],
"HouseTeam"=>["Taub", 13, "Kutner"],
"Equip" => {"Sword" => "Dragonblade", "Armor" => "Golden Plate Armor"},
"Time" => 30.5,
"Empty" = nil
}
To check for either of those flags, you can use the regular way, using a reference to the game element, as well as the method identifier, with the flag name as an additional attribute.
Code:
$data_items[1].flags('OriginMaps')
You can also set default values to not input generic values into every single item note, for example. So if you let the majority of your items have UseCount = 1, for example, put this in the DefaultFlags constant instead:
Code:
DefaultFlags = {'UseCount' => 1}
Q: Why is this script VX-only?
A: RMXP doesn't feature note fields in the database, which is why a XP version wouldn't make sense.
Unless any other scripts have the same names as the ones in my script, it's perfectly compatible, as it's a simple add-on - no modified methods.
I'm personally using this for my newly developed (unreleased) equip system, because - as mentioned in the introduction - just a boolean value isn't enough customization sometimes. It's a neat little add-on that won't hurt performance even if you just use it for a single item... though of course, you could most likely get there some other way in that case
...to Devlin for pointing out a major bug, along with the solution, which has been fixed for v1.2
You may use and/or modify this script in any way you want, and/or release your modifications, as long as you accept the following terms and conditions entirely.
You may not use this for commercial projects, profit-oriented projects, or projects that aren't meant to be sold, but otherwise aquire money (i.e. through donations). That is not limited to RPG Maker projects, but valid for all appliances. You may not remove or delete contents of the original header included in the script, but you may add your name if you made any changes.
The actual mentioning of my nickname in your release (i.e. in-media credits, printed pages or even a readme file) is not necessary, but much apprechiated.