Jump to content
kal

Ruby/RGSS3 questions that don't deserve their own thread

Recommended Posts

This is probably something simple so I'm posting it here rather than its own thread. Using the tag manager script:

 

http://himeworks.com/2013/03/tag-manager/

 

What would be the script call to check if any item in the inventory has a specified tag? Like if I tag some items "bossdrop" and I want to check if any of them are in $game_party.items? Thanks for your help!

Share this post


Link to post
Share on other sites
4 hours ago, staticispuink said:

This is probably something simple so I'm posting it here rather than its own thread. Using the tag manager script:

 

http://himeworks.com/2013/03/tag-manager/

 

What would be the script call to check if any item in the inventory has a specified tag? Like if I tag some items "bossdrop" and I want to check if any of them are in $game_party.items? Thanks for your help!

 

To check if any item in inventory contains a specific tag, use:

$game_party.items.any? {|i| i.tags.include? "tag"}

The code above returns either true or false, depending if there is an item with the specified tag in inventory.

 

Replace "tag" with the one you're looking for. For example;

$game_party.items.any? {|i| i.tags.include? "bossdrop"}

 

Share this post


Link to post
Share on other sites
1 hour ago, Rikifive said:

$game_party.items.any? {|i| i.tags.include? "tag"}

 

Actually, that'll likely be useful to me as well, since that script in particular is one of my most commonly used. So, double thanks. lolz

Share this post


Link to post
Share on other sites

I've always wondered the following:

How does one check the eight tiles surrounding the player for region and terrain IDs, without a lot of complicated eventing? I'm sure there's a way, just not sure how to check this.
 

Share this post


Link to post
Share on other sites

On a related note, possibly a more complex question about the tag manager: how would I go about finding the number of items in the inventory of a certain tag? I.e. the total number of "bossdrop" items added together.

 

Thanks again.

Share this post


Link to post
Share on other sites

So Im trying to do something really simple, however I have no scripting ability whatsoever. I simply need a script that copies the variables of an actor and saves them to a file. Then I need a script that then refers to that file and copies the variables to the currently played actor. The reason I need this is to make it to where a player who was offline can log in to a server that has different variables and switches saved for the actor they are taking over. An event would then reset all of the actors progress reducing level and stats to beginning status, then once the player has logged in the script call would then copy the variables from the file to the character thus bringing offline progress in to the online server. This is the last hurdle I have to jump before the framework for my game is complete. Any help would be greatly appreciated and credited.

 

Share this post


Link to post
Share on other sites

... That really doesn't sound simple at all! I mean, I guess the Ruby part isn't complex, but...


Anyway! You know VX Ace already kinda has a way to do this right? It's called saving and loading the game... Okay okay, so you obviously don't want to save and load the whole game do you? You want something like this right?

 

Spoiler

 


module DataManager

  def self.make_actor_filename(id)
    sprintf("Actor%02d.rvdata2", id)
  end
  
  def self.save_actor(id)
    File.open(make_actor_filename(id), "wb") do |file|
      Marshal.dump($game_actors[id], file)
    end
  end
  
  def self.load_actor(id)
    File.open(make_actor_filename(id), "rb") do |file|
      $game_actors[id] = Marshal.load(file)
    end
  end
  
end

 

 

 

With that you can use DataManager.save_actor and DataManager.load_actor to save an load any individual actor you want! No need to reset them first or copy individual variables, it will just save and load the whole object at once. So that's all you need right?

 

... Except that you said this:

Quote

The reason I need this is to make it to where a player who was offline can log in to a server that has different variables and switches saved for the actor they are taking over.

 

Variables and switches? You mean for events? Those have nothing to do with actors. An actor is just made up of stats and other battle info and that's it. Saving and loading an actor wouldn't effect variables and switches. Also what about the player's inventory? That's stored with the party's information, not the actor's. What else do you want to be able to keep track of? The player's location? Yeah, that's got nothing to do with actors either.

 

Are you sure you just don't want to save and load the whole game after all?

 

Or maybe I am completely off base and what you really need is a way to translate data to some format you can easily read elsewhere like .json or something?

Edited by Kayzee

Share this post


Link to post
Share on other sites

Yo is it possible to make new class variables in superclasses like RPG::BaseItem? Every time I try to alias the initialize method or attr_accessor a new variable ":new_var" @new_var = 0", that variable stays at "nil" but things like "@id" and "@description" still work. 

I'm trying to create a "reinforcement" variable on weapons and armor, and even tried using the RPG::Weapon, RPG::Armor, and RPG::EquipItem superclasses. 

