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=XT8W253I
If 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.
You know, this is a great idea, mad.array! Excellent Script!
Hey. I have limited time here, so I'll have to be quick about this.
I think it'd be easier if you stored the data in a module instead of those case methods. Something like this:
module RottenItems
FRAMES = {
1 => 400
2 => 2000
#etc.
}
ITEMS = {
1 => 33
2 => 34
#etc.
}
end
And replace the calculate_perish_time method with this:
def calculate_perish_time(item_id)
return RottenItems::FRAMES[item_id].nil? false : RottenItems::FRAMES[item_id]
end
And replace the rot_item method with:
def rot_item(item_id)
return RottenItems::ITEMS[item_id].nil? false : RottenItems::ITEMS[item_id]
end
And that should probably make it more user-friendly ;)
Would it be okay with you if I rewrote this for VX? It would be a pretty cool script.
@AngryPacman: You know I never looked into using modules, for no reason other than the first time I saw one in RMXP (Way back when I were a lad) they confused me and I didn't know any better. I guess I should do a bit of experimentation. Yeah, you go ahead and rewrite it for VX. Usual credit bleh applies.
Using a module for the config is a good idea, but changing the case statements to a hashes is definitely not going to improve "user-friendliness".
As for the "rot_item" method a simple "return RottenItems::ITEMS[item_id]" will do just fine. "nil" is the same as "false" when Ruby is looking for a boolean value in an "if" statement.
I find it easier to work with hashes than case methods, and I find that people like that too. I guess it's subjective. You are definitely correct about that .nil? thing, though. My syntax was even wrong it that post XD
I don't like fighting with Zer0, because he's persistent and always sees to it that he wins, so I'll just leave it at that. He's also probably right.
On a side-note, I think Zer0's post-count is the same as the year the person in his avatar was born in. Or their age. O.o
The difference between using a hash and using case-when statements is that with a hash you have to think like a programmer and with case-when statements, you just have to be able to read. That's why for the average user it's easier to use case-when statements.
That's really only the case if you don't provide any explanation of syntax, which everyone should. But I do so your reasoning, it makes perfect sense, I just don't like that it's a fact. But it's true, people are lazy and just want something simple (when done with this in mind, a case-when method could look exactly like English - return case x when y then z). I get that.
I just prefer hashes. That's it.
I prefer hashes for that kind of thing myself. If you take a look at the unofficial configuration part of RMX-OS, you'll seen nothing but hashes and constants.
Yeah, I personally don't care for myself which it is, but most people who use scripts aren't scripters and find case statements easier to overview and configure.
Aside from that, it usually doesn't matter. I agree it is more of a preference.
Quotedef rot_item(item_id)
case item_id
#when 1
#return 33
end
return fasle
end
typo?
Thanks. Typo fixed. Don't adjust your televisions!
EDIT: I've decided to leave the case... return method for the time/new item methods. I know there are a few options open but I think no matter which I choose there will always be a debate. As mentioned, the case method seems the closest to 'English'. Anyone wishing to change to a module, either with hashes or other methods, can use the steps outlined in the earlier posts.
Thanks for giving me something to think about though!
Cool script. I made a visual editor to config your script. Now is extremely easy to set for someone who does not know RGSS xD.
Download it from Megaupload:http://www.megaupload.com/?d=XT8W253I (http://www.megaupload.com/?d=XT8W253I)
Download it from Multi-upload:http://www.multiupload.com/3Q0EP50990 (http://www.multiupload.com/3Q0EP50990)
You can see the visual configurator tool in this video:
http://www.youtube.com/watch?v=1uGw27sjqzg
(http://www.youtube.com/watch?v=1uGw27sjqzg (http://www.youtube.com/watch?v=1uGw27sjqzg))
if you want sorce code ask me ;)
INSTRUCTION:
download file, unzip, copy
Config Perishable Items.exe to proyect's folder and run. RPG MAKER XP EDITOR must be closed. This editor not use the original script. You only must open the editor and press save button and it will work fine. You dont need any script more to work ;)
@newold: That. Is. Awesome.
I did consider a configuration program but it's not my speciality (If I could be said to have one). I'll add a request for credit to the main post, as well as a link, if you want.
Quote from: mad.array on January 12, 2012, 11:09:11 am
@newold: That. Is. Awesome.
I did consider a configuration program but it's not my speciality (If I could be said to have one). I'll add a request for credit to the main post, as well as a link, if you want.
ok, perfect! :D