Perishable Items
Authors: mad.array
Version: 1.0a
Type: Custom Item System
Key Term: Custom Item System
IntroductionThis script adds a 'best before date' to any item that you choose. After you have bought/found an item, it will only have a limited shelf life, before it goes off. Now your heroes can experience stomach bugs from drinking Potions that are past their Use By Date and experience the wonderful smell of musty old perfume!
Features
- Lets Items 'go off', changing their effects
- Each Item ID has it's own life expectency
- Items can have multiple stages of freshness
- Each instance of each item has its own timer before it goes off
ScreenshotsNo screenshots, as rotten items are not pleasant to look at!
ScriptInsert below default scripts and above Main. Jiggle it about it if it doesn't work!
#==============================================================================
# Perishable Items (Version 1.0a) by mad.array
#------------------------------------------------------------------------------
# Use this script to give your items a limited shelf life.
# To use, add a 'rotten' version of your item in the database, then
# find def calculate_perish_time and add a case for your original item number.
# e.g. (Item 1 = Potion, Item 33 = Potion [Rotten])
# ---------------
# when 1
# return 400
# ----------------
# This is the amount of time, in frames, that your item will last before going
# off. Now 400 frames is only 20 seconds, so I'd use a larger number.
#
# Next, find def rot_time and again add a case for your item. Only this time
# it will be returning the item that it will 'rot' into.
# e.g. 2
# ---------------
# when 1
# return 33
# ----------------
#
# Now, enjoy. 400 Frames after picking up a Potion, it will be removed from
# the item screen and replaced with it's rotten replacement. You can have your
# rotten equivalent do anything that a normal item would do, so go nuts!
#==============================================================================
class Game_Party
attr_accessor :perishablelist
alias perinitialize initialize
def initialize
perinitialize
@perishablelist = []
end
alias perish_gain_item gain_item
def gain_item(item_id, n)
perish_gain_item(item_id, n)
for i in 0...n
pt = calculate_perish_time(item_id)
if pt !=false
pt += Graphics.frame_count
@perishablelist[item_id] = [] if @perishablelist[item_id] == nil
@perishablelist.push[item_id].push(pt)
end
end
end
alias perish_lose_item lose_item
def lose_item(item_id, n)
perish_lose_item(item_id, n)
for i in 0...n
@perishablelist[item_id].delete_at(0) if @perishablelist[item_id] != nil
end
end
def calculate_perish_time(item_id)
case item_id
#when 1
#return 400
end
return false
end
end
class Window_Item < Window_Selectable
alias perish_draw draw_item
def draw_item(index)
perish_draw(index)
item = @data[index]
if item.is_a?(RPG::Item) && $game_party.perishablelist[item.id] != nil
number = $game_party.item_number(item.id)
changeamt = 0
for i in 0...number
if $game_party.perishablelist[item.id][i] < Graphics.frame_count
changeamt +=1
end
end
if changeamt > 0
$game_party.gain_item(rot_item(item.id), changeamt)
$game_party.lose_item(item.id, changeamt)
refresh
end
end
end
def rot_item(item_id)
case item_id
#when 1
#return 33
end
return false
end
end
InstructionsInstructions are included in the script, but I'll put some here as well.
Once the script is inserted, create a 'rotten' version of your perishables items in the Database and adjust the properties as you see fit. For example have a Potion [Rotten] take away 500 HP rather than restoring it. Then, in the script, find the def calculate_rot_time and add a case for your original item id, returning the number of frames it will take to go off. In this example we'll be using the Potion:
Note that by default there are 20 frames per second in RMXP, so the Potion would go off 20 seconds after you pick it up... I'd advise using a larger number.
Now that that's done, find def rot_time and again add a case with your original item id. Only this time we'll be returning the item that will be replacing our stinky Potion. In this example it's Item 33 (which doesn't exist by default in the Database):
Et voila! Each Potion that you pick up will go off after 20 seconds... so I'd use them fast!
CompatibilityNot tested for compatability. May not work with other Custom Item Systems. Contact me if you are having compatability issues and if I can I'll help out.
Credits and ThanksPlease credit mad.array if you use this script.
newolds Configuration program can be found here
http://www.megaupload.com/?d=XT8W253IIf you use it, give credit to him for making your life less rotten! (See what I did there?!)
Author's NotesI'm sure there is a better way of doing this, so if you can think of another method then please contact me.