Share this post


Link to post
Share on other sites
2 minutes ago, BrandonKaminari said:

Yo is it possible to make new class variables in superclasses like RPG::BaseItem? Every time I try to alias the initialize method or attr_accessor a new variable ":new_var" @new_var = 0", that variable stays at "nil" but things like "@id" and "@description" still work. 

I'm trying to create a "reinforcement" variable on weapons and armor, and even tried using the RPG::Weapon, RPG::Armor, and RPG::EquipItem superclasses. 

 

Well technically yes, but there is usually little point in really doing so for the classes in the RPG module such as RPG::BaseItem. The RPG module classes are just for holding data imported from the editor. It's sometimes handy to add new methods to the classes and to 'cache' the results of things like when parsing note tags, but other then that adding things to those classes doesn't accomplish much. Also, the initialize method only runs if you are creating new objects. Since all of the RPG module classes are loaded from files, it's not used. It's possible to set the default value in another way actually but again it's kind of pointless.

 

In case you are confused as to why is it pointless exactly, let me explain a bit more. As I said, the RPG module classes are just for holding data imported from the editor. When you say you want to make a "reinforcement" variable on weapons and armor, it implies to me a variable you can change in game, maybe even for individual copies of items. But the RPG module classes are lists of the properties of each item type, not of each actual item in the player's inventory. Also the RPG module classes are never saved anywhere by the game, just loaded from some files and used as a reference. The inventory system in VX Ace is very simple for the most part and wasn't really designed for items to be tinkered with on the fly.

Share this post


Link to post
Share on other sites
2 minutes ago, Kayzee said:

 

Well technically yes, but there is usually little point in really doing so for the classes in the RPG module such as RPG::BaseItem. The RPG module classes are just for holding data imported from the editor. It's sometimes handy to add new methods to the classes and to 'cache' the results of things like when parsing note tags, but other then that adding things to those classes doesn't accomplish much. Also, the initialize method only runs if you are creating new objects. Since all of the RPG module classes are loaded from files, it's not used. It's possible to set the default value in another way actually but again it's kind of pointless.

 

In case you are confused as to why is it pointless exactly, let me explain a bit more. As I said, the RPG module classes are just for holding data imported from the editor. When you say you want to make a "reinforcement" variable on weapons and armor, it implies to me a variable you can change in game, maybe even for individual copies of items. But the RPG module classes are lists of the properties of each item type, not of each actual item in the player's inventory. Also the RPG module classes are never saved anywhere by the game, just loaded from some files and used as a reference. The inventory system in VX Ace is very simple for the most part and wasn't really designed for items to be tinkered with on the fly.

tch, I should've known. The answer was in front of me, they were modules, not actual classes.

Do you think I should go at this through Game_BaseItem instead and put my class variables and methods there?

Share this post


Link to post
Share on other sites

That might work, I'm not sure.

My query is for @Kayzee; So, with Neon Black's Character Customization script, say I want to have some graphic bit be able to be custom color, but it is already attached to some equipped item. How would I go about making this happen? (I meant to ask about this days ago lol)

 

Share this post


Link to post
Share on other sites
6 hours ago, BrandonKaminari said:

tch, I should've known. The answer was in front of me, they were modules, not actual classes.

Do you think I should go at this through Game_BaseItem instead and put my class variables and methods there?

 

Well... I hate to make things needlessly confusing but... When I say 'the RPG module classes' I don't mean they aren't classes, I mean they are defined inside a module called 'RPG'. They are in fact actual classes not modules. Defining things inside modules is kinda the main way Ruby does namespaces you see. You might notice some scripts like to use modules in modules for configuration constants. This is mostly so the configuration is in a unique namespace in case other scripts use some of the same names you see. Even I end up doing it, like at the beginning of my word wrapping script! You can also put classes and other stuff in modules for the same reason, but scripts rarely do so. Actually, the names of classes and modules are really just constants that hold the class or module object! :P

 

Also... While I am being nitpicky, variables that start with '@' are actually usually called 'instance variables' not 'class variables'. Usually the term 'class variable' usually refer to a different type of variable that starts with '@@' instead and are part of the class object it's self. Yeah, sometimes Ruby can be kinda hard to explain properly because the difference between a 'class' and an 'instance of a class' actually a fairly abstract philosophical concept.

 

