Jump to content
kal

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

Recommended Posts

Haven't posted in a while, but I have a seemingly easy thing to code that is giving me a small migraine.

 

I've got an image showing during battle, that rest behind each character's information in Window_BattleStatus. However, I'd like it to actually show over that information. Trying to change to Z value of the image being shown is returning errors or simply not working, so I'm sure it's just a matter of me putting it in the wrong place. Been a few months since I've coded anything, so I'm a little rusty, but here's the method which creates the image in battle.

  def draw_actor_hud(x, y, enabled = true)
    bitmap = Cache.system("Actor_Battle_HUD")
    rect = Rect.new(0, 0, bitmap.width, bitmap.height)
    contents.blt(x, y, bitmap, rect, enabled ? 255 : translucent_alpha)
    bitmap.dispose
  end

This is within Window_BattleStatus. This method is then called here.

  #--------------------------------------------------------------------------
  # * Overwrite method: draw_basic_area
  #--------------------------------------------------------------------------
  def draw_basic_area(rect, actor)
    width = $data_system.opt_display_tp ? 640 : 640
    draw_actor_name(actor, rect.x, rect.y - 5, 100)
    draw_actor_battle_icons(actor, rect.x + 328 , rect.y, 168)
    draw_actor_hud(rect.x, rect.y)
  end

Also in Window_BattleStatus.

 

Can anyone tell me the proper way to alter the Z value to make the image I'm calling show over the character's battle status information?

Share this post


Link to post
Share on other sites

You are copying the content of a bitmap inside the bitmap of the window so you can't change the z value ,for that you would need to create a new sprite

def draw_actor_hud(x, y, enabled = true)
    bitmap = Cache.system("Actor_Battle_HUD")
    rect = Rect.new(0, 0, bitmap.width, bitmap.height)
    sprite = Sprite.new
    sprite.bitmap = bitmap
    sprite.x = @x 
    sprite.y = @y 
    sprite.z = @z + 1
  end

So something like this should do it , (It probably need some adjustments tho like adding padding values to your sprite coordinates) don't forget to alias the dispose method from your window to make it also dispose the sprite

Share this post


Link to post
Share on other sites

Returning an error of "No implicit conversion from nil to integer," on the sprite.x line of that code.

 

I feel like I should also note that the reason I coded it the way I did, rather than just use a sprite.new, is because it has to load this image once for each party member, not just one image.

Edited by WCouillard

Share this post


Link to post
Share on other sites

Yeah it should be 
this.x/y/z instead of @x/@y/@z
wiat I think it should appear above anyway because you are drawing on the bitmap after so I don't know sorry

Share this post


Link to post
Share on other sites

Silly question:

Can I clear a part of bitmap?

 

I've made sprites, where I'm drawing text and such on their bitmaps (not using window classes at all) - now because one sprite holds multiple draw_text methods (to change color and/or set the accurate position of various parts of text and such) it makes it harder to change something in the text, because I need to redraw the entire bitmap, which is kinda inconvenient and just unnecessary.

 

So, .clear method clears the entire bitmap ~ is there a way to clear just a part of it ~ something like .clear(100, 0, 50, 20)

Or... should/can I set rect's?

 

This will work as an example:

Let's say I have a setting like this:

 

-->   VOLUME:         < 100% >

 

Now, I'd like to redraw the right part, while not having to redraw the 'VOLUME'.

 

Thanks ~

Share this post


Link to post
Share on other sites

From the VX ace help page about bitmap

clear_rect(x, y, width, height)
clear_rect(rect)
Clears this bitmap box (x, y, width, height) or rect (Rect).
Edited by Shiggy
  • Like 1

Share this post


Link to post
Share on other sites

*facepalm that big, that it takes so much space*

 

 

third_party.jpg

 

 

I was searching through the libraries on the web, but there was so much stuff except these methods, so that's why the question appeared - I totally forgot about the HELP file in the Editor...

Yes it does exactly what I wanted, thanks for pointing that out.

That's good I've put the 'silliness' warning at the beginning.

Now excuse me, I'm going to the shame corner for some time.

Share this post


Link to post
Share on other sites

This has probably been covered here before, but what would be the easiest way, using a script call, to grab a random value from an array and store it in a variable? For example, we have an array of integers, let's say something like..

random_id = [1, 2..22, 24..100]

Whenever I try to use different ways to pull one of the integers in the range above, it returns an error citing "cannot convert Array into Integer," which is understandable. What I want to know is, how do we take ONE integer from the range above at random, and then store it in the variable to be used further down in the script call?

Share this post


Link to post
Share on other sites

Are you strictly asking to chose either 1 or a number between 2 and 22 or a number between 24 and 100, or do you want to pick a number from a array that contains 1, all numbers from 2 to 22, and all numbers from 24 to 100? Because those are two different things. The first you will get 1 one third of the of the time, and the other you will only get 1 one ninetyninth of the time.

 

Long story short, first would be like this:

ids = [1, 2..22, 24..100]
step_one = ids.sample
step_two = step_one.is_a?(Enumerable) ? step_one.to_a.sample : step_one

And the second would be like this:

ids = [1, 2..22, 24..100]
step_one = ids.collect_concat {|n| n.is_a?(Enumerable) ? n.to_a : [n]}
step_two = step_one.sample

Both are probably not the best way to do it.

Edited by KilloZapit

Share this post


Link to post
Share on other sites

Are you strictly asking to chose either 1 or a number between 2 and 22 or a number between 24 and 100, or do you want to pick a number from a array that contains 1, all numbers from 2 to 22, and all numbers from 24 to 100? Because those are two different things. The first you will get 1 one third of the of the time, and the other you will only get 1 one ninetyninth of the time.

 

