Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Tent only useable when save is enabled.

I'm not sure if anyone else has posted this but what the heck...

This is a simple script I made that disables the use of a 'Tent' item when save is disabled, like in Final Fantasy games.

All you have to do is copy and paste above main and put the ID of the Tent item next to @TENT.
eg:
@TENT = 13

Code:
# FINAL FANTASY STYLED TENT USE

# ----------------------------

# A simple script that makes Tents only useable when save is enabled

# ----------------------------

# How to use:

# Copy and Paste above Main

# Put the ID of item you want to be tent next to @TENT

# ---------------------------

# Now whenever Save is disabled, these items will be too!

#-------------------------

 

class Game_Party < Game_Unit

  def item_can_use?(item)

    return false unless item.is_a?(RPG::Item)

        return false if item_number(item) == 0 

 #=======================

@TENT =  #ID Number of the Item you want to be a tent!

#========================

    if $game_temp.in_battle

      return item.battle_ok?

    else

      return item.menu_ok? unless $game_system.save_disabled == true && item == $data_items[@TENT]

    end

  end

  end

So far I've only been able to get it so you can only have one item id disabled. I'm trying to work out how to use the [1,2,3] etc list thingy.
 
To expand on it for multiple items you could do this
Code:
# FINAL FANTASY STYLED TENT USE

# ----------------------------

# A simple script that makes Tents only useable when save is enabled

# ----------------------------

# How to use:

# Copy and Paste above Main

# Put the ID of item you want to be tent next to @TENT

# ---------------------------

# Now whenever Save is disabled, these items will be too!

#-------------------------

 

class Game_Party < Game_Unit

  def item_can_use?(item)

    return false unless item.is_a?(RPG::Item)

        return false if item_number(item) == 0 

 #=======================

@TENT =  [1, 2, 3]#ID's of multiple tent items

#========================

    if $game_temp.in_battle

      return item.battle_ok?

    else

      return item.menu_ok? unless $game_system.save_disabled == true && @TENT.include?(item.id)

    end

  end

  end

This allows for multiple tent items.

Though nice idea! Surprised no one else has thought of it =D
 
Ah so that's how its done. Thanks. Yeah I'm surprised no one else did one either. I'm making a nostalgic FF fan game on VX out of boredom and was looking for a tent so I couldn't find one and made it myself :)

Anyways, I've tidied it up a little so it's easier to find where to put the item IDs. I'll work on it a little more in the future, maybe add more features and stuff, for example items disabled until you have a certain amount, or disabled when a switch is ON/OFF. Stuff like that. ^_^

Tidied up version with multiple ids:
Code:
# FINAL FANTASY STYLED TENT USE

# ------------------------------------------------

# Special thanks to game_guy from hbgames.org for helping with using 

# multiple IDs XD

# -------------------------------------------------

# A simple script that makes Tents only useable when save is enabled

# -------------------------------------------------

# How to use:

# Copy and Paste above Main

# Put the ID of items you want to be disabled in ITEMS_SAVE = [] 

# -------------------------------------------------

# Now whenever Save is disabled, these items will be too!

#=======================================

module Tent

 

ITEMS_SAVE = [] 

#ID(s) of items to be disabled when save is disabled, eg [1,2,3]

 

end

#=======================================  

class Game_Party < Game_Unit

  def item_can_use?(item)

    return false unless item.is_a?(RPG::Item)

        return false if item_number(item) == 0

@tent =  Tent::ITEMS_SAVE 

    if $game_temp.in_battle

      return item.battle_ok?

    else

      return item.menu_ok? unless $game_system.save_disabled == true && @tent.include?(item.id)

    end

  end

  end
 
Good idea but there are some (code specific) things which could be better :)

Code:
class Game_Party

  

  TENT_ITEMS = [1, 2, 3]

  

  alias_method :nb_itemcanuse_notents, :item_can_use?

  def item_can_use?(item)

    if $game_system.save_disabled and TENT_ITEMS.include?(item.id)

      return false

    end

    nb_itemcanuse_notents(item)

  end

end

I changed some things:
- removed the < Game_Unit, because I think this can cause errors.
- added the constant (TENT_ITEMS) into Game_Party and not into a new Module, which is not necessary
- used alias instead of rewriting the full method
You should apply those changes to your script as well :)

Anyway, even this script is short, I think it'll help some people.
 
