Code:
# * ReKordChoices XP * #
# Scripter : Kyonides Arkanthes
# 2024-10-08
# This scriptlet allows you to auto-select 2 game variables that will store
# the choices list ID for the selected event page and the number of times you
# have selected a given option.
# The value of that game variable will get updated automatically every time
# you pick any of the available choices.
# * Script Calls * #
# Use them to create a new choices list storage or to retrieve its data.
# List of Arguments:
# - ListID stands for Any "String" or Number
# - ChoiceIndex is a Number, 1 through 4
# - EventPage is a Number, 1 through 99 (Maximum Number of Pages)
# get_choice(ListID, ChoiceIndex)
# get_choice(ListID, ChoiceIndex, EventPage)
# get_choice(ListID, ChoiceIndex, EventPage, EventID)
# get_choice(ListID, ChoiceIndex, EventPage, EventID, MapID)
module ReKord
CHOICES_LIST_VAR_ID = 5
CHOICES_TIMES_VAR_ID = 6
class GameChoices
def initialize
@data = {}
@data.default = 0
end
def [](key)
@data[key]
end
def increase(key)
@data[key] += 1
end
attr_reader :data
end
end
class Game_Variables
alias :kyon_rekord_choices_gm_var_init :initialize
def initialize
kyon_rekord_choices_gm_var_init
@choice_data = {}
end
def find_choice_set(map_id, event_id, page_index, list_index)
@choice_data ||= {}
key = [map_id, event_id, page_index, list_index]
@choice_data[key] ||= ReKord::GameChoices.new
end
def set_choice_vars(choice_index, total)
@data[ReKord::CHOICES_LIST_VAR_ID] = choice_index + 1
@data[ReKord::CHOICES_TIMES_VAR_ID] = total
end
def choice(map_id, event_id, page, list_index, choice_index, go_up)
choices = find_choice_set(map_id, event_id, page, list_index)
choices.increase(choice_index) if go_up
set_choice_vars(choice_index, choices[choice_index])
end
end
class Game_Event
def page_index
@event.pages.index(@page)
end
end
class Interpreter
alias :kyon_rekord_choices_int_cmd_402 :command_402
def command_402
if @branch[@list[@index].indent] == @parameters[0]
map_id = $game_map.map_id
page = $game_map.events[@event_id].page_index
list = $game_variables[ReKord::CHOICES_LIST_VAR_ID]
choice = @parameters[0]
$game_variables.choice(map_id, @event_id, page, list, choice, true)
end
kyon_rekord_choices_int_cmd_402
end
def get_choice(list, choice_index, page=nil, ev_id=nil, map_id=nil)
map_id ||= $game_map.map_id
ev_id ||= @event_id
page = page ? page - 1 : $game_map.events[ev_id].page_index
choice_index -= 1
$game_variables.choice(map_id, ev_id, page, list, choice_index, nil)
end
end