Jump to content
kal

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

Recommended Posts

(I'm more likely to get any coding queries answered here than in the Discord-go figure)

Script call for RGSS3:
Change Equip By ID:
$game_actors[1].change_equip_by_id(1, 1) if $game_actors[1]
Can I use _weapon_ in place of _equip_ ? Because as of now, even with the Dual Wield flag set, it will equip the first weapon slot with the weapon, but not the second weapon slot. It'll unequip it. Also, forcing it via the event command leads to the same, and yes, I have more than one of the weapon added to the inventory beforehand.

@Rikifive, @Kayzee, anyone?

Edited by PhoenixSoul
Likely to be buried

Share this post


Link to post
Share on other sites
7 hours ago, Kayzee said:

I hope it works out the way you expect! :3

Working fine, but it seems like maybe it's working the old way for enemies? Is there somewhere else I might have to change that code that I changed? Just seems like enemies with an ATK buff are hitting for insane damage, but it could just be me.

Edited by WCouillard

Share this post


Link to post
Share on other sites

Got another quick (I think) problem to fix:

The player in my game can ride vehicles and the vehicle graphic is larger than 32x32 pixels (no wider than 60 pixels though). When the vehicle is next to an event, the part that pokes into another tile (since again it is longer than 32 px) ends up displaying over the event graphic beside it.

So, I think if I could make it so that by default the player z value is below "Same as Character" events, the edge of the vehicle (which is actually just the character sprite changed into my character riding the vehicle) won't go over the event graphic but instead under it, which would look far better.

Is there a way to change the z value of Same as Character events?

Share this post


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

(I'm more likely to get any coding queries answered here than in the Discord-go figure)

Script call for RGSS3:
Change Equip By ID:
$game_actors[1].change_equip_by_id(1, 1) if $game_actors[1]
Can I use _weapon_ in place of _equip_ ? Because as of now, even with the Dual Wield flag set, it will equip the first weapon slot with the weapon, but not the second weapon slot. It'll unequip it. Also, forcing it via the event command leads to the same, and yes, I have more than one of the weapon added to the inventory beforehand.

@Rikifive, @Kayzee, anyone?

 

Either I didn't understand the problem or... it works for me..

1XfTotC.gif

Share this post


Link to post
Share on other sites

OK, so I have another issue. This is just a QoL thing to alleviate what I believe to be the cause of some lag.

 

Actors state icons being drawn in battle still draw an icon when that state's icon ID is 0 (a blank icon). I am trying to only show the icons of states that actually have one. Characters in my game can have many, many states applied at once, passively and I believe it's causing a bit of slowdown in fights.

 

def draw_actor_battle_icons(actor, x, y, width = 144)
    icons = (actor.state_icons + actor.buff_icons)[0, width / 24]
    icons.each_with_index {|n, i| draw_icon(n, x + 24 * i, y) }
end

So I cloned the method that does just that, but I am looking for a way to eliminate any state icons that return 0 from this. I expect that "n" is what refers to the icon ID?

Edited by WCouillard

Share this post


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

I think n is what refers to the icon ID. I'd look into adding in an "unless n == 0" operator.

 

Any idea where I'd put that? I have tried a few things and keep getting crashes. Clearly, I'm getting the syntax wrong.

 

This is the one way I have it written where it doesn't crash, but I'd need to test more to make sure it's working.

 

  def draw_actor_battle_icons(actor, x, y, width = 144)
    icons = (actor.state_icons + actor.buff_icons)[0, width / 24]
    icons.each_with_index {|n, i|
    unless n == 0
      draw_icon(n, x + 24 * i, y) 
    end
    }
  end

EDIT: OK, that seems to be helping with the lag a little bit. Now, is there something I can add that tells this method to only draw up to let's say, four or five icons at any time for an actor?

Edited by WCouillard

Share this post


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


@Rikifive Hmmm... I do have a lot of scripts in place but I can't imagine any of them interfering like that...

A script that allows customizing equip slots (adding more and such) is quite often used (I even used one back then) and it might alter how these are stored or something. Are you using anything, that enhances the equipment system?

Of course it's just a wild guess, haven't delved into code in these scripts and it was ages ago anyway.

 

11 hours ago, WCouillard said:

 

Any idea where I'd put that? I have tried a few things and keep getting crashes. Clearly, I'm getting the syntax wrong.

 

This is the one way I have it written where it doesn't crash, but I'd need to test more to make sure it's working.

 


  def draw_actor_battle_icons(actor, x, y, width = 144)
    icons = (actor.state_icons + actor.buff_icons)[0, width / 24]
    icons.each_with_index {|n, i|
    unless n == 0
      draw_icon(n, x + 24 * i, y) 
    end
    }
  end

EDIT: OK, that seems to be helping with the lag a little bit. Now, is there something I can add that tells this method to only draw up to let's say, four or five icons at any time for an actor?

yes, use break to break out from the loop.

  def draw_actor_battle_icons(actor, x, y, width = 144)
    icons = (actor.state_icons + actor.buff_icons)[0, width / 24]
    icons.each_with_index {|n, i|
      break if i == 5 # skip and break at 6th icon (0,1,2,3,4 will be drawn; 5 and next won't)
      draw_icon(n, x + 24 * i, y) unless n == 0
    }
  end

haven't toyed with defaults much, but if you're mentioning a blank icon, then be aware, that it will still reserve space for it, even if drawing will be skipped. With that 'unless' operator you're skipping drawing the blank icon, but it still exists and has an index, so if the first state has that blank icon, the next one will be drawn in the second run, with i set to 1, where it is used in x coordinate (x + 24 * i)

With that being said, you might need some more adjustments if you'll notice a horizontal offset (by 24 pixels to the right).

 

Also, if that blank state will be in one of the first 5 slots, the loop will break after drawing 4, as that blank state will be the fifth one.

 

If every single actor would always have that blank state in the first spot, you could easily alter the code to account that fact. Like, add extra index (i == 6 would run through the loop 6 times, where that one time with blank would be skipped) and adjust the x coordinate to x + 24 * (i-1) to start with the first slot when drawing the second icon.

Share this post


Link to post
Share on other sites

Aren't icons text objects anyway, @Kayzee, mi amour? I thought that this was so.
@Rikifive Yes; I'm using Yanfly's Equip Engine and Hime's Equip scripts (some functionalities needed are provided by Hime but not Yanfly and vice-versa).
I also do have the weapon slots as universal equip slots 1 and 2 with 0 being a Skill Card which is its' own equip slot type, hence why I asked if I should use change_weapon instead of change_equip, and if that would be okay with Ruby...lolz

Share this post


Link to post
Share on other sites

@PhoenixSoul If you'll hit CTRL+SHIFT+F in the script editor and search for "change_equip" you'll get results, including the method you're using "change_equip_by_id". If you'll type "change_weapon", you won't get anything, so that means you cannot use that, as that method doesn't even exist. That's at least, how it is by default, because I don't know if these scripts may be adding that one.

 

By default, you have these slots:

sUgOIF8.png

(and I'm pretty sure this is totally overwritten by these equip engines in order to actually be able to allow you customize slots)

 

Now this is the method you're using:

UBRbSp3.png

 

As you can see, the method checks what type of slot it is and if it is 0 (both weapon slots are 0), it selects the item from weapon category, otherwise from armors. So no need for "change_weapon", as "change_equip" is universal.

 

So I suppose some science has to be happening in these 3rd party scripts, making "change_equip" fail to determine the actual weapon slots. You mentioned first slot working fine, while the second one not, so my guess is that these equip engines may possibly have changed the second weapon slot (dual wield) to something else than 0 and the method you're using tries to equip an armor (that doesn't exist in that index, because if it was, nothing would happen, it would leave whatever it had equipped) as that second weapon, resulting in leaving nothing equipped.

7mWzKb1.png

 

So if you have 10 weapons and 5 armors in the database and try to equip a weapon with ID 7, it will unequip whatever it has if it tries to equip an armor (instead of weapon) with that ID, that doesn't exist (nil).

 

You may want to check these two methods and see if these are compatible. Perhaps a little bit of adjusting should be enough, assuming these equip engines don't bring big guns into how equip system works.

 

 


Some sentences don't make sense? Typos? Sorry about that, but it's past 6AM and I haven't slept yet. I'm tired.

 

Share this post


Link to post
Share on other sites

@Rikifive I'm also using Fomar's Dual Wield -> Free Hands script. Essentially, it allows one with the Dual Wield flag to equip a shield type item (a massive oversight since that should be a built-in feature), and I think that's the issue since...

 

Spoiler

class Game_Actor
  
  def equip_slots
    return [8,0,1,7,7,7,7,7,7,7,6,6,6,4,4,4,4,5,5,5]
  end

 

Pretty sure that slot_id counts this as an array beginning at zero, and ending at the last number in the array, which makes the weapon slots slot_id 1 and 2 respectively, which as far as I can tell, the script isn't coded to handle for some parts (I can use shields just fine with this array). However, my level of Ruby/RGSS expertise is still quite lacking, so I'll just post the script here and then... 🤷‍♀️
 

Spoiler

=begin
Dual Wield -> Free Hands
by Fomar0153
Version 1.1
----------------------
Notes
----------------------
No requirements
Changes dual wielding to allow characters to equip shield or one handed
weapons in the shield slot. Also allows for two handed weapons.
----------------------
Instructions
----------------------
Notetag two handed weapon with <two-handed> and have them
disable the shield slot.
I would reccomend changing the slot name to Main Hand and Off Hand
or something similiar
----------------------
Change Log
----------------------
1.0 -> 1.1 Fixed a bug where the equip item in the second hand could
           overwrite the main hand's equip item.
----------------------
Known bugs
----------------------
None
=end
class Game_Actor
  
  def equip_slots
    return [8,0,1,7,7,7,7,7,7,7,6,6,6,4,4,4,4,5,5,5]
  end
  
  def change_equip(slot_id, item)
    return unless trade_item_with_party(item, equips[slot_id])
    return if (item && equip_slots[slot_id] != item.etype_id) and
      not (dual_wield? and (equip_slots[slot_id] == 1 and item.etype_id == 0))
    @equips[slot_id].object = item
    refresh
  end
  
  def release_unequippable_items(item_gain = true)
    @equips.each_with_index do |item, i|
      if !equippable?(item.object,equip_slots[i]) || (item.object.etype_id != equip_slots[i] and
          not (dual_wield? and (equip_slots[i] == 1 and item.object.etype_id == 0)))
        trade_item_with_party(nil, item.object) if item_gain
        item.object = nil
      end
    end
  end
  
  def equippable?(item, slot = nil)
    unless slot.nil?
      if slot == 1 and dual_wield?
        return (super(item) and not equip_type_sealed?(1)) if item.is_a?(RPG::Weapon)
      end
    end
    return super(item)
  end
  
  def slot_list(etype_id)
    result = []
    equip_slots.each_with_index {|e, i| result.push(i) if e == etype_id or ((e == 1 and etype_id == 0) and dual_wield?) }
    result
  end
end

class RPG::Weapon
  
  def two_handed?
    return self.note.include?("<two-handed>")
  end
  
end

class Window_EquipItem < Window_ItemList
  
  def include?(item)
    return true if item == nil
    return false unless item.is_a?(RPG::EquipItem)
    return false if @slot_id < 0
    return false if @actor.equip_slots[@slot_id] == 1 and 
      (item.is_a?(RPG::Weapon) and item.two_handed?)
    return false if (item.etype_id != @actor.equip_slots[@slot_id]) and 
      not (@actor.dual_wield? and (@actor.equip_slots[@slot_id] == 1 and item.etype_id == 0))
    return @actor.equippable?(item,@actor.equip_slots[@slot_id])
  end
  
end

 

If you've got any further insight, feel free to let me know, and merci beaucoup.

Share this post


Link to post
Share on other sites

UUuuuuuugghhhhh... PS, I wuv you, but by Eris' non-existent hot dog bun, whenever do you do anything with dual wield or even sometimes just equipment in general I just want to quietly sneak off and hide in a dark corner and hope you don't notice me. >_<

 

Also: No, icons are not text, they are normal bitmaps. Though there really is no such thing as a 'text object' in this context anyway really, unless you mean a Font object. All the text and icons are both drawn onto bitmaps, usually window contents bitmaps. The only real difference is, icons are bitmaps loaded from an image and bitmaps can just be copied from one bitmap to another really quickly. Text actually has to be drawn on to stuff, so it's much slower. There are some scripts that 'cache' fonts as a series of bitmaps for each letter which is actually much much faster (still can cause a lag spike when drawing lotsa text in an uncached font, but is still much much faster).

 

Fun fact: By font, I actually mean font not just typeface. Technically the word 'font' actually is supposed to include size and style.

Edited by Kayzee

Share this post


Link to post
Share on other sites
19 hours ago, Rikifive said:

A script that allows customizing equip slots (adding more and such) is quite often used (I even used one back then) and it might alter how these are stored or something. Are you using anything, that enhances the equipment system?

Of course it's just a wild guess, haven't delved into code in these scripts and it was ages ago anyway.

 

yes, use break to break out from the loop.


  def draw_actor_battle_icons(actor, x, y, width = 144)
    icons = (actor.state_icons + actor.buff_icons)[0, width / 24]
    icons.each_with_index {|n, i|
      break if i == 5 # skip and break at 6th icon (0,1,2,3,4 will be drawn; 5 and next won't)
      draw_icon(n, x + 24 * i, y) unless n == 0
    }
  end

haven't toyed with defaults much, but if you're mentioning a blank icon, then be aware, that it will still reserve space for it, even if drawing will be skipped. With that 'unless' operator you're skipping drawing the blank icon, but it still exists and has an index, so if the first state has that blank icon, the next one will be drawn in the second run, with i set to 1, where it is used in x coordinate (x + 24 * i)

With that being said, you might need some more adjustments if you'll notice a horizontal offset (by 24 pixels to the right).

 

Also, if that blank state will be in one of the first 5 slots, the loop will break after drawing 4, as that blank state will be the fifth one.

 

If every single actor would always have that blank state in the first spot, you could easily alter the code to account that fact. Like, add extra index (i == 6 would run through the loop 6 times, where that one time with blank would be skipped) and adjust the x coordinate to x + 24 * (i-1) to start with the first slot when drawing the second icon.

All of the states I want to hide have 0 priority set and a blank icon, so this should work fine, right?

Share this post


Link to post
Share on other sites

@PhoenixSoul Looks like the script doesn't modify the method you're using.

Look at the array you have:

[8,0,1,7,7,7,7,7,7,7,6,6,6,4,4,4,4,5,5,5]

the second and third ones are the weapon slots, right? but these no longer are 0 (weapon) and 0 (weapon). 1 by default is shield, so these slots are for weapon and shield. The script modifies the shield slot, so that when an actor has dual wield, it is possible to equip a weapon in the shield slot, which makes sense. However, the method you're using still sees only type 0 as the weapon, so that particular method thinks, that the second weapon (third entry in the array => 1) is a shield, so it tries to equip an item from armor category.

 

Since you were asking for something like change_weapon, so how about a new method, where you can manually specify item category?

class Game_Actor < Game_Battler
  #--------------------------------------------------------------------------
  # * Change Equipment (Specify with ID and TYPE)
  #     slot_id:  Equipment slot ID
  #     item_type: 0 for Weapons, 1 (or whatever) for Armors
  #     item_id:  Weapons/armor ID
  #--------------------------------------------------------------------------
  def change_equip_by_id_and_type(slot_id, item_type, item_id)
    if item_type == 0
      change_equip(slot_id, $data_weapons[item_id])
    else
      change_equip(slot_id, $data_armors[item_id])
    end
  end

end

paste this in materials and give it a try.

 

for example:

$game_actors[1].change_equip_by_id_and_type(2, 0, 1)

 

would equip a WEAPON with ID 1 on the third slot [ 8 , 0 , , 7 , 7 , ... ], where your second weapon/shield slot is.

 

$game_actors[1].change_equip_by_id_and_type(2, 1, 1)

would equip an armor with id 1 in that slot (shield)

 

4 hours ago, WCouillard said:

All of the states I want to hide have 0 priority set and a blank icon, so this should work fine, right?

IIRC, that should make them appear at the end of the arrays, so yeah, that should get these out of the way.

Share this post


Link to post
Share on other sites

Well, hot damn, @Rikifive, it works. Works without a fuss. The Polish Pixie Pony saves the day once again! lolz

@Kayzee, ah yes, the good old bitmap fonts that a lot of older games utilize. Even newer games do as well, though one game in particular uses a bunch of them since they reference a single character per file. Yes, I speak of Phase Shift. (hugs)


Well, now that this is working, there's one issue; I have a skill replacement system in place that changes the attack skill based on what the character has equipped. Thing is, the way it works, it checks to see if a weapon is equipped in either weapon slot, but with the aforementioned script, if a shield is in the secondary weapon slot, it'll throw an error (NoMethodError wtype_id for RPG::Armor) or if I put in a check to see if the slot has a shield in it, it throws the NoMethodError (atype_id for RPG::Weapon).

So, how can I make it check for this without the error? I could do it by using a lot of if member is in party and has each potential shield item equipped, but that would be a clusterf*ck of clutter! I need this to run in the script portion of Conditional Branch.

 

Spoiler

$game_party.leader.equips[2] && $game_party.leader.equips is an? RPG::Armor

My best guess.

Edited by PhoenixSoul
trying to figure out a new arising issue

Share this post


Link to post
Share on other sites
31 minutes ago, PhoenixSoul said:

Well, hot damn, @Rikifive, it works. Works without a fuss. The Polish Pixie Pony saves the day once again! lolz

@Kayzee, ah yes, the good old bitmap fonts that a lot of older games utilize. Even newer games do as well, though one game in particular uses a bunch of them since they reference a single character per file. Yes, I speak of Phase Shift. (hugs)

 

Phew, I am glad someone was able to help you at least!

 

Also: Though I am not sure if the phrase 'bitmap font' usually refers to any set of bitmaps used as a font, or if it usually refers to a particular file format. Plus there are apparently SDF Fonts which apparently are technically a type of bitmap font that are scalable like vector fonts.

Share this post


Link to post
Share on other sites

@Rikifive Yep, I wasn't too far off. Of course, I goofed with the second .equips by leaving out [2]...lolz
This is the conditional branch script call I cobbled, and yup, it seems to work.
 

$game_party.members[0].equips[2] && $game_party.members[0].equips[2].is_a?(RPG::Armor)

Making progress feels so good, and merci beaucoup once again.
@Kayzee I definitely wanna play Daggerfall Unity at some point, but eh...not on this crap-tastic hardware setup...

Edited by PhoenixSoul

Share this post


Link to post
Share on other sites

I am trying to create a quick script to display the turn count in battle, and have it update when a turn ends. However, I can't seem to find any actual turn count stored in the default scripts anywhere, other than increasing turn counts for States only. Enemy battle AI can be dependent on turn count, so it must be stored somewhere. Can someone point me in the right direction?

Share this post


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

I am trying to create a quick script to display the turn count in battle, and have it update when a turn ends. However, I can't seem to find any actual turn count stored in the default scripts anywhere, other than increasing turn counts for States only. Enemy battle AI can be dependent on turn count, so it must be stored somewhere. Can someone point me in the right direction?

$game_troop.turn_count

- will return the turn count of the current battle.

Share this post


Link to post
Share on other sites

how, if at all, can i add custom methods to a troop script?

 

i'm trying to make pseudoskills (fake actions made entirely out of custom methods, e.g. stun(attacker.id,turns_length,targets)), so that i can have a wide variety of similar 'moves' among my enemies without relying on an excess of skill slots, and to have, ideally, one-line setup skills during troop creation.

 

trying to use scripts in battle asks for Game_Interpreter:Class (which i assumed was the Game Interpreter), but it seems like methods from Game_Interpreter just don't carry over.

Metaclass methods like Game.Interpreter.print_hello also fizzle as undefined for Game_Interpreter:Class, and calling a class asks for Game_Interpreter::[CALLED CLASS]:Class?

 

was i a naive and ideal fool for thinking that i wouldn't have to clutter up my skills with various degrees of bonking and whapping? Is there a better way to change lots of attributes or methods for a single enemy's attack you're probably only going to use once?

 

script included in case specifics are needed, or in case some poor soul actually decides to wade through my beginner-level trash to see if this kind of thing can even be done.

pseudoskill example.txt

Share this post


Link to post
Share on other sites
2 hours ago, rapid_Movement said:

how, if at all, can i add custom methods to a troop script?

 

i'm trying to make pseudoskills (fake actions made entirely out of custom methods, e.g. stun(attacker.id,turns_length,targets)), so that i can have a wide variety of similar 'moves' among my enemies without relying on an excess of skill slots, and to have, ideally, one-line setup skills during troop creation.

 

trying to use scripts in battle asks for Game_Interpreter:Class (which i assumed was the Game Interpreter), but it seems like methods from Game_Interpreter just don't carry over.

Metaclass methods like Game.Interpreter.print_hello also fizzle as undefined for Game_Interpreter:Class, and calling a class asks for Game_Interpreter::[CALLED CLASS]:Class?

 

was i a naive and ideal fool for thinking that i wouldn't have to clutter up my skills with various degrees of bonking and whapping? Is there a better way to change lots of attributes or methods for a single enemy's attack you're probably only going to use once?

 

script included in case specifics are needed, or in case some poor soul actually decides to wade through my beginner-level trash to see if this kind of thing can even be done.

pseudoskill example.txt

 

Uh... Looks like you forgot an 'end' down at the bottom?

 

Also what do mean it 'asks for' 'Game_Interpreter:Class'? Do you mean you get an error like "undefined local variable or method 'blah' for Game_Interpreter:Class"? Because if you are calling a method from an event the error should be more like "undefined local variable or method `blah' for #<Game_Interpreter:0x[some hex number]>".  I assume by 'metaclass methods' you mean methods attached to the class object it's self. Not sure if it's the right term in ruby, I just call them 'class methods'. Usually I see eigenclass rather then metaclass for ruby too. But whatever. If it's complaining about 'Game_Interpreter:Class' that way it means it's looking for a (meta)class method. In that case 'Game.Interpreter.print_hello' should be 'Game_Interpreter.print_hello'. Not sure why it would look for one though.

 

Anyway, (meta)class methods are usually defined like:

 

class Game_Interpreter
  
  def self.blah()
    puts "blah"
  end
  
end

with a 'self.' in front of the method name or like:

class Game_Interpreter
  
  class << self # the class's eigenclass/metaclass
    
    def blah()
      puts "blah"
    end
    
  end

end

Again though, I don't know why it would look for a method like that unless you are actually calling the methods using 'Game_Interpreter.blah()' in the events. If you are... well a Game_Interpreter instance is running the event. Just use 'blah()'.

Edited by Kayzee

Share this post


Link to post
Share on other sites

I was getting the undefined variable for #<Game_Interpreter:0x(numbers)> errors, and im not entirely sure why, but i think i literally just pranked myself by forgetting that starting a battle test doesn't save your changes or something equally embarrassing, because it works fine now.

w e l p

thanks for the help - i've been having trouble sorting out metaclass / class / who knows what else methods anyway, so your explanation cleared up a lot.

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.

×