Select an item when you activate an event and have the script return the item

omnikeith

Veteran
Veteran
Joined
Jan 7, 2015
Messages
34
Reaction score
1
First Language
English
Primarily Uses
So, I've been trying to use select_item_variable_id but that returns the id of the item i need a script call that lets you choose any item or a key item or ideally a key item with a note that I've made. I saw the code $game_message.item_choice but I'm not sure how it works or if it returns the item. Is there a bit of code out there that does what I want?

example:

Code:
Class Game_Event
  def start
    item = #code here to ask the player what item they want to use and return that item
    tag, id = item.note =~ "/^<(seed) (\n)>"/i ? [true, $1.to_i] : [nil, nil]
    if tag
      plant_id = id
    else
      $game_message.add("This item isn't a seed")
      plant_id = 0
    end
  end
end
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,159
Reaction score
14,652
First Language
English
Primarily Uses
RMMV
Are you using Ace? I don't remember if VX had key items or not. Might be an idea to put the engine you're using into your profile.

And, ewww, I wouldn't put it into Game_Event.start - that means EVERY event is going to do this when it starts - transfer events, NPCs, etc - all of them!

What exactly are you wanting to achieve, from the player's perspective?
 

omnikeith

Veteran
Veteran
Joined
Jan 7, 2015
Messages
34
Reaction score
1
First Language
English
Primarily Uses
I was just using start as an example. I curently have it check the events name and exicute the code if its name matches. Everything else in my script seems to work. I just need to be able to access item.note from a game event to check and see if the item has the note: <seed 1> where one is any number and then save that number to a variable.

I am using rpg maker vx ace
 

omnikeith

Veteran
Veteran
Joined
Jan 7, 2015
Messages
34
Reaction score
1
First Language
English
Primarily Uses
I'm still looking for help. Please help me find the right code to ask the player to pick an item and hold that item in a variable
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,516
Reaction score
8,147
First Language
German
Primarily Uses
RMMV
There is a problem with helping you, because we do not und er stand what you want to achieve - you only tell us how you want to do something, not what that something is ingame.

That is why shaz asked above what you want to achieve from the players point of view, a question you didn't answer at all, you only repeated how you want to do that unknown something.

So please describe what should happen in the game, then we can tell you how to do that best.
 

omnikeith

Veteran
Veteran
Joined
Jan 7, 2015
Messages
34
Reaction score
1
First Language
English
Primarily Uses
okay... from a programmers point of view i thought i explained the code i need pretty well. but here is what i want the player to see. I want a screen to pop up when the player activates an event and have the player choose a seed to plant. when the seed is selected the event starts a count down for the plant to grow and when it is fully grown the player can harvest it. Now, don't give me all the code for that because I have most of it. I just need a bit of code for the item select screen. I tried implementing select_item_variable_id but that just return the id of the item and from what I can tell i cant access the note of an item from it's id. I need to access the item note as written in the first posts code to to determine what seed id the item has.
 

omnikeith

Veteran
Veteran
Joined
Jan 7, 2015
Messages
34
Reaction score
1
First Language
English
Primarily Uses
Here is all my code so far. you should be able to determine what it should look like from this. I think I read somewhere that I need to put a piece of code in that yields the code until input is given. That may be my problem but item.note keeps throwing an error.

Code:
module FARM_PARAMS
 
  SEED = 21
 
end

FARMING_OBTAINED_STRING = '"Obtained \\\i[#{item.icon_index}] #{item.name} x#{amount}."'
FARMING_GATHERFAIL_STRING = "Failed to gather resource."
FARMING_LOWLEVEL_STRING = '"Level #{node_data[:level]} required."'
FARMING_TOOLREQ_STRING = '"Tool \\\i[#{item.icon_index}] #{item.name} required."'

Plant = {
  #turnip
  1 => {:item => [:item,17,[1,4]],
        :level => 1,
        :timer => 1,                      #in-game hours until grown
        :base_chance => 75,
        :max_chance => 100,
        :chance_mod => 5,
        :graphic => ["$Turnip",0],
        :sound => ["Jump1",75,1,3]},
        :persist => "false",
      
}



