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

TheoAllen

Self-proclaimed jack of all trades
Regular
Joined
Mar 16, 2012
Messages
7,530
Reaction score
11,935
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

Regular
Regular
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
Regular
Joined
Mar 16, 2012
Messages
7,530
Reaction score
11,935
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
Regular
Joined
Mar 16, 2012
Messages
7,530
Reaction score
11,935
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

Regular
Regular
Joined
Feb 7, 2019
Messages
197
Reaction score
62
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
Regular
Joined
Nov 12, 2018
Messages
676
Reaction score
511
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
Regular
Joined
Nov 17, 2019
Messages
1,885
Reaction score
960
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
Regular
Joined
Nov 12, 2018
Messages
676
Reaction score
511
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
Regular
Joined
Nov 17, 2019
Messages
1,885
Reaction score
960
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
Regular
Joined
Nov 12, 2018
Messages
676
Reaction score
511
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
Regular
Joined
May 22, 2016
Messages
5,226
Reaction score
1,557
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
Regular
Joined
Nov 17, 2019
Messages
1,885
Reaction score
960
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.
 

TheNewSon

Regular
Regular
Joined
Aug 24, 2019
Messages
76
Reaction score
138
First Language
Portuguese
Primarily Uses
Other
For RMXP, is there a script that increases an event's activation range? Something like this VXA script or this MV plugin. Thanks in advance!
 

Pingwen

Villager
Member
Joined
Apr 15, 2023
Messages
19
Reaction score
2
First Language
English
Primarily Uses
RMXP
For RGSSx, how do I refer to the element set of an attacking actor's equipped weapon? I'm trying to modify my own damage system, but "elements_correct(attacker.element_set)" and "elements_correct(weapon.element_set)" both just crash the game.

I'm messing with Game_Battler 3, under the "apply skill effects" section, and I'm sure there's something I need to call on, but I don't know what or how.
 

KK20

Just some XP Scripter
Regular
Joined
Oct 11, 2018
Messages
495
Reaction score
204
First Language
English
Primarily Uses
RMXP
For RGSSx, how do I refer to the element set of an attacking actor's equipped weapon? I'm trying to modify my own damage system, but "elements_correct(attacker.element_set)" and "elements_correct(weapon.element_set)" both just crash the game.

I'm messing with Game_Battler 3, under the "apply skill effects" section, and I'm sure there's something I need to call on, but I don't know what or how.
elements_correct(user.element_set)

As described...
Code:
  #--------------------------------------------------------------------------
  # * Apply Skill Effects
  #     user  : the one using skills (battler)
  #     skill : skill
  #--------------------------------------------------------------------------
  def skill_effect(user, skill)
user is the variable name you want to use.
 

Latest Threads

Latest Profile Posts

I have completed what is clearly the most important part of participating in the game jam: coming up with a name!
My shrink has me trying to limit 30 mins a day for each of my personal projects so I can have a healthier life. But lately the rpg making in particular has been hard to pull away from and I keep getting lost in it.
Everyone has a test project named like this...right?

1701263020760.png
Pardon my japanese but this is my honest reaction to yesterday's "tangent":
1701262223568.png
I know these are all simple things for experienced users, but working on this Game Jam I have officially learned how to:
  • Use my own title screen image
  • Use scrolling text
  • Fade in a picture
  • Use any image for the Face in a dialog box
Probably silly for many people, but observable progress for me!

Forum statistics

Threads
136,570
Messages
1,267,668
Members
180,254
Latest member
jennyyu16
Top