10-06-2007, 01:00 PM
Level Based Shop Goods
by GubiD
Oct 6 2007
This script allows you to sell items based on your highest level actor in the party not what is specified in the event... unless an override is used, in which case the passed contents will be sold.
This item was a request, but I thought I would release it to everyone.
Note:
Although this script should be compatible with anything under the sun, this script does replace the COMMAND_302 method for the Interpreter and thus this script MAY not be compatible with other shop scripts. It is very rare that this method would be replaced, but if you have any problems with compatibility, please provide me with a link to the other shop system you are integrating this with and I will make the modifications required to make it compatible.
by GubiD
Oct 6 2007
This is a locked, single-post thread from Creation Asylum. Archived here to prevent its loss.
No support is given.
No support is given.
This script allows you to sell items based on your highest level actor in the party not what is specified in the event... unless an override is used, in which case the passed contents will be sold.
This item was a request, but I thought I would release it to everyone.
script
Code:
#-------------------------------------------------------------------------
# Leveled Shops
# by GubiD 10/15/07
# version 2.0
#-------------------------------------------------------------------------
# To call this script simply open a event and choose shop processing.
# The first "item" specified in the list will specify the shop type if USE_INDV_SHOPS
# is true, otherwise a default GOODS shop will be called with your specified
# goods you setup per this script.
#
# To add/remove static goods you must use the add/remove_static_goods methods
# within an event. To add goods, type: add_static_goods(ID, TYPE, SHOP_TYPE)
# and likewise to remove goods, type: remove_static_goods(ID, TYPE, SHOP_TYPE)
# *ID is the database ID of the "item"
# *TYPE is the item type. 0-item, 1-weapon, 2-armor
# *SHOP_TYPE is the shop type you want to add it too, which is determined the
# same way as TYPE.
#
# The above is true unless you enable the OVERRIDE_SHOP in a script, via the
# event prior to calling the shop. To do this type set_override, or to
# disable a override, set_override(false).
#-------------------------------------------------------------------------#
#-------------------------------------------------------------------------
# Features
#-------------------------------------------------------------------------
# >Allows shops to be dictated for proper goods for the current actor level
# >Allows STATIC goods so that you can set something and forget about adding it again.
# >Allows STATIC goods to be erased if wanted.. remove_static_goods(id, type, shop_type)
# >Allows you to do stanard shop processing if a OVERRIDE is used.
#-------------------------------------------------------------------------
#-------------------------------------------------------------------------
# Disclaimer
#-------------------------------------------------------------------------
# Static goods dont manage themselves. this said YOU must ensure your items are not duplicated in the shop.
# Using this script is at YOUR risk
# You may NOT use this in a commercial game without my permission. (I deserve my fair cut!)
# You may NOT post this script anywhere without my permission.
# You may create your own addons for this script but please make me aware of them so that they can be added to the release!
# The use of this script in your game is at your own risk.
# You *MUST* give me credit.
# Bugs may or may not be fixed when reported.
#-------------------------------------------------------------------------
module LEVEL_SHOP
#-------------------------------------------------------------------------
# SHOP ENABLED - Turns on the Level Shop code
#-------------------------------------------------------------------------
SHOP_ENABLED = true
#-------------------------------------------------------------------------
# USE_INDV_SHOPS - System detects first item in shop_calling and calls that shop type
#-------------------------------------------------------------------------
USE_INDV_SHOPS = true
#-------------------------------------------------------------------------
# Get shop items
#-------------------------------------------------------------------------
def self.get_shop_goods
high_level = 0
for actor in $game_party.actors
if actor.level > high_level
high_level = actor.level
end
end
goods = []
if $game_system.static_goods.size > 0
goods += $game_system.static_goods
end
#-------------------------------------------------------------------------
# To add goods, first specify..When LEVEL, then goods.push([TYPE, ID])
# LEVEL being the LEVEL of the highest character.
# Types - 0 items, 1 weapons, 2 armors
# ID is simply the ID of the item in the database under the appropriate tab
#-------------------------------------------------------------------------
case high_level
when 1
goods.push([0,1]) #potion ###Items all start with 0, then item ID
goods.push([1,2]) #iron sword###Weapons start with 1, then weapon ID
goods.push([2,1]) #brz armor ###Armor starts with 2, then armor ID
#note that you can specify more than 1 LEVEL per when statement if desired.
when 2,3
goods.push([0,2]) #high potion
else
goods.push([0,1]) #potion
goods.push([1,1]) #iron sword
end
goods.sort! #resorts items to ensure they are in proper order
return goods
end
def self.get_item_goods
high_level = 0
for actor in $game_party.actors
if actor.level > high_level
high_level = actor.level
end
end
goods = []
if $game_system.static_items.size > 0
goods += $game_system.static_items
end
case high_level
when 1
goods.push([0,2]) #hi-potion
goods.push([0,3]) #full potion
when 2,3
goods.push([0,4]) #perfume
end
goods.sort! #resorts items to ensure they are in proper order
return goods
end
def self.get_weapon_goods
high_level = 0
for actor in $game_party.actors
if actor.level > high_level
high_level = actor.level
end
end
goods = []
if $game_system.static_weapons.size > 0
goods += $game_system.static_weapons
end
case high_level
when 1
goods.push([1,2]) #iron sword
when 2,3
goods.push([1,4]) #mythril sword
end
goods.sort! #resorts items to ensure they are in proper order
return goods
end
def self.get_armor_goods
high_level = 0
for actor in $game_party.actors
if actor.level > high_level
high_level = actor.level
end
end
goods = []
if $game_system.static_armors.size > 0
goods += $game_system.static_armors
end
case high_level
when 1
goods.push([2,2]) #iron shield
when 2,3
goods.push([2,4]) #mythril shield
end
goods.sort! #resorts items to ensure they are in proper order
return goods
end
end
class Game_Temp
attr_accessor :override_shop
alias gubid_level_shop_temp_init initialize
def initialize
@override_shop = false
gubid_level_shop_temp_init
end
end
class Interpreter
def add_static_goods(id, type = 0, shop_type = 0)
if LEVEL_SHOP::USE_INDV_SHOPS
case shop_type
when 0 #item
$game_system.static_items.push([type, id])
when 1 #weapon
$game_system.static_weapons.push([type, id])
when 2 #armor
$game_system.static_armors.push([type, id])
end
end
$game_system.static_goods.push([type, id])
##ensure items are "IN ORDER"
$game_system.static_items.sort!
$game_system.static_weapons.sort!
$game_system.static_armors.sort!
$game_system.static_goods.sort!
return true
end
def remove_static_goods(id, type = 0, shop_type = 0)
if LEVEL_SHOP::USE_INDV_SHOPS
case shop_type
when 0 #item
$game_system.static_items.delete([type, id])
when 1
$game_system.static_weapons.delete([type, id])
when 2
$game_system.static_armors.delete([type, id])
end
end
$game_system.static_goods.delete([type, id])
##ensure items are "IN ORDER"
$game_system.static_items.sort!
$game_system.static_weapons.sort!
$game_system.static_armors.sort!
$game_system.static_goods.sort!
return true
end
def command_302
# Set battle abort flag
$game_temp.battle_abort = true
# Set shop calling flag
$game_temp.shop_calling = true
# Set goods list on new item
if LEVEL_SHOP::SHOP_ENABLED and !$game_temp.override_shop
if LEVEL_SHOP::USE_INDV_SHOPS
type = @parameters[0]
if type == 0
$game_temp.shop_goods = LEVEL_SHOP::get_item_goods
elsif type == 1
$game_temp.shop_goods = LEVEL_SHOP::get_weapon_goods
elsif type == 2
$game_temp.shop_goods = LEVEL_SHOP::get_armor_goods
end
else
$game_temp.shop_goods = LEVEL_SHOP::get_shop_goods
return true
end
if $game_temp.shop_goods.empty?
$game_temp.shop_goods = [@parameters]
end
else
$game_temp.shop_goods = [@parameters]
$game_temp.override_shop = false
end
# Loop
loop do
# Advance index
@index += 1
# If next event command has shop on second line or after
if @list[@index].code == 605
# Add goods list to new item
$game_temp.shop_goods.push(@list[@index].parameters)
# If event command does not have shop on second line or after
else
# End
return false
end
end
end
def set_shop_override(set = true)
$game_temp.override_shop = set
end
end
class Game_System
attr_accessor :static_items
attr_accessor :static_weapons
attr_accessor :static_armors
attr_accessor :static_goods
alias level_shops_sys_init initialize
def initialize
@static_items = []
@static_weapons = []
@static_armors = []
@static_goods = []
level_shops_sys_init
end
end
Note:
Although this script should be compatible with anything under the sun, this script does replace the COMMAND_302 method for the Interpreter and thus this script MAY not be compatible with other shop scripts. It is very rare that this method would be replaced, but if you have any problems with compatibility, please provide me with a link to the other shop system you are integrating this with and I will make the modifications required to make it compatible.