Long story short, first would be like this:

ids = [1, 2..22, 24..100]
step_one = ids.sample
step_two = step_one.is_a?(Enumerable) ? step_one.to_a.sample : step_one

And the second would be like this:

ids = [1, 2..22, 24..100]
step_one = ids.collect_concat {|n| n.is_a?(Enumerable) ? n.to_a : [n]}
step_two = step_one.sample

Both are probably not the best way to do it.

Second option, to choose one integer out of every number included in all the ranges in the array. I'll give it a test!

 

EDIT: Works beautifully. Thank you.

Edited by WCouillard

Share this post


Link to post
Share on other sites

Hello,

 

I have a party of 15+ members, and one of them is wearing a specific weapon, how would I go about finding that actor's ID and position in the party? I need to get both because it will determine their move route and positioning in the map.

 

EDIT:

I finally got it to work with Tsukihime's Equip Check :D

Edited by Kaneshon

Share this post


Link to post
Share on other sites

I'm trying to figure out how to properly check if the player is trying to choose himself as the subject of a skill.

I've made a new targeting scope inside Yanfly Target Manager called "not_for_user?" which requires you to choose an ally for the skill, but can't choose yourself.

    elsif item.not_for_user?
      array |= [friends_unit.smooth_target(@target_index)]
      array -= [subject] 

So far it does what I want it to except, if you purposely choose yourself the skill does nothing, you waste a turn, (at least you don't expend the cost of the skill though...).

 

I think I have to add code to item_test, something like

  return false if item.not_for_user? && item.target == user?

but it still allows me to select the user. I've tried a whole bunch of different things here that either crash or do nothing.

Share this post


Link to post
Share on other sites

How do I add a switch function to an existing script so it would only work when it is on? I looked at other scripts for reference but I can't get it to work.

Share this post


Link to post
Share on other sites

You can't just magically turn a script on and off with a switch. You will need to reprogram it to do or not do what you want depending on the switch. You can wrap chunks of code in a big if statement, but that only works for when the script is loading. Good for configuration options or testing but not much else.

 

Sidenote: Come to think of it, it's probably possible to fiddle with metaprograming trickery to make it easier to do stuff like this. But that might make things even more complected.

Edited by KilloZapit

Share this post


Link to post
Share on other sites

Looking for all the places I would have to change the base VX Ace codes for Parameters to make them ADDITIVE and not MULTIPLICATIVE.

 

What I mean is, let's say we have an accessory that increases HP by 100%, worn on an actor with 500 Max HP. His Max HP would now be 1,000. Now let's equip another. His Max HP is now 2,000, instead of 1,500, which is the way I'd like it to be.

 

It should only increase the BASE value.

Share this post


Link to post
Share on other sites

Looking for all the places I would have to change the base VX Ace codes for Parameters to make them ADDITIVE and not MULTIPLICATIVE.

 

Parameters do add. I'm sure you've already taken a look at the param_plus method in Game_Actor. And if you've checked the actual parameters array of the items, you'll see they comprise only the flat stat values for the eight stats you see in the databse.

 

What you're thinking of are Features. Whether those values stack multiplicatively or additively depend on the actual feature itself. In the case of parameter change features, they're positive percentages, so of course they multiply. Otherwise when wearing something that doubles the stat (200%) and something that halves it (50%) you'd get 250% stat instead of 100%.

 

What you REALLY want is not just to make them stack additively, but change how those percentage numbers are seen by the engine. I suggest you take a look at the features_ methods in Game_BattlerBase, particularly features_pi and param_rate. Good luck.

Edited by Traverse

Share this post


Link to post
Share on other sites

How do change the font size of the number value of items? I changed the default font size, but for some reason it doesn't affect the the number value.

Edited by TheYungVxAce

Share this post


Link to post
Share on other sites

Hey there guys! Just a quickie-

 

I want to use a conditional branch to check and see if an event (not the one running) has a certain self switch on. I set the conditional branch to this script: 

$game_self_switches[[24,16,A]] == false

With the 'else' being what would happen if the identified self switch was ON.

 

However, the script can't ever detect when the self switch is on, even when I know it's on.

 

Does anyone know what I'm doing wrong, or have a better way to do this? Thank you!

Share this post


Link to post
Share on other sites

I am pretty sure you can't reference a self switch by letter. I am actually surprised that didn't crash with some kind of 'constant not defined' error actually. You should probobly use '1' (or maybe '0' depending on how it is counted) instead of 'A'. At best it might be ':A' but I doubt it.

Share this post


Link to post
Share on other sites

Honestly, I'm surprised it didn't crash too. It certainly did when I tested it.

 

In any case the usual way you'd reference a self-switch is, in fact, by a letter. That is, a String letter - by which I mean you want [24, 16, "A"] and not [24, 16, A], since that refers to a variable which should by rights be non-existent... except for some reason you seem to have one that exists by that name. Either that or you have some script modifying how self-switches work or that prevents the default error handling.

 

You know if you're not sure how the system is reading a piece of data, you can just print it to the console to see what it looks like.

Share this post


Link to post
Share on other sites

Ah, that is another possibility I didn't really think was too likely for some reason. Also, you can't really easily print the list of self switches so I wasn't too sure how to check the format. I guess I could have added a print to an interpreter command that uses them though.

Share this post


Link to post
Share on other sites
p $game_self_switches

That prints the list of self-switches. Every self-switch, for every event on every map (that uses them, and that at some point has set them to true/false).

Share this post


Link to post
Share on other sites

Does it? Wouldn't it just print <Game_Self_Switches:0x79794fef> or something?

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.

×
Top ArrowTop Arrow Highlighted