class Game_Event
  alias farm_update update
  alias gather_start start
  alias farm_init setup_page
  def setup_page(*args)
    farm_init(*args)
    @@empty_plot = true
    @@days_to_grow = 0
    @@hours_until_full = 0
    @@plant_id = 0
  end
 
  def event_timer(rate)
    if farm_data != nil
      @@hours_until_full += rate if @@hours_until_full < farm_data[:timer].to_i
      return farm_data[:timer].to_i - @@hours_until_full
    else
      return 0
    end
  end
  def farmland
    @event.name.include?("Farmland")
  end

  def farm_data
    Plant[@@plant_id]
  end
  def start
    farmland ? farm_start : gather_start
  end
  def grown
    if event_timer(0) <= 0 && empty_plot == false
      return true
    else
      return false
    end
  end
  def anim_stages
    if farm_data != nil
      if @@days_to_grow < farm_data[:timer].to_i / 4
        @@days_to_grow = 0
        if @@dir < 8
          @@dir += 2
        end
        @direction = dir
      end
    end
  end
  def farm_start
    if @@empty_plot == true
      $game_message.add("What would I like to plant?")
      $game_message.item_choice_variable_id = FARM_PARAMS::SEED
      item = $data_items[$game_variables[FARM_PARAMS::SEED]]
      tag, id = item.note =~ "/^<(seed) (\n)>"/i ? [true, $1.to_i] : [nil, nil] #item.note returns an error of note on nil value.
      if tag
        @@plant_id = id
      else
        $game_message.add("This item isn't a seed")
        @@plant_id = 0
      end
      if @@plant_id != 0
        return no_tool if !carrying_tool?
        return no_level if farm_data[:level] > $game_party.highest_level
        #persist = farm_data[:persist].to_s == 'true' ? true : false
        graphic = farm_data[:graphic]
        @character_name = graphic[0]
        @character_index = graphic[1]
        @@days_to_grow = 0
        @@dir = 8
        @direction = dir
      end
    end
    if grown
      $game_party.gathering = true
      if gather_success
        item_d = farm_data[:item]
        item = $data_items[item_d[1]] if item_d[0] == :item
        item = $data_weapons[item_d[1]] if item_d[0] == :weapon
        item = $data_armors[item_d[1]] if item_d[0] == :armor
        msgbox("Invalid item category") unless item
        amount = rand(item_d[2][1] - item_d[2][0]) + item_d[2][0]
        $game_party.gain_item(item,amount)
        $game_message.add(eval(FARMING_OBTAINED_STRING))
      end
      if farm_data[:sound]
        farm_data[:sound][2].times do |i|
          Audio.se_play("Audio/SE/" + farm_data[:sound][0],farm_data[:sound][1])
          node_data[:sound][3].times do |i|
            Graphics.update
            SceneManager.scene.update
          end
        end
      end
      $game_party.gathering = false
    end
  end
  def carrying_tool?
    if plant_id != nil
      item_d = farm_data[:tool]
      return true if item_d.nil?
      item = $data_items[item_d[1]] if item_d[0] == :item
      item = $data_weapons[item_d[1]] if item_d[0] == :weapon
      item = $data_armors[item_d[1]] if item_d[0] == :armor
      return $game_party.has_item?(item)
    end
  end
  def unerase
    @erased = false
    refresh
  end
  def erased?; @erased == true; end
  def event_id; @id; end
  def no_level
    $game_message.add(eval(FARMING_LOWLEVEL_STRING))
  end
  def no_tool
    if plant_id != nil
      item_d = farm_data[:tool]
      item = $data_items[item_d[1]] if item_d[0] == :item
      item = $data_weapons[item_d[1]] if item_d[0] == :weapon
      item = $data_armors[item_d[1]] if item_d[0] == :armor
      $game_message.add(eval(FARMING_TOOLREQ_STRING))
    end
  end
  def gather_success
    if plant_id != nil
      empty_plot = true
      chance = farm_data[:base_chance]
      chance += farm_data[:chance_mod] * ($game_party.highest_level - farm_data[:level])
      chance = [chance,farm_data[:max_chance]].min
      if rand(100) < chance
        return true
      else
        $game_message.add(FARMING_GATHERFAIL_STRING)
        return false
      end
    end
  end
end

class Game_Map
  alias farm_set setup_events
  alias farm_up update_events
  def setup_events
    farm_set
    @events.each_value do |event|
      next unless event.farmland
      event.erase if event.event_timer(0) > 0
    end
  end
  def update_events
    farm_up
    @events.each_value do |event|
      next unless event.farmland && event.erased?
      event.unerase if event.event_timer(0) == 0
    end
  end
end
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,516
Reaction score
8,147
First Language
German
Primarily Uses
RMMV
In that case, you don't need any script at all, you only need to make all seeds as key items and use the event command "select key item".
That command will open a window with all key items, and store the ID of the selected item into the variable decided in the command.

Even if you can't use the event command, you should use that as an example on how to do what you want. Additionally there is a script out there (i think seither from galv or tsukihime) that modifies this command to allow regular items to be selected.
 

omnikeith

Veteran
Veteran
Joined
Jan 7, 2015
Messages
34
Reaction score
1
First Language
English
Primarily Uses
You obviously didn't read what i posted in regards to my script. What i want done can't be done in just the editor. I sugest you read the script i posted and then see if your sugestion is relevant. My script uses a timer and an array of seeds with their own variables that would take forever to enter in each seed into the event then have the event change image as it ages and have each seed change how the event responds. My script is sound it just needs a minor adjustment that i cant figure out. If you can't read code or don't know enough to answer my question, then please dont respond with unhelpful posts.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
32,516
Reaction score
8,147
First Language
German
Primarily Uses
RMMV
No, i didn't have time to read the code - but that is why I suggested you check the code for the event command and use that as a guide if you can't use the command directly.

