module EventFinder # Returns an array of events on the current map which set the value of the # switch with the given `id` to the given boolean `value`. def self.with_switch(id, value) batch_with_switch(id, id, value) end # Returns an array of events on the current map which set the values of the # switches within the range of `start` to `finish` to the given boolean # `value`. # # **Note:** the given `start` and `finish` values absolutely **must** match # what was defined in the event editor. def self.batch_with_switch(start, finish, value) # **Note:** we're converting a boolean value into `1` or `0` due to how the # editor stores these values internally (the internal values really don't # make much sense). value = value ? 0 : 1 with_command(121, start, finish, value) end # Returns an array of events on the current map which perform the given # `operation` (with the given `operand`) to the variable with the given `id`. def self.with_variable(id, operand, operation) batch_with_variable(id, id, operand, operation) end # Returns an array of events on the current map which perform the given # `operation` (with the given `operand`) to the variables within the range of # the given `start` and `finish` values. # # **Note:** the given `start` and `finish` values absolutely **must** match # what was defined in the event editor. def self.batch_with_variable(start, finish, operand, operation) # **Note:** we're converting descriptive symbol names into integers here # due to how the editor internally stores operands and operations. operand = [:const, :var, :rand, :game, :script].index(operand) operation = [:set, :add, :sub, :mul, :div, :mod].index(operation) with_command(122, start, finish, operand, operation) end # Returns an array of events with event commands matching the given command # code and parameter list. # # **Note:** the parameter list is built as-needed; only include as many # parameters as you need to filter events. def self.with_command(code, *params) return [] unless $game_map $game_map.events.values.select do |event| event.list.any? do |cmd| cmd.code == code && cmd.parameters[0...params.size] == params end end endend