Group: Member
Posts: 98
Type: Musician
RM Skill: Beginner
How can I make certain objects respond only to certain items after you've selected them from the menu. For example, when you get a key all you have to do is walk towards the door and it will automatically open. How can I make it so you have to actually select the item from the menu before you can open the door. And have it so the key item will not do anything when you use it at any other time? Not only for keys but for items as well. Maybe certain npcs react differently when you go near them and select a certain item. I know how to do this by creating an event that turns on a switch that makes the item pull up a common event etc.... but then I have to make a new event to turn off the switch so the item doesnt do it all the time. I know there has to be an easier way. Thanks you in advance,
Group: +Gold Member
Posts: 1,522
Type: Scripter
RM Skill: Undisclosed
That sounds fun
CODE
#============================================================================== # ** VXAce: NR's Using Items #------------------------------------------------------------------------------ # History: # Date Created: 21 May 2012 # Created for: Noob_king # @> http://www.rpgrevolution.com/forums/index.php?showtopic=56447 # # Description: # This script lets you click on an item from the pause menu, and use it on a # pre-configured event. # # How to Intsall: # Copy this entire script. In your game's editor, along the Menu Bar, click # Tools >> Script Editor. # Along the left, scroll down to Materials, right click underneath it, and # select 'Insert' # Paste the code on the right. # # How to Use: # Have a event with a comment command that reads like so: # <UseItem:1,SS:A> # where 1 is the ID of the item (ID is found next to the name of the item in # the Database) you need to use to activate the event, and A is the # self-switch to activate when the item is used. #==============================================================================
module NR_UsingItems Format = /\<UseItem\:(\d+),SS\:([a-zA-Z])\>/ end
#============================================================================== # ** Scene_Item #------------------------------------------------------------------------------ # This class performs the item screen processing. #==============================================================================
class Scene_Item #-------------------------------------------------------------------------- # * Alias Methods #-------------------------------------------------------------------------- alias nr_useItem_start start unless $@ alias nr_useItem_on_item_ok on_item_ok unless $@ #-------------------------------------------------------------------------- # * Start Processing #-------------------------------------------------------------------------- def start(*args) # Create an array of items usable on the map @items_usable_on_map = [] # Get the spot in front of the player player = $game_player x2 = $game_map.round_x_with_direction(player.x, player.direction) y2 = $game_map.round_y_with_direction(player.y, player.direction) # Loop through looking for an event, either under the player or in front positions = [ [player.x, player.y], [x2, y2] ] events = [] for xy in positions $game_map.events_xy(xy[0], xy[1]).each do |event| events << event end end # If an event exists if not events.nil? # Loop through them for event in events # Loop through the event's commands for command in event.list.to_a # If there's a comment if command.code == 108 # If the comment is the correct format item = command.parameters[0].scan(NR_UsingItems::Format)[0] if not item.nil? # List this item as the usable on an event item << event add_to_items_usable_on_map(item) end end end end end # Run the original start return nr_useItem_start(*args) end #-------------------------------------------------------------------------- # * Add to items usable on the map #-------------------------------------------------------------------------- def add_to_items_usable_on_map(item) @items_usable_on_map << {:item_id => item[0].to_i, :self_switch => item[1], :event_id => item[2].id } end #-------------------------------------------------------------------------- # * Item [OK] #-------------------------------------------------------------------------- def on_item_ok(*args) # Loop through each item usable for map_item in @items_usable_on_map # If the usable on map item is selected if item.id == map_item[:item_id] event_id = map_item[:event_id] key = [$game_map.map_id, event_id, map_item[:self_switch]] $game_self_switches[key] = true $game_map.need_refresh = true SceneManager.goto(Scene_Map) return end end # If the item is used normally, process normally return nr_useItem_on_item_ok(*args) end end
#============================================================================== # ** End of Script. #==============================================================================
This script works by activating a self-switch of the event underneath/in front of the player, if the event is configured to accept it, so for example:
See inside
See how there's a comment, is says that this event needs a potion (the item ID 1 corresponds to the first item in the database), and if it is given the potion then it will activate the event's self switch A
And yeah, since Self Switch A is the condition along the left to show this page, it runs...
http://i.1dl.us/u8t.png I ran out of motivation to write an epic NPC, so I'll let you continue it
And that works by going in to the Items screen, and selecting the potion
__________________________
K.I.S.S. Want help with your scripting problems? Upload a demo! Or at the very least; provide links to the scripts in question.
Group: +Gold Member
Posts: 1,522
Type: Scripter
RM Skill: Undisclosed
Pleasure my friend
The thing to always remember about Enterbain is that they always implement what they see as the most new-user friendly option, I assume that they saw implementing a system like this could be confusing to new users, and so they left it to scripters to create.
I've removed the accidental posts, make it a bit easier for people to read what's happening.
__________________________
K.I.S.S. Want help with your scripting problems? Upload a demo! Or at the very least; provide links to the scripts in question.