YERD Dynamic Common Event Shop
Sept 1 2011
SummaryA way to change what appears in a common event shop based on certain conditions.
Features Desired- In-game command of the shop
- Add/remove items from the shop based on conditions
What other scripts are you using?- YERD Common Event Shop
- Sky00Valentine's Quest Script
Did you search?Yes
Where did you search?- This site
- rpgmakervx.net
- rpgrevolution
What did you search for?- YERD common event shop
- dynamic
- script
If it is already possible to do this with a script call, that would be great to know. I looked through the script and it didn't seem like there were any pre-made script calls to modify the script in-game.
YERD_CommentEventShop
#===============================================================================
#
# Yanfly Engine RD - Common Event Shop
# Last Date Updated: 2009.05.31
# Level: Normal, Hard
#
# Sometimes the lack of things you can do with money can become a little boring
# since it's only ever used for buying items and equipment and that's it. Well,
# now your players can expend their funds on common events (that you can decide
# what will happen). They can purchase common events that may unlock extras,
# recruit characters, teleport to unique places, anything your eventing ability
# allows you to do.
#
#===============================================================================
# Updates:
# ----------------------------------------------------------------------------
# o 2009.05.31 - Started script and finished.
#===============================================================================
# Instructions
#===============================================================================
#
# First, bind the CE_SHOP_VARIABLE to a variable you wish to dedicate towards
# the common event shops. Whenever you send the player to a shop and the common
# event variable's value is above 0, the player will be taken to the common
# event shop instead. Remember to set the variable back to 0 when you want to
# issue a normal shop.
#
#===============================================================================
#
# Compatibility
# - Alias: Scene_Map: call_shop
#
#===============================================================================
$imported = {} if $imported == nil
$imported["CommonEventShop"] = true
module YE
module EVENT
# Note that when you change this variable on the field map, it will change
# the scene to the common event shop and then reset itself.
CE_SHOP_VARIABLE = 99
#-------------------------------------------------------------------------
# Set up your common event shops the way you prefer here. Fill out each
# part completely to create your own common event shops.
#
# CurID - Currency ID, 0 for gold. If higher, uses a variable instead.
# Buy Text - Text used to select the common event list.
# Leave - Text used to leave the common event shop.
# Welcome - Text displayed at top when common event list isn't selected.
# Sold IDs - Array containing all of the common events sold in the shop.
#-------------------------------------------------------------------------
CE_SHOP_LIST={ # Follow the example.
# ShopID => [CurID, Buy Text, Leave, Welcome Text -------------------]
1 => [ 0, "Select Mission", "Leave", "Welcome to the Mission Counter.",
[10, 12, 13],
],# Above are the common events sold in the shop.
# ShopID => [CurID, Buy Text, Leave, Welcome Text -------------------]
2 => [ 0, "Buy Points", "Leave", "No pain, no gain! Money helps too.",
[3, 5, 7, 9, 4, 6, 8, 11],
],# Above are the common events sold in the shop.
} # Do not remove this.
#-------------------------------------------------------------------------
# This following hash determines how much common events will be sold. Fill
# out each part completely in order for this script to function correctly.
#
# ID - ID of the common event being sold.
# Cost - Cost of the common event being sold.
# Icon - Icon of the common event being sold.
# Limit - How many times the common event can be sold.
# Leave - Leave the shop upon buying the common event.
# Descr - Description of the common event.
#-------------------------------------------------------------------------
# Zero limit means that there is no maximum amount of times to buy event.
#-------------------------------------------------------------------------
COMMON_EVENT_ITEM_HASH ={ # Follow the example.
# ID => [ Cost, Icon, Limit, Leave, Description] ----------------------
3 => [ 5000, 131, 0, false, "+5 Status Points for the party member in slot 1"],
4 => [ 9500, 129, 0, false, "+10 Status Points for the party member in slot 1"],
5 => [ 5000, 130, 0, false, "+5 Status Points for the party member in slot 2"],
6 => [ 9500, 131, 0, false, "+10 Status Points for the party member in slot 2"],
7 => [ 5000, 129, 0, false, "+5 Status Points for the party member in slot 3"],
8 => [ 9500, 130, 0, false, "+10 Status Points for the party member in slot 3"],
9 => [ 5000, 160, 0, false, "+5 Status Points for the party member in slot 4"],
11=> [ 9500, 125, 0, false, "+10 Status Points for the party member in slot 4"],
10=> [ 0, 153, 1, false, "Mission: The Legend of Dexx"],
12=> [ 0, 200, 1, false, "Mission: Photoshopped Slime"],
13=> [ 0, 120, 1, false, "Mission: Cutscene!"],
} # Do not remove this.
# This determines how to call the currency for each variable value. Note
# that variable 0 and below will always return the default currency so
# don't adding values for those.
CURRENCY_VARIABLE_MATCH ={
# VarID => Name
1 => " Sil",
2 => " Plat",
3 => " Souls",
4 => " Credits",
} # Do not remove this.
# This will be the name given to variables not listed under the list above.
UNDEFINED_CURRENCY = " Points"
# If there is no cost for the common event, would you like for it to still
# show 0 Gold or 0 Points?
CE_SHOW_FREE_COST = false
# The following will let you decide whether or not you would like to show
# a limit indicator for the number of times a common event can be bought.
CE_LIMIT_TEXT = "%d/%d"
CE_SHOW_LIMIT = true
CE_SHOW_LIMIT_0 = false
CE_SHOW_LIMIT_1 = false
end # YE
end # YE
#===============================================================================
# Editting anything past this point may potentially result in causing computer
# damage, incontinence, explosion of user's head, coma, death, and/or halitosis.
# Therefore, edit at your own risk.
#===============================================================================
#===============================================================================
# Game_Party
#===============================================================================
class Game_Party < Game_Unit
#--------------------------------------------------------------------------
# public instance variables
#--------------------------------------------------------------------------
attr_accessor :ces_limit
end # Game_Party
#===============================================================================
# Scene_Map
#===============================================================================
class Scene_Map < Scene_Base
#--------------------------------------------------------------------------
# alias call_shop
#--------------------------------------------------------------------------
alias call_shop_ces call_shop unless $@
def call_shop
if meet_ceshop_conditions
$game_temp.next_scene = nil
$scene = Scene_Common_Event_Shop.new
else
call_shop_ces
end
end
#--------------------------------------------------------------------------
# meet_ceshop_conditions
#--------------------------------------------------------------------------
def meet_ceshop_conditions
shop_id = $game_variables[YE::EVENT::CE_SHOP_VARIABLE]
return false if shop_id <= 0
return false unless $scene.is_a?(Scene_Map)
return false unless YE::EVENT::CE_SHOP_LIST.include?(shop_id)
return true
end
end # Scene_Map
#===============================================================================
# Scene_Common_Event_Shop
#===============================================================================
class Scene_Common_Event_Shop < Scene_Base
#--------------------------------------------------------------------------
# initialize
#--------------------------------------------------------------------------
def initialize
@shop_id = $game_variables[YE::EVENT::CE_SHOP_VARIABLE]
@currency = YE::EVENT::CE_SHOP_LIST[@shop_id][0]
@welcome = YE::EVENT::CE_SHOP_LIST[@shop_id][3]
@interpreter = Game_Interpreter.new
@message_window = Window_Message.new
@message_window.back_opacity = 255
@common_event = 0
end
#--------------------------------------------------------------------------
# start
#--------------------------------------------------------------------------
def start
super
create_menu_background
create_command_window
@help_window = Window_Help.new
@currency_window = Window_Variable_Currency.new(@currency)
@event_window = Window_Common_Event.new
@event_window.help_window = @help_window
set_welcome_text
end
#--------------------------------------------------------------------------
# terminate
#--------------------------------------------------------------------------
def terminate
super
dispose_menu_background
@message_window.dispose
@command_window.dispose
@help_window.dispose
@currency_window.dispose
@event_window.dispose
end
#--------------------------------------------------------------------------
# update
#--------------------------------------------------------------------------
def update
super
update_menu_background
update_interpreter
update_currency_window
@message_window.update
@interpreter.update
return if @interpreter.running?
return if $game_message.visible
if @command_window.active
update_command_window
elsif @event_window.active
update_event_window
end
end
#--------------------------------------------------------------------------
# update_interpreter
#--------------------------------------------------------------------------
def update_interpreter
if @common_event > 0
@interpreter.setup($data_common_events[@common_event].list)
@common_event = 0
return
end
end
#--------------------------------------------------------------------------
# update_currency_window
#--------------------------------------------------------------------------
def update_currency_window
if @currency == 0
if @currency_window.value != $game_party.gold
@currency_window.refresh
end
else
if @currency_window.value != $game_variables[@currency]
@currency_window.refresh
end
end
end
#--------------------------------------------------------------------------
# update_command_window
#--------------------------------------------------------------------------
def update_command_window
@command_window.update
if Input.trigger?(Input::B)
Sound.play_cancel
$scene = Scene_Map.new
$game_variables[YE::EVENT::CE_SHOP_VARIABLE] = 0
elsif Input.trigger?(Input::C)
Sound.play_decision
case @command_window.index
when 0
@command_window.active = false
@event_window.active = true
text = YE::EVENT::COMMON_EVENT_ITEM_HASH[@event_window.event][4]
@help_window.contents.clear
@help_window.contents.font.color = @help_window.normal_color
@help_window.contents.draw_text(4, 0, 504, 24, text)
when 1
$scene = Scene_Map.new
$game_variables[YE::EVENT::CE_SHOP_VARIABLE] = 0
end
end
end
#--------------------------------------------------------------------------
# update_event_window
#--------------------------------------------------------------------------
def update_event_window
@event_window.update
@help_window.update
if Input.trigger?(Input::B)
Sound.play_cancel
@command_window.active = true
@event_window.active = false
set_welcome_text
elsif Input.trigger?(Input::C)
event = @event_window.event
if event == nil
Sound.play_buzzer
elsif !can_purchase_event?(event)
Sound.play_buzzer
else
Sound.play_shop
adjust_currency(event)
buy_event(event)
end
end
end
#--------------------------------------------------------------------------
# create_command_window
#--------------------------------------------------------------------------
def create_command_window
s1 = YE::EVENT::CE_SHOP_LIST[@shop_id][1]
s2 = YE::EVENT::CE_SHOP_LIST[@shop_id][2]
@command_window = Window_Command.new(384, [s1, s2], 2)
@command_window.y = 56
end
#--------------------------------------------------------------------------
# set welcome text
#--------------------------------------------------------------------------
def set_welcome_text
@help_window.contents.clear
@help_window.contents.draw_text(4, 0, 540, 24, @welcome)
end
#--------------------------------------------------------------------------
# can purchase event?
#--------------------------------------------------------------------------
def can_purchase_event?(event)
return false if $data_common_events[event] == nil
cost = YE::EVENT::COMMON_EVENT_ITEM_HASH[event][0]
if YE::EVENT::CE_SHOP_LIST[@shop_id][0] == 0
return false if $game_party.gold < cost
else
return false if $game_variables[@currency] < cost
end
$game_party.ces_limit = {} if $game_party.ces_limit == nil
$game_party.ces_limit[event] = 0 if $game_party.ces_limit[event] == nil
if YE::EVENT::COMMON_EVENT_ITEM_HASH[event][2] != 0 and
$game_party.ces_limit[event] >= YE::EVENT::COMMON_EVENT_ITEM_HASH[event][2]
return false
end
return true
end
#--------------------------------------------------------------------------
# adjust currency
#--------------------------------------------------------------------------
def adjust_currency(event)
cost = YE::EVENT::COMMON_EVENT_ITEM_HASH[event][0]
if @currency == 0
$game_party.lose_gold(cost)
else
$game_variables[@currency] -= cost
end
end
#--------------------------------------------------------------------------
# buy event
#--------------------------------------------------------------------------
def buy_event(event)
$game_party.ces_limit[event] += 1
@event_window.refresh
if YE::EVENT::COMMON_EVENT_ITEM_HASH[event][3]
$game_temp.common_event_id = event
$scene = Scene_Map.new
$game_variables[YE::EVENT::CE_SHOP_VARIABLE] = 0
else
@common_event = event
end
end
end
#===============================================================================
# Window_Variable_Currency
#===============================================================================
class Window_Variable_Currency < Window_Base
#--------------------------------------------------------------------------
# intialize
#--------------------------------------------------------------------------
def initialize(currency)
super(384, 56, 160, WLH + 32)
@currency = currency
refresh
end
#--------------------------------------------------------------------------
# refresh
#--------------------------------------------------------------------------
def refresh
self.contents.clear
if @currency > 0
@value = $game_variables[@currency]
if YE::EVENT::CURRENCY_VARIABLE_MATCH.include?(@currency)
@vocab = YE::EVENT::CURRENCY_VARIABLE_MATCH[@currency]
else
@vocab = YE::EVENT::UNDEFINED_CURRENCY
end
else
@value = $game_party.gold
@vocab = Vocab::gold
end
draw_currency
end
#--------------------------------------------------------------------------
# draw_currency
#--------------------------------------------------------------------------
def draw_currency
cx = contents.text_size(@vocab).width
self.contents.font.color = normal_color
self.contents.draw_text(4, 0, 118 - cx, WLH, @value, 2)
self.contents.font.color = system_color
self.contents.draw_text(4, 0, 120, WLH, @vocab, 2)
end
#--------------------------------------------------------------------------
# value
#--------------------------------------------------------------------------
def value
return @value
end
end # Window_Variable_Currency
#==============================================================================
# Window_Common_Event
#==============================================================================
class Window_Common_Event < Window_Selectable
#--------------------------------------------------------------------------
# initialize
#--------------------------------------------------------------------------
def initialize
super(0, 112, 544, 304)
shop_id = $game_variables[YE::EVENT::CE_SHOP_VARIABLE]
@shop = YE::EVENT::CE_SHOP_LIST[shop_id]
if @shop[0] <= 0
@currency = Vocab::gold
elsif YE::EVENT::CURRENCY_VARIABLE_MATCH.include?(@shop[0])
@currency = YE::EVENT::CURRENCY_VARIABLE_MATCH[@shop[0]]
else
@currency = YE::EVENT::UNDEFINED_CURRENCY
end
@shop_items = @shop[4]
self.index = 0
refresh
end
#--------------------------------------------------------------------------
# refresh
#--------------------------------------------------------------------------
def refresh
@data = []
@common_event = []
@item_max = 0
for item in @shop_items
@data.push(item) if YE::EVENT::COMMON_EVENT_ITEM_HASH.include?(item)
end
@item_max = @data.size
create_contents
for i in 0...@item_max
draw_item(i)
end
end
#--------------------------------------------------------------------------
# draw item
#--------------------------------------------------------------------------
def draw_item(index)
rect = item_rect(index)
self.contents.clear_rect(rect)
rx = rect.x; ry = rect.y; rw = rect.width; rh = rect.height
sw = self.width - 32
@common_event_id = @data[index]
ce_array = YE::EVENT::COMMON_EVENT_ITEM_HASH[@common_event_id]
@common_event_name = $data_common_events[@common_event_id].name
@common_event_cost = ce_array[0]
@common_event_icon = ce_array[1]
@common_event_limit = ce_array[2]
draw_icon(@common_event_icon, rx+2, ry, enabled)
self.contents.font.color.alpha = enabled ? 255 : 128
self.contents.draw_text(rx+26, ry, rw-278, rh, @common_event_name, 0)
if YE::EVENT::CE_SHOW_LIMIT
limit = $game_party.ces_limit[@common_event_id]
text = sprintf(YE::EVENT::CE_LIMIT_TEXT, limit, @common_event_limit)
if !YE::EVENT::CE_SHOW_LIMIT_0 and @common_event_limit == 0
text = ""
end
if !YE::EVENT::CE_SHOW_LIMIT_1 and @common_event_limit == 1
text = ""
end
self.contents.draw_text(rw-242, ry, 80, rh, text, 1)
end
unless !YE::EVENT::CE_SHOW_FREE_COST and @common_event_cost <= 0
text = sprintf("%s%s", @common_event_cost, @currency)
self.contents.draw_text(rw-152, ry, 150, rh, text, 2)
end
end
#--------------------------------------------------------------------------
# event
#--------------------------------------------------------------------------
def event
return @data[self.index]
end
#--------------------------------------------------------------------------
# update help
#--------------------------------------------------------------------------
def update_help
if event == nil
@help_window.set_text("")
else
text = YE::EVENT::COMMON_EVENT_ITEM_HASH[event][4]
@help_window.set_text(text)
end
end
#--------------------------------------------------------------------------
# enabled
#--------------------------------------------------------------------------
def enabled
$game_party.ces_limit = {} if $game_party.ces_limit == nil
$game_party.ces_limit[@common_event_id] = 0 if
$game_party.ces_limit[@common_event_id] == nil
return false if $data_common_events[@common_event_id] == nil
if @shop[0] == 0
return false if $game_party.gold < @common_event_cost
else
return false if $game_variables[@shop[0]] < @common_event_cost
end
if @common_event_limit > 0 and
$game_party.ces_limit[@common_event_id] >= @common_event_limit
return false
end
return true
end
end # Window_Common_Event
#===============================================================================
#
# END OF FILE
#
#===============================================================================