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

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
7,176
Reaction score
10,569
First Language
Indonesian
Primarily Uses
N/A
Or be dumb like
Ruby:
class Game_System
  #--------------------------------------------------------------------------
  # * New Method:
  #--------------------------------------------------------------------------
  def unlock_achievement_slot
    $game_switches
  end
end
Ruby:
$game_system.unlock_achievement_slot[value] = string
 
Last edited:

FG7

Veteran
Veteran
Joined
Jan 4, 2021
Messages
76
Reaction score
27
First Language
English
Primarily Uses
RMVXA
Or be dumb like
Ruby:
class Game_System
  #--------------------------------------------------------------------------
  # * New Method:
  #--------------------------------------------------------------------------
  def unlock_achievement_slot(value)=(string)
    $game_switches
  end
end
Ruby:
$game_system.unlock_achievement_slot[value] = string
Well, as long as the solution works... is it really dumb? I will give this one a go as well. Thanks for the different approach.
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
7,176
Reaction score
10,569
First Language
Indonesian
Primarily Uses
N/A
Oh I forgot to remove the parameters, edited
 

mashedcookie

Warper
Member
Joined
Mar 24, 2022
Messages
2
Reaction score
0
First Language
Indonesia
Primarily Uses
RMVXA
I have a question regarding game_battlerbase. This is long but actually just need short answer.
Please bear with me.
Im not a scripter, only can read basic stuff.
Suppose I want to create custom hit rate, I copy item_hit from game_battler and create new snippet.
I use sixth custom param to create custom parameter and Yanfly enemy level so enemy can have its own level (albeit no parameter growth)
Ruby:
def item_hit(user, item)
    rate = item.success_rate * 0.01     # Get success rate
    rate *= ((user.hit*1.0) / self.eva) + (((user.level+user.hit)*1.0) / (self.level + self.eva)) / 2 
    return rate                         # Return calculated hit rate
  end
Thing is, this is work.
But on my mind, this shouldnt. The code is filled with user. and self.
And self.(?) is actually refering to enemy? shouldnt it be the attacker ?

And then my formula damage snip
Ruby:
def basicatk(base)
   ((self.level+(self.atk*base/100.0) - (target.def/2))*(100.0/(100+(target.def/2.0))))*self.tdm
end
I can use target.def, my brain can accept it.
But why item_hit cant use target. ?
Ruby:
def apply_critical(damage)
    damage * target.cdmg / 100.0
  end
and this critical damage multiplier only work when using target.critical stats instead self.critical stats
Can someone explain to me why this is happen ?
As people who isnt scripter like me, these arent make sense because they are classmates (in 1 class).
 

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
7,176
Reaction score
10,569
First Language
Indonesian
Primarily Uses
N/A
The code is filled with user. and self.
And self.(?) is actually refering to enemy? shouldnt it be the attacker ?
"Self" refers to the target (actor/enemy).
"User" refers to the attacker (or the user of skill/item)
Because the function is evaluated within the target object, not the attacker.

"Self" is a Ruby keyword that refers to the class instance (for example, the enemy object).

I can use target.def, my brain can accept it.
But why item_hit cant use target. ?
Because there is no reference to "target". What does it mean? what does it refer to?
If it is used in the damage formula, you can do it like

Ruby:
def basicatk(base, target, user)
   ((user.level+(user.atk*base/100.0) - (target.def/2))*(100.0/(100+(target.def/2.0))))*user.tdm
end
Then in the damage formula
Ruby:
basicatk(100, b, a)
You are passing it as an argument to the function

EDIT:
I misread your post, but my answer is still the same.
There is no reference to "target" in the item_hit.

and this critical damage multiplier only work when using target.critical stats instead self.critical stats
Are you sure it isn't the otherwise?
 

NoPiessadface

Veteran
Veteran
Joined
Feb 7, 2019
Messages
190
Reaction score
55
First Language
english
Primarily Uses
RMVXA
how do i make the sprite called in a method appear?