There is no default way to read notetags in Ace because the notebox was never intended to be used for data transfer in the original concept. Only after the community of scripters found this to be a workaround for data assignment, in the case of MV the meta function was added there. But in Ace, nothing like that exists and you need to program any notetag reading completely yourself.

And due to the complexity of the game loop, it will be easier to implement that not AS an automatic check on all events (even on those that have nothing to do with planting), but on call from the events themselves, and split into two parts. The first part would be to get the player to select the ID of the item, and then to access the notes from that item.

For the first part it was my suggestion to use the select item command if possible or program your own with that as a guideline, for the second part there are several tutorial available on how to access the notedata and to create a regex to filter any notetags for the data you want.
I don't have the links because my main computer is down, but if I remember correctly one of those tutorials was written by fomar.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,159
Reaction score
14,652
First Language
English
Primarily Uses
RMMV
Seems like you are trying to make a Harvest Moon type game. There are scripts out there already that do this, so it might be worth grabbing some of them and seeing how they do things. I'm thinking of allowing you to decide what to plant where, the timer for it being ready to harvest, they probably also have watering/tending requirements which you may or may not want, and then showing the correct image depending on what seed was planted.

How many different types of seeds are you after?

If you have all your seeds set as key items and they are the ONLY key items you are using, then you can simply use Select Key Item and put the item number into a variable. Then you would need to run a script call to grab the details that you're after from the note. Unfortunately, this will require some regular expression magic and that's something I struggle with, which is why I haven't replied again. But if you can figure out regular expressions, you'd be able to get the info you want from the note just using a single script call after getting the item id into a variable. No entire script needed.

Self Variables might also be of use to you, as a way of recording what kind of seed is planted in each location. There are some scripts around for that - one that comes to mind is PK8's Self Data Suite.

I haven't looked at your script, but it sounds like you're trying to do the whole thing in a single script. I wouldn't do it that way - I'd break it up into 3 distinct things: selection of seed and getting of the note data (as already mentioned, you can do this using the existing command and a script call, if your items are set up in a suitable way); timer for event to harvest (I already have an extended game timers script that could be used for this); and the harvesting. You might find it easier if you try and keep those as separate, distinct ideas and design/code for them accordingly.
 

omnikeith

Veteran
Veteran
Joined
Jan 7, 2015
Messages
34
Reaction score
1
First Language
English
Primarily Uses
my timer/calendar script is separate and i would love to use a pre-made script for this but the only one i could find out on the internet doesn't do what i want it to do. i have the self variables script but it takes a bunch less work programming everything in scripts instead of filling out an event with like a hundred conditional branches and when i add pages the script from one page has a hard time interacting with scripts from another page. I have other key items other than seeds so only making key items seeds is not going to work as well as being just plain bad coding. I tried to cache all my item note tags in a separate script but i was having trouble implementing it and another user told me not to do it that way. If I should attach a variable to each item with the seed note tag and record them at start how would I go about doing that because last time I tried the code was broken.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
42,159
Reaction score
14,652
First Language
English
Primarily Uses
RMMV
i would love to use a pre-made script for this but the only one i could find out on the internet doesn't do what i want it to do

you'd love to use a premade script for which part exactly? What did you find, and what didn't it do that you needed it to?
 

Bex

Veteran
Veteran
Joined
Aug 2, 2013
Messages
1,502
Reaction score
412
First Language
German
Primarily Uses
RMMV
What about planning?
If you know that in the Database the Item Ids 70 to 150 are Seeds, than when getting the selected Item ID via Script or via Select Item Eventcommand, than one just needs 2 conditional branches/if conditions:
Is VariableX equal or more 70 and is it equal or less 150?
If yes: Its a Seed.
If no: This Item is not a Seed.
Thisway you dont need a Item tag.

The Problem is if your Seed Item Ids are scattered. Than you cant solve it with an easy range condition.
EDIT:
OHOH i have no Idea how it happened that i necroposted, just realised it, please delete the Post.
 
Last edited:

Latest Threads

Latest Profile Posts


I'm proud of what I have achieved with my project. Don't mind with the Spanish, Ill add more languages.
Our garage has been so full since moving we haven't been able to get our car in. Storm night before last (no hail), storms forecast for last night & today. I convinced hubby we should clean out the garage and we managed to get it done and get the car in. Hail last night! Just in time!
Taller RTP Characters, Rewrite Dialogues w/ AI, & Simple Event AI & Shooting | RPG Maker News #37


No water this time, just trying for a majestic cliffside... The cave snuck in because I liked it. Now I guess I need a mini cave map or "secret" for it. :kaoswt:
Revamped the crew for my VN about thirty times. Only character that's stayed constant has been the fungus character. Guess it really grew on me...

Forum statistics

Threads
111,278
Messages
1,059,842
Members
144,575
Latest member
pvralston22
Top