I like the idea of this script, and with Bahamut's edits, it even follows some coding style :p The only thing bothering me is the nb_itemcanuse_notents symbol, which name-wise makes absolutely no sense (you should know better!) and is kinda cocky, considering you put your initials in there, Bahamut... :huh: It should be something like tentrestrict_item_can_use (aka putting a single word inbefore the original - unchanged - method name for the alias to get closer to maximum readability; also it shouldn't contain any nicknames or initials whatsoever...)

Either way, I like the idea of this, even though it goes more towards remaking Final Fantasy with RM** ^^ You - oblivia5 - should definately work n your scripting style a bit more to get some consistency into it... and I also see a bunch of indentation errors in your first version. Either way, as you're a somewhere between beginning and advancing scripter, consider this a good script that needs some improvement while you need to be more careful on your next one ;)

Keep up the good work.
 
@ BlueScope: Well, my full alias names (in complex scripts) would be:
nb_aliasmethod_no_tents_without_save_game_party_item_can_use
Pretty long, so I just put the class and method names into a single word :)

And the nb, I saw some other scripters doing this as well (for example Trickster I think) so I used it too :)
That are only 3 characters so this doesn't affect readybility that much ;)
 

Atoa

Member

It's also easy to make this script work on XP
Code:
class Game_Party

 

  TENT_ITEMS = [1, 2, 3]

 

  alias_method :nb_itemcanuse_notents, :item_can_use?

  def item_can_use?(item_id)

    if $game_system.save_disabled and TENT_ITEMS.include?(item_id)

      return false

    end

    nb_itemcanuse_notents(item_id)

  end

end

@BlueScope
I also add my "nick" on my alias, it's an way to ensure that no one ever will use an same alias as mine (i've already saw many scripts using things such as "old_initialize", wich may cause conflits).
Also it's an good way to avoid noobs from trying to claim your system as their own, since most of them are so stupid to change the name on the alias XD (This already happened with me, an noob removed my name from the header, but on the code there was a lot of alias with "atoa")
 
@Atoa/Bahamut: I'm well aware of everyone doing this, and I blame Seph, who actually started it. Now, that totally doesn't keep me from trying to beat it out of people, as while you (Bahamut) say it doesn't affect readability much, I heavily disagree: You effectively add a factor that has nothing to do with the script itself, nor the program, nor anything. Sure, it's the name of the author, but really, the last thing I care about when viewing a script is the author, who is long in my credits list by the time a script ends up in my script library (and if he/she isn't, chances are the person using the script doesn't care). It's like naming a method heydihoo_initialize just because you can - sure it's unique, sure it does serve the purpose of avoiding coincidentially doubled aliasing, but it is still bad scripting style...
Imagine you'd use global variables instead of all local/instance/class variables - you avoid the fact that a variable couldn't be accessible from somewhere, and you only loose some performance and logic in return. It just doesn't make any sense, and the reason why noone cares about it is that famous scripters in here were always saying "global variables are bad", and "put your nicknames in your aliases to reward people who are too lazy to move a finger when inserting scripts in their projects"...

Now, don't get me wrong... I'm not trying to say you guys are sheeps doing whatever you saw someone else do, and neither am I saying I'm perfectly right with what I'm posting here. Either way, it's my opinion that you should avoid redundancy and confusion as much as possible, and nicknames in aliases definately fill both criteria.

On a side note, if any other script uses tentrestrict_item_can_use, you're welcome to link me up (meaning with all the precautional naming going on, I'm yet to see a duplicated alias coming up anywhere if the alias is properly named like my example is).

As for identifications, what can I say... you can perfectly prove it's your code with the code... no need for any hidden names whatsoever. On top of that, the reason why they're not removing these parts is that maybe they don't understand what they do (talking about how they apparently aren't confusing at all ;) )
 
The first thing I care about when using alias is the uniqueness of my names.
Before I used "nb_aliasmethod_scriptname_classname_methodname" I just put random characters together (asuifbsdglusn) :)
I don't care that much about readability because I don't read the alias names either. At the moment I am trying to put a lot of Battle System Addons together for my project and whenever an error occures the script editor jumps to that line automatically. And when I still need more information about that method I just use the search function. So with those two tools/functions you can easily find the original names even of methods like "asuifbsdglusn" ;)

I can understand that other people care more about understandable method names than I do so I will stop filling this thread with offtopic content :thumb:
 
