Save-Point

Full Version: KExpire XP
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
KExpire XP

by Kyonides Arkanthes


Introduction

This scriptlet exists in order to let you make your items expire either after walking a long distance or time is up just because. Laughing + Tongue sticking out That means that it will replace them with useless items automatically. Should I feel sorry for all of you players now? Laughing

Script

Code:
# * KExpire XP
#   Scripter : Kyonides-Arkanthes
#   2019-02-27

#   This scriptlet allows you to setup items that will expire because the team
#   walked a long distance or time is up. Then it will replace it with a useless
#   item to piss off the player. XD

module KExpire
  # ItemID => [NewItemID, :step or :time, steps or seconds], etc.
  ITEMS = { 32 => [33, :step, 25] }
end

class BadItem
  def initialize(new_id, data)
    @id = new_id
    @next_id = data[0]
    @kind = data[1]
    @amount = data[2]
  end
  def expired?() @amount == 0 end
  def reduce_amount() @amount -= 1 end
  attr_reader :id, :next_id, :amount, :kind
end

class Game_System
  alias kyon_kexpire_gm_sys_init initialize
  alias kyon_kexpire_gm_sys_up update
  def initialize
    kyon_kexpire_gm_sys_init
    @step_items = []
    @time_items = []
  end

  def update
    kyon_kexpire_gm_sys_up
    @time_items.each do |item|
      item.reduce_amount
      $game_party.expire_item(item.id, item.next_id) if item.expired?
    end
  end

  def trash_items(item_id, kind, number)
    if kind == :step
      stuff = @step_items.select{|item| item.id == item_id }
      number.times {|n| @step_items.delete(stuff[n]) }
    elsif kind == :time
      stuff = @time_items.select{|item| item.id == item_id }
      number.times {|n| @time_items.delete(stuff[n]) }
    end
  end
  def reduce_steps() @step_items.each {|item| item.reduce_amount } end
  attr_reader :step_items, :time_items
end

class Game_Party
  alias kyon_kexpire_gm_party_gain_item gain_item
  alias kyon_kexpire_gm_party_inc_steps increase_steps
  def gain_item(item_id, n)
    old_max = item_number(item_id)
    kyon_kexpire_gm_party_gain_item(item_id, n)
    data = KExpire::ITEMS[item_id]
    return true unless data
    new_max = item_number(item_id)
    if old_max > new_max
      trash_items(item_id, data[1], old_max - new_max)
    elsif old_max < new_max
      total = new_max - old_max
      if data[1] == :step
        total.times { $game_system.step_items << BadItem.new(item_id, data) }
      elsif data[1] == :time
        data[2] *= Graphics.frame_rate
        total.times { $game_system.time_items << BadItem.new(item_id, data) }
      end
    end
    return true
  end

  def expire_item(old_id, new_id)
    total = [item_number(old_id) - 1, 99].min
    total > 0 ? @items[old_id] = total : @items.delete(old_id)
    old_max = item_number(new_id)
    @items[new_id] = [old_max + 1, 99].min
  end

  def increase_steps
    kyon_kexpire_gm_party_inc_steps
    $game_system.reduce_steps
  end
end


Terms of Use

This will be a cheap script in case you go commercial, do not forget to include my name in your game credits!