Author Topic: [XP] Perishable Items  (Read 9384 times)

Offline mad.array

  • Trained Member
  • *
  • Posts: 26
  • LV: 7
  • Gender: Male
  • Homeless Dev
    • View Profile
[XP] Perishable Items
« on: October 13, 2011, 04:48:31 AM »
Perishable Items
Authors: mad.array
Version: 1.0a
Type: Custom Item System
Key Term: Custom Item System

Introduction

This 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

Screenshots
No screenshots, as rotten items are not pleasant to look at!


Script

Insert below default scripts and above Main. Jiggle it about it if it doesn't work!
(click to show/hide)

Instructions

Instructions 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:

Code: [Select]
when 1
    return 400

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):

Code: [Select]
when 1
    return 33

Et voila! Each Potion that you pick up will go off after 20 seconds... so I'd use them fast!

Compatibility

Not 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 Thanks

Please 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 Notes

I'm sure there is a better way of doing this, so if you can think of another method then please contact me.
« Last Edit: January 17, 2012, 12:55:19 AM by mad.array »
"To walk at speed, manage or oversee..."

"RUN!"

Offline Xuroth

  • Awakened Visionist
  • **
  • Posts: 82
  • LV: 6
  • Gender: Male
  • *smite!* oops...
    • View Profile
Re: [XP] Perishable Items
« Reply #1 on: October 13, 2011, 09:43:46 AM »
You know, this is a great idea, mad.array! Excellent Script!

Offline AngryPacman

  • Transcended Spirit
  • ***
  • Posts: 182
  • LV: 5
  • Gender: Male
    • View Profile
Re: [XP] Perishable Items
« Reply #2 on: October 13, 2011, 02:14:02 PM »
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:
Code: [Select]
module RottenItems
  FRAMES = {
    1 => 400
    2 => 2000
    #etc.
  }
  ITEMS = {
    1 => 33
    2 => 34
    #etc.
  }
end
And replace the calculate_perish_time method with this:
Code: [Select]
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:
Code: [Select]
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.
« Last Edit: October 13, 2011, 02:18:06 PM by AngryPacman »
G_G's a silly boy.

Offline mad.array

  • Trained Member
  • *
  • Posts: 26
  • LV: 7
  • Gender: Male
  • Homeless Dev
    • View Profile
Re: [XP] Perishable Items
« Reply #3 on: October 13, 2011, 02:25:29 PM »
@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.
"To walk at speed, manage or oversee..."

"RUN!"

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3248
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: [XP] Perishable Items
« Reply #4 on: October 13, 2011, 06:19:12 PM »
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 am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline AngryPacman

  • Transcended Spirit
  • ***
  • Posts: 182
  • LV: 5
  • Gender: Male
    • View Profile
Re: [XP] Perishable Items
« Reply #5 on: October 14, 2011, 03:38:58 PM »
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
G_G's a silly boy.

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19903
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: [XP] Perishable Items
« Reply #6 on: October 14, 2011, 03:51:37 PM »
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.
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline AngryPacman

  • Transcended Spirit
  • ***
  • Posts: 182
  • LV: 5
  • Gender: Male
    • View Profile
Re: [XP] Perishable Items
« Reply #7 on: October 14, 2011, 04:40:23 PM »
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.
G_G's a silly boy.

Offline Blizzard

  • This sexy
  • Administrator
  • has over 9000 posts
  • *****
  • Posts: 19903
  • LV: 642
  • Gender: Male
  • Magic midgets.
    • View Profile
    • You're already on it. (-_-')
Re: [XP] Perishable Items
« Reply #8 on: October 14, 2011, 05:00:48 PM »
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.
Check out Daygames and our games:

King of Booze      King of Booze: Never Ever      Pet Bots
Drinking Game for Android      Never have I ever for Android      Pet Bots for Android
Drinking Game for iOS      Never have I ever for iOS      Pet Bots for iOS
Drinking Game on Steam


Quote from: winkio
I do not speak to bricks, either as individuals or in wall form.

Quote from: Barney Stinson
When I get sad, I stop being sad and be awesome instead. True story.

Offline ForeverZer0

  • CP's Pedophile
  • Global Moderator
  • Guardian of Chaos
  • ****
  • Posts: 3248
  • LV: 294
  • Gender: Male
  • Remember you are unique, just like everyone else.
    • View Profile
Re: [XP] Perishable Items
« Reply #9 on: October 14, 2011, 06:34:06 PM »
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.
I am done scripting for RMXP. I will likely not offer support for even my own scripts anymore, but feel free to ask on the forum, there are plenty of other talented scripters that can help you.

Offline LiTTleDRAgo

  • Astral Trancist
  • *****
  • Posts: 812
  • LV: 510
  • Gender: Male
    • View Profile
    • ~
Re: [XP] Perishable Items
« Reply #10 on: October 17, 2011, 11:41:08 AM »
Quote
  def rot_item(item_id)
    case item_id
    #when 1
      #return 33
    end
    return fasle
  end

typo?

Offline mad.array

  • Trained Member
  • *
  • Posts: 26
  • LV: 7
  • Gender: Male
  • Homeless Dev
    • View Profile
Re: [XP] Perishable Items
« Reply #11 on: October 17, 2011, 08:42:49 PM »
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!
« Last Edit: October 30, 2011, 05:40:55 PM by mad.array »
"To walk at speed, manage or oversee..."

"RUN!"

Offline newold

  • Trained Member
  • *
  • Posts: 30
  • LV: 12
    • View Profile
Re: [XP] Perishable Items
« Reply #12 on: November 02, 2011, 03:41:12 PM »
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
Download it from Multi-upload:http://www.multiupload.com/3Q0EP50990

You can see the visual configurator tool in this video:

<a href="http://www.youtube.com/watch?v=1uGw27sjqzg" target="_blank" class="new_win">http://www.youtube.com/watch?v=1uGw27sjqzg</a>

(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 ;)
« Last Edit: November 02, 2011, 04:01:03 PM by newold »

Offline mad.array

  • Trained Member
  • *
  • Posts: 26
  • LV: 7
  • Gender: Male
  • Homeless Dev
    • View Profile
Re: [XP] Perishable Items
« Reply #13 on: January 12, 2012, 06:09:11 PM »
@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.
"To walk at speed, manage or oversee..."

"RUN!"

Offline newold

  • Trained Member
  • *
  • Posts: 30
  • LV: 12
    • View Profile
Re: [XP] Perishable Items
« Reply #14 on: January 12, 2012, 07:23:28 PM »
@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