Help - Search - Members - Calendar
Full Version: Item call a unique script?
RPG RPG Revolution Forums > Game Engines > RPG Maker XP Discussion
superafroboy
Hey folks, is there a way I can have an item call a unique script?

The reason I ask is that I have a crafting script that I quite like, and it has a feature that allows the player to learn new recipes. I'd like to have a shop or something where you could buy different recipes as items, and when used it would call the script necessary to add the recipe. At first I just figured I could have the item call a common event, but from there I don't know how to determine which item the player used to call the event, so I'd have to have a different common event for each recipe, which just seems silly.

Is there something I'm missing somewhere?
Night_Runner
First off, welcome to the forums smile.gif

I'm assuming that the crafting script tells you to run some code, something like:
CODE
learn_recipe( 123 )

and that will unlock the 123rd recipe?

If so, wonderful!

Insert this code before Main in the Script Editor as usual:
Night_Runner's Item Memory Script
[code#===================================================================
===========
# ** Night_Runner's Item Memory Script
#------------------------------------------------------------------------------
# History:
# Date Created: 25/July/2011
# Created for: superafroboy
# @> http://www.rpgrevolution.com/forums/index....showtopic=51842
#
# Description:
# This script is designed to keep track of the last highlited item in the
# inventory screen.
#
# How to Install:
# Select and copy this entire peice of code.
# In your game, select Tools >> Script Editor
# Along the left hand side, scroll all the way to the bottom, right
# click on 'Main', and select 'Insert'.
# Paste the code in the blank window on the right.
#
# How to Use:
# Below on lines 46 & 48 you will find the code:
# $game_variables[10]
# change the 10 to the index of the variable that you would like to use
# to keep track of the last item highlited in the inventory screen
#==============================================================================



#==============================================================================
# ** Window_Item
#------------------------------------------------------------------------------
# Edited to keep track of the item highlited last
#==============================================================================

class Window_Item
#--------------------------------------------------------------------------
# * Alias Methods
#--------------------------------------------------------------------------
alias nr_itemHighlightedMemory_dispose dispose unless $@
#--------------------------------------------------------------------------
# * Dispose
#--------------------------------------------------------------------------
def dispose(*args)
# Keep track of the item
if @data[self.index].is_a?(RPG::Item)
$game_variables[10] = @data[self.index].id
else
$game_variables[10] = -1
end
# Run the original code
nr_itemHighlightedMemory_dispose(*args)
end
end[/code]


And in your common event edit your code so instead of the 123 from before, you have:
CODE
$game_variables[ 10 ]

Where 10 is the variable you chose in the script.


Make any sense at all?
superafroboy
Well that's simply fantastic. I'll try to get that going today and let you know if I need further assistance.

Edit: Yup, your script works perfectly for me, too bad I can't seem to get the recipe function of my crafting script to work properly.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2013 Invision Power Services, Inc.