Jump to content
kal

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

Recommended Posts

The formulas aren't in the scripts anymore. They're in the database. Check the Skills and Items tabs, and look at the Damage box. You can put the formula in there. Also check the help file for instructions and examples.

shaz, I meant the formula the game uses to calculate the EXP needed for next level. What I meant is that in previous versions I could find the variables with wich they created the EXP graphic, but for some reason I can'f find the formula, now. I do realize that skills and item damage, recover, etc, formulas have been put in the database.

  • Like 1

Share this post


Link to post
Share on other sites

Is there a way to set it so that events with the Through option set override the tile it's placed on? Where in the scripts is that handled?

Share this post


Link to post
Share on other sites

They are actually defined in the scripts; they're just not inside scripts you normally have access to. You can still find it and modify it if you dig a little. It's defined inside RPG::Class in a method called "exp_for_level(level)".

 

class RPG::Class < RPG::BaseItem
 def exp_for_level(level)
lv = level.to_f
basis = @exp_params[0].to_f
extra = @exp_params[1].to_f
acc_a = @exp_params[2].to_f
acc_b = @exp_params[3].to_f
return (basis*((lv-1)**(0.9+acc_a/250))*lv*(lv+1)/
  (6+lv**2/50/acc_ +(lv-1)*extra).round.to_i
 end

 

Basis, Extra, Acc_A and Acc_B are variables assigned to a class inside the database. If your new formula won't use them, you could just ignore them and override the function with whatever code you want.

Edited by Kaelan

Share this post


Link to post
Share on other sites

Is there a way to set it so that events with the Through option set override the tile it's placed on? Where in the scripts is that handled?

 

Override the tile?

You can access the through flag directly

 

<Event>.through

 

but not sure what you want to do.

Share this post


Link to post
Share on other sites

Currently, if an event with Through is placed on a tile that is not passable, the player cannot step on the tile. I want the events Through property to take priority over the tiles passability setting.

Share this post


Link to post
Share on other sites

Passability flags are in the help docs for RPG::tileset.

 

class Game_Map

 

def passable?(x, y, d)
 check_passage(x, y, (1 << (d / 2 - 1)) & 0x0f)
end

 

def check_passage(x, y, bit)
 all_tiles(x, y).each do |tile_id|
   flag = tileset.flags[tile_id]
   next if flag & 0x10 != 0            # [☆]: No effect on passage
   return true  if flag & bit == 0     # [â—‹] : Passable
   return false if flag & bit == bit   # [×] : Impassable
 end
 return false                          # Impassable
end

 

Note that all_tiles includes events

 

def all_tiles(x, y)
 tile_events_xy(x, y).collect {|ev| ev.tile_id } + layered_tiles(x, y)
end

 

So you should be able to just check the events at that position as well.

Edited by Tsukihime

Share this post


Link to post
Share on other sites

I don't know if this was already asked. I just want to know how to create a next line when the text reaches the width of the window. Here's the script

 


def draw_objective(x, y)
   change_color(system_color)
   draw_text(x, y + line_height * 0, contents.width, line_height, "Current objective:")
   change_color(normal_color)
   draw_text(x, y + line_height * 1, contents.width, line_height, $goal)
end

 

The $goal here is the objective itself.

 

Thanks for helping!

Share this post


Link to post
Share on other sites

Where do I go to change the default system font?

 

I know I can change an individual window's font by doing:

 

contents.font.name = "Arial"

 

How do I do that for the whole game at once?

 

 

Edit:

 

I don't know if this was already asked. I just want to know how to create a next line when the text reaches the width of the window. Here's the script

 

Funny you should ask, that's exactly what I'm working on. You need to grab the width of the text and insert newlines every time it exceeds the width of the window. The problem is, as far as I can tell, Ruby doesn't have a standard way of doing font metrics, so there doesn't appear to be any simple way to get the physical width of any arbitrary string in pixels.

 

My workaround for this is just using a fixed-width font, so you know the exact size of each character. If you use that and take into account the font size, you should be able to figure out how much space any given string will take by just counting the length. Once you know how many pixels each character takes, you just have to override the draw_text function to insert a newline every X characters (X being some number based on the size of the window) in a string before drawing it.

Edited by Kaelan

Share this post


Link to post
Share on other sites

You might be able to get away with using Bitmap#text_size to calculate the width of a given line

 

Gets the box (Rect) used when drawing the string str with the draw_text method. Does not include the outline portion (RGSS3) and the angled portions of italicized text.

 

The other issue to consider is the impact of just adding new-line chars without reformatting the original string. For example, if I wrote something like

 

This is my line. It is very long. But I've calculated it so that I should 
break my line here.

 

Unfortunately, I suddenly decide to increase font size to 32 px rather than 24 px, and now the display might end up looking like

 

This is my line. It is very long. But I've calculated it
so that I should
break my line here.

 

Which just looks weird.

Share this post


Link to post
Share on other sites

You could probably just duplicate that string

 

string2 = String.new(string1)

 

and, each time you use your method that inserts "\n"'s at specific points, re-run above line of code before and then apply the method to the duplicated string.

Share this post


Link to post
Share on other sites

You might be able to get away with using Bitmap#text_size to calculate the width of a given line

 

Gets the box (Rect) used when drawing the string str with the draw_text method. Does not include the outline portion (RGSS3) and the angled portions of italicized text.

 

Isn't that just the width of the rect you pass draw_text when you call it? The actual string can be arbitrarily larger/longer than that

 

The other issue to consider is the impact of just adding new-line chars without reformatting the original string. For example, if I wrote something like

 

This is my line. It is very long. But I've calculated it so that I should
break my line here.

 

Unfortunately, I suddenly decide to increase font size to 32 px rather than 24 px, and now the display might end up looking like

 

This is my line. It is very long. But I've calculated it
so that I should
break my line here.

 

Which just looks weird.

 

Edit: I forget everything is pass-by-reference by default in Ruby. You can just create a copy of the passed string before displaying it and only modify the copy.

Edited by Kaelan

Share this post


Link to post
Share on other sites

Im trying to modify the Scene_Shop class to implement a simple crafting system but I can't figure out what these things mean:

 

class Scene_Shop < Scene_MenuBase
 #...
 def create_command_window
#...
@command_window.set_handler(:buy, method(:command_buy))
#...
 end
 #....
end

 

What are the :buy and :command_buy things?

I'm going to need to modify them or make my own to do what I want to do but I have no clue what they are.

Share this post


Link to post
Share on other sites

A handler is method that will be called when some event happens within the window. In that case, something at somepoint causes a ":buy" event to fire (my guess is it's probably an option in the command window, so it gets triggered when the player hits confirm while highlighting "Buy" in the menu, and it got there because at some point it was added via the add_command function), and when that happens, the menu will call the method called ":command_buy". If you wanted more options than whatever the default shop window has, you'd implement more of them in the same way. i.e.:

 

class Scene_MyShop < Scene_Shop
 def create_command_window
@command_window.set_handler(:a_crafting_command, method(:a_function_that_gets_called_and_lets_you_craft_things))
 end

 #...

 def a_function_that_gets_called_and_lets_you_craft_things
# ....
 end

end

Edited by Kaelan

Share this post


Link to post
Share on other sites

Here's one: I want critical hits to ignore the target's Defense, as opposed to doing a flat multiplication of the damage.

 

  #--------------------------------------------------------------------------
 # * Apply Critical
 #--------------------------------------------------------------------------
 def apply_critical(damage)
damage * 3
 end

 

I'm pretty sure that this is where I'd modify VX Ace's base scripts to accomplish that. My problem is...I have no idea how to do that. What would I change this part of the script to, so that all critical hits ignore the foe's Defense/treat it as zero? (Note that I have no intentions of letting non-physical attacks/skills crit).

Share this post


Link to post
Share on other sites

The issue is that the formula you write is evaluated directly.

 

class RPG::UsableItem::Damage
 def eval(a, b, v)
   [Kernel.eval(@formula), 0].max * sign rescue 0
 end
end

 

You would basically have to define a custom "damage eval" formula that will take in a critical flag indicating whether the critical went through or not (through @result.critical), and then modify the formula to ignore b.def or b.mdef, whichever is used.

 

It is not a very clean change to do.

Edited by Tsukihime

Share this post


Link to post
Share on other sites

Since my last question was a bust... If my information is correct, this is the part of the script that determines when substitute will work:

 

  def check_substitute(target, item)
target.hp < target.mhp / 4 && (!item || !item.certain?)
 end

 

What would I need to change this to, so that the user will take attacks for their allies, regardless of their (user's and allies') HP? (Also, I'm not really certain how it works beyond "they need to have less HP." I can't seem to get it to work at all.)

Share this post


Link to post
Share on other sites

A quick question. To call the item menu via a script, I know to use the code:

SceneManager.call(Scene_Item)

How would I make it so a script call would go straight to 'key items' submenu of the items scene?

 

EDIT: I suppose that would mean to set the cursor to to key items somehow?

Share this post


Link to post
Share on other sites

I have a question about Ramiro's Battle Engine (doesn't seem to be answered on his blog). During battle, all(most?) actions make the camera zoom in. I'd like to disable this so there is no camera zooming during battle. Anyone know how I might do that?

 

Ideally, I'd like to disable the battler/enemy graphic scaling as well.

Share this post


Link to post
Share on other sites

New to Ruby scripting and had a question about accessing game variables and switches.

I assumed it's as simple as using a script that says $game_variables[a] = value, $game_switches = true, but I can't get those to work.

Specifically when using this kind of conditional statement:

 

$game_switches = true

Conditional branch: script: $game_switches == true

...

else

...

branch end

 

I get errors telling me: " undefined local variable or method for 'b' "

 

Normally i would have just used the event menu, but for this particular script I want to check multiple switches at once using &&s. However, I can't even seem to be able to control even one switch using script so I was wondering what i am doing wrong

 

Thanks so much.

Edited by awake234

Share this post


Link to post
Share on other sites

@Rigor

  def check_substitute(target, item)
   target.hp <= target.mhp && (!item || !item.certain?)
 end

Should work

 

@awake

are you actually using $game_switches because $game_switches uses numbers for the switch_id

eg

$game_switches[2] = true

Conditional branch: script: $game_switches[2] == true

Share this post


Link to post
Share on other sites

Perfect Xypher. Thanks so much.

 

same with variables i assume? the number of the variable instead of the custom name i've assigned?

Share this post


Link to post
Share on other sites

Yep, $game_variables[2]==1 or whichever variable you're checking

Share this post


Link to post
Share on other sites

Anyone ever decrypted the built-in Window class? I need help on lowering the spot where the contents are drawn...

Share this post


Link to post
Share on other sites

ox

The x-coordinate of the starting point of the window's contents. Change this value to scroll the window's contents.

 

Also affects the cursor. (RGSS3)

 

oy

The y-coordinate of the starting point of the window's contents. Change this value to scroll the window's contents.

 

Also affects the cursor. (RGSS3)

 

Just set the ox and oy values.

Share this post


Link to post
Share on other sites

That's not really what I'm trying to achieve. There's this window, it's a selectable window. It has a list of data BUT also some text above that. I want to have the text display at all times, while you can still freely scroll in the datalist. However, since the basic system uses oy and ox values for the list, I'm having a lot of trouble managing this. Already tried normally, with the ox/oy way and with a couple of variables.

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