All that aside, Game_BaseItem would be the better place for your variables and methods, but I don't think it's quite as simple as that because I don't think a lot of things actually use it. For the most part the default scripts just reference items by their index number in the database. It's actually requires a lot of scripting to overcome this limitation. Trust me, I basically ended up overhauling VX Ace's whole inventory system for my game. You might want to look at what is known as 'instance items' scripts, like this one. Not sure if it's really that good or what other ones are really available now and how well they work. I ended up working with an old buggy one the author of that one made that isn't supported anymore because it had some big design flaws, but by the point the new one came out I have totally redone most of it myself to make it work the way I want and really heavily customized it. I mean I could maybe give you some of the code I use, but it sort of turned into a huge cobbled together monstrosity over the years and I would probobly need permission too.

 

46 minutes ago, PhoenixSoul said:

So, with Neon Black's Character Customization script, say I want to have some graphic bit be able to be custom color, but it is already attached to some equipped item. How would I go about making this happen? (I meant to ask about this days ago lol)

 

You mean recoloring an individual item? Are you using a instance items script yourself? You tried them out before I think, but I thought you said it was too much to bother with? I actually wrote something to do this for my game, but it would require my mess of a inventory overhaul to work right so...

Edited by Kayzee

Share this post


Link to post
Share on other sites
1 hour ago, Kayzee said:

You mean recoloring an individual item? Are you using a instance items script yourself? You tried them out before I think, but I thought you said it was too much to bother with? I actually wrote something to do this for my game, but it would require my mess of a inventory overhaul to work right so...

 

Yes, recoloring an already equipped item using the script call. No, no instance items here.

Like, for example, one can create a layer to be applied and recolored, but since the equipped item has a hue tag already, I want to be able to change that, and that alone. If you've ever played a game where one can change the color of their equipment (usually a paywalled feature-it was so in DragonFable), that's what I'm talking about. The item is already equipped, but the color should still be customizable. Does that make sense, or do I need to provide some visuals or something?

Edited by PhoenixSoul

Share this post


Link to post
Share on other sites

Naw I think I know what you mean. Well, what I did to change the colors is basically to edit make_equip_hashes to change what it sets the @equip_hashes to, maybe something like this:

 

  def make_equip_hashes(block)  ## Makes the handler hash for equips.
    @equip_hashes = {}
    equips.each do |eq|
      next unless eq
      eq.composite_hash.each do |key, array|
        next if Composites.files[array[0]][male? ? 0 : 1].nil?
        arr = array.dup # need to dup to prevent bugs
        arr[1] = 0 # set what you want the hue to be here
        @equip_hashes[key] = arr
      end
    end
  end

 

Share this post


Link to post
Share on other sites

Hmmm... so, that is a separate scriptlet?
 

What this seems to miss is when the custom composite scene is brought up (yeah I meant that). This just forces a specific value when the recoloring is meant to be done by the end user/player...via the hue bar in the scene...

 