Ruby:
  def attack_state
    @bitmap = Bitmap.new(32,32)
    @hitbox = Rect.new(Graphics.width/2,Graphics.height/2,32,32)
    @color  = Color.new(255,255,255,0)
    @viewport = Viewport.new(@hitbox)
    @sprite = Sprite.new(@viewport)
    
    @get_dir = "right" if Input.repeat?(:RIGHT)
    @get_dir = "left"  if Input.repeat?(:LEFT)
    @get_dir = "up"    if Input.repeat?(:UP)
    @get_dir = "down"  if Input.repeat?(:DOWN)
    
    if Input.trigger?(:C)
      @bitmap.fill_rect(@hitbox, @color)
      @sprite.src_rect = @hitbox
      @sprite.ox = @hitbox.x
      @sprite.oy = @hitbox.y
      @sprite.update
#      msgbox(@character_index)
    end
    return
  end
 

Tw0Face

Master Strategist
Veteran
Joined
Nov 12, 2018
Messages
623
Reaction score
473
First Language
German
Primarily Uses
RMVXA
For RPG Vx Ace, I'm looking for a snippet that plays a SE only once as soon as the title screen appears.
 

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
884
Reaction score
425
First Language
English
Primarily Uses
RMXP
You could place it here:
Ruby:
class Scene_Title
  def play_title_music
    se = RPG::SE.new("Teleport")
    se.play
    $data_system.title_bgm.play
    RPG::BGS.stop
    RPG::ME.stop
  end
end

Or use an alias instead of rewriting the play_title_music method. XD

And there's also using this:

Ruby:
class Scene_Title
  def post_start
    super
    se = RPG::SE.new("Teleport")
    se.play
  end
end
 
Last edited:

Tw0Face

Master Strategist
Veteran
Joined
Nov 12, 2018
Messages
623
Reaction score
473
First Language
German
Primarily Uses
RMVXA
You could place it here:
Thanks. :LZSjoy: Can I prevent the SE from playing anytime I cancel out the save menu (or any other menu on the title screen)? That's because the SE should only play once as soon as the title screen is shown after the first time (or after F12).
 

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
884
Reaction score
425
First Language
English
Primarily Uses
RMXP
Weird, I clearly defined it inside Scene_Title for a reason... I'd have to check the default scripts later on.
 

Tw0Face

Master Strategist
Veteran
Joined
Nov 12, 2018
Messages
623
Reaction score
473
First Language
German
Primarily Uses
RMVXA
Weird, I clearly defined it inside Scene_Title for a reason... I'd have to check the default scripts later on.
Have you already had some time to take a look at it, maybe?
 

Roninator2

Gamer
Veteran
Joined
May 22, 2016
Messages
4,690
Reaction score
1,327
First Language
English
Primarily Uses
RMVXA
Can't stop it from playing without using global save data when closing the game and starting it again.
Otherwise this should work
Ruby:
class Scene_Title
  alias r2_title_snd_once play_title_music
  def play_title_music
    se = RPG::SE.new("teleport")
    se.play unless $onetitlesnd
    $onetitlesnd = true
    r2_title_snd_once
  end
end
 
Last edited:

kyonides

Reforged is laughable
Veteran
Joined
Nov 17, 2019
Messages
884
Reaction score
425
First Language
English
Primarily Uses
RMXP
Can't stop it from playing without using global save data when closing the game and starting it again.
Otherwise this should work
Ruby:
class Scene_Title
  alias r2_title_snd_once play_title_music
  def play_title_music
    $onetitlesnd = false if $onetitlesnd == nil
    se = RPG::SE.new("teleport")
    se.play unless $onetitlesnd
    $onetitlesnd = true
    r2_title_snd_once
  end
end
Err, @Roninator2 you have no need to initialize such a global variable for nil is treated like a false value in Ruby anyway.
As he told you, @Tw0Face , only something global could help you then. That's as simple as saving a separate file with just that variable's value stored therein.
 

Latest Threads

Latest Posts

Latest Profile Posts

My mom showed up yesterday and I wanted to proudly show off my comic con web page. So of course, it no longer existed. I guess when the 4 day event was over they removed it.
Feeling like a creative Pattato this morning...
Calibrating the timing of dialogue is deffo my new least favorite thing.
I died aged 27 to cancer. Then I was reborn in a South-American state. I retained all memories and skill and had a goal from my previous life I needed to finish, but now I was just a 1-year-old girl capable of only smiling at others.

Dreams like this one make me glad I'm able to wake up from them at will.
Found a critical bug the other day with the time system that would have caused none of the NPCs to spawn. Since I use dev mode to test time-based stuff, I didn't catch this for way too long!

Forum statistics

Threads
129,979
Messages
1,206,686
Members
171,205
Latest member
CuriousMonkeyX
Top