It's not just that "other people" care about some aliased methods nomenclature, it's about letting people get the idea of what you're aliasing. If some noob reads something like this...

alias adfasdf read_save_data

...he or she'll think it's going to do something different than just aliasing a method. Why? Because its own name doesn't tell them it has some connection with the actual aliased method.
 

Zeriab

Sponsor

You can generalize to deal with items being restricted based on switches being turned on and off.
I know this is not completely the same, but you can have an Enable Save and a Disable Save common event which also turns a switch on and off. I'd recommend such a structure anyway since it gives you more freedom for later changes.

Here is a quick'n'dirty script illustrating the concept:
[ruby]# Item switches stuff
module ItemSwitches
  @@items = {}
 
  module_function
  def add(item_switch)
    @@items[item_switch.item_id] = item_switch
  end
 
  def usable?(item)
    if item.is_a?(RPG::Item)
      return true if @@items[item.id].nil?
      @@items[item.id].usable?
    else
      return true if @@items[item].nil?
      @@items[item].usable?
    end
  end
end
 
##
# All switches must be ON for the item to be usable
#
class ItemSwitch < Struct.new:)item_id, :switches)
  def initialize(item_id, *args)
    if args.size == 0
      raise ArgumentError.new("No switches given")
    end
    super(item_id, args.flatten)
    ItemSwitches.add(self)
  end
 
  def usable?
    return false if $game_switches.nil?
    for switch in switches
      if switch.is_a?(ItemSwitch)
        return false unless switch.usable?
      elsif !$game_switches[switch]
        return false
      end
    end
    true
  end  
end
 
##
# At least one switch must be OFF for the item to be usable
#
class ItemNotSwitch < ItemSwitch
  def usable?
    !super
  end
end
 
##
# The item is usable if one or more switch is ON.
# All switches must OFF for the item to be unusable.
# (Unless something else causes it)
#
class ItemOrSwitch < ItemSwitch
  def usable?
    return false if $game_switches.nil?
    for switch in switches
      if switch.is_a?(ItemSwitch)
        return true if switch.usable?
      elsif $game_switches[switch]
        return true
      end
    end
    false
  end  
end
 
##
# No switches must be ON for the item to be usable
#
class ItemNotOrSwitch < ItemOrSwitch
  def usable?
    !super
  end
end
 
##
# Integration
#
class Game_Party < Game_Unit
  alias zer_switch_item_can_use item_can_use?
  def item_can_use?(item)
    # Just to make sure we are deaing with an RPG::Item
    return false unless item.is_a?(RPG::Item)
    # Check that it is usable according to the switches
    return false unless ItemSwitches.usable?(item)
    # Return normal result
    zer_switch_item_can_use(item)
  end
end
 
#################
# CUSTOMIZATION #
#################
ItemSwitch.new(21,1,2)
ItemNotSwitch.new(12,1)
ItemOrSwitch.new(2,1,2)
[/ruby]

Working demo: http://www.mediafire.com/?bkvep7nmscef2nu

Note that ItemOrSwitch and item ItemNotOrSwitch are not necessary, but they do make life easier.


@blue:
There is a prevalence of aspect oriented design for modular scripts in the rm communities.
Consider problem of you wanting to change the behavior of a method where you want to use the old method for something. A solution is create an alias for the old method so you can refer to it while outside calls refer to the new method.
This introduces the problem of creating a proper alias. It should tell you that it is the old version of the method. As you say the most common naming scheme is GUID_aspect_method. Some also include class name, but more often than not I find that being clear from the context. (GUID is an acrynom for global unique identifier, which typically is an acronym for the scripter)
For this purpose alone the GUID is superfluous. The aspect tells you which script has overwritten it and the method which method was overridden.

The picture changes if you consider the problem of compatibility. The convention of each scripter having their own unique identifier is nice because it is more reasonable to assume that a scripter is aware of his or her own work than the work of all scripters. It is possible that two scripters name the aspect the same even if they are not trying to do the same thing which could happen due to the ambiguity of the chosen word. What they did could be independent and not attaching their GUID could be the only reason for the two scripts not being compatible.
It increases compatibility at the price of readability.

I do not think you should add the GUID if you are working on your own game, but for modular scripts which you publish for everyone? I think that adding the GUID is better than the alternative.

*hugs*
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top