(I'm tired...of course I have to try to figure this out now lolz)

 

Share this post


Link to post
Share on other sites

Oh! You want to be able to change the colors that way? That makes a lot of sense. For some reason I thought you wanted to have your own special way of recoloring the equipment. I don't know why, I used the composite scene for recoloring clothing in character creation myself. Now let me see... ... ... Ah! This should work I think:

 

  def make_equip_hashes(block)  ## Makes the handler hash for equips.
    @equip_hashes = {}
    equips.each do |eq|
      next unless eq
      eq.composite_hash.each do |key, array|
        next if Composites.files[array[0]][male? ? 0 : 1].nil?
        arr = array.dup # need to dup to prevent bugs
        if hue = @editor_hues[key]
          arr[1] = hue
        end
        @equip_hashes[key] = arr
      end
    end
  end

 

Haven't really tried it, but it should have the editor hues override the equip hues. Just make it's own script after the composite script I guess. It overwrites rather then aliases, but that should be fine.

 

Edited by Kayzee

Share this post


Link to post
Share on other sites

(redacting)

 

Here's the issue.

I have the equipment in place, so there's no need to change the equipment graphic in order to recolor it. However, it seems the script wants me to do just that, and if that is going to be the case, that is going to bring development entirely to a halt because I am not going forward with it otherwise.

Yeah, call me whatever ya want. Don't care; I am not okay with this being overlooked. I'd go and bug the original script writer, but oh, they're over on RMW, and I'm not bothering with the likes of them. Meh.

I figured, I could just use layers in a creation array, but no, I get two middle fingers pointed at me instead, and a 'NO TEXT' single list item. Seriously...

 

Spoiler

GUI_LISTS ={
  :under      => [:socks, :legs, :bra, :top],
  :cloth      => [:cape, :footwear, :hips, :top1, :top2, :armor],
  :acc        => [:acc, :acc1, :acc2, :glasses, :acc3, :acc4, :acc5],
  :helm       => [:helm, :helm1, :helm2],

 

There's no reason that this should not work. None. No excuses.

Edited by PhoenixSoul
Redaction and Elaboration

Share this post


Link to post
Share on other sites

Huh, it works for me... as long as the graphic is actually set to something already anyway. Maybe that was a change I made and forgot about, but for me the current graphic is always part of the list. The no text menu thing does indeed happen for me if it's a layer that is completely blank though, but there is nothing to really recolor there in any case and the option really shouldn't show up at all.

 

A quick and dirty solution for you might be to add a "None" option to all those layer's GUI_LISTS. Like:

GUI_LISTS ={
...
  :socks => ["None"], 
  :legs => ["None"],
  :bra => ["None"], 
  :top] => ["None"],
  :cape => ["None"],
...
}

 

Not sure how well that will work, but give it a try!

 

 

Share this post


Link to post
Share on other sites
On 8/26/2019 at 8:59 PM, PhoenixSoul said:

I've always wondered the following:

How does one check the eight tiles surrounding the player for region and terrain IDs, without a lot of complicated eventing? I'm sure there's a way, just not sure how to check this.
 

 This remains unanswered. ☹️

Also, how does one check to see if both weapon slots (YES DUAL WIELD) contain the exact same weapon?

Share this post


Link to post
Share on other sites
10 hours ago, PhoenixSoul said:

 This remains unanswered. ☹️

I thought I answered something like it at some point... Anyway instead of complicated eventing you can use still fairly complicated scripting! Heres how I do it.


 

Spoiler

 

What I do to check the surrounding tiles works like this:

 

I made a little utility method that returns all the surrounding tile locations like this:


class Game_Map
  
  def neighboring_xy_8dir(x, y)
    [[x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1],
     [x + 1, y + 1], [x - 1, y - 1], [x + 1, y - 1], [x - 1, y + 1]]
  end
  
  def neighboring_xy_4dir(x, y)
    [[x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]]
  end
  
end

Note: I included both an 8 directional version and a 4 directional version here. I am going to assume you mostly want to use the 4 directional version for most things. I personally using 8 directional movement, so I check diagonals for everything too.

 

Okay now we have a list of locations to check as an array of arrays. Now we can write methods to check things!


class Game_Map
  
  def neighboring_xy_8dir(x, y)
    [[x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1],
     [x + 1, y + 1], [x - 1, y - 1], [x + 1, y - 1], [x - 1, y + 1]]
  end
  
  def neighboring_xy_4dir(x, y)
    [[x + 1, y], [x - 1, y], [x, y + 1], [x, y - 1]]
  end
  
  def check_neighboring_region(x, y, id)
    (neighboring_xy_4dir(x, y)).any? do |xy|
      region_id(xy[0], xy[1]) == id
    end
  end
  
  def check_neighboring_terrain_tag(x, y, tag)
    (neighboring_xy_4dir(x, y)).any? do |xy|
      terrain_tag(xy[0], xy[1]) == tag
    end
  end
  
end

 

So in this example you can call $game_map.check_neighboring_region(x, y, id) to check if any of the nearby tiles or $game_map.check_neighboring_terrain_tag(x, y, tag) to check if any nearby tiles have the given tag. This may not be exactly what you want, but I hope it shows a good example of how I might do something that checks a lot of tiles at once.

 

Edited by Kayzee

Share this post


Link to post
Share on other sites

I didn't actually think any further code was needed; I had figured it could be done with what's already present, and yeah, it should return the values of the neighboring tiles' region IDs or terrain tags. Ah, well...
Hmmm...but it leaves (once again) one query unanswered...

Share this post


Link to post
Share on other sites

Well the methods are quite short so it could probobly all be rewritten to be pasted in an event script command, but using methods like that is handy.

 

I might have over complicated things a bit really. If you wanted to do it in the simplest way possible all you would need to do is this to get the four nearby region_ids in an array is:

x = $game_player.x
y = $game_player.y
[region_id(x + 1, y), region_id(x - 1, y), region_id(x, y + 1), region_id(x, y - 1)]

Or you could put them all in different variables or something. It's just adding and subtracting 1 form the x and y really.

 

Anyway, as for your other question:

 

Assuming 'actor' is the actor you want to check, you can use this in an if statement or a conditional branch script call I think:

actor.weapons[1] && (actor.weapons[0] == actor.weapons[1])

Not sure what actor you intend on checking or where you want to use this so I can't exactly give you anything more exact.

Edited by Kayzee

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×