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

TheoAllen

Self-proclaimed jack of all trades
Veteran
Joined
Mar 16, 2012
Messages
7,316
Reaction score
10,998
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,316
Reaction score
10,998
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,316
Reaction score
10,998
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
195
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
Veteran
Joined
Nov 12, 2018
Messages
630
Reaction score
474
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
1,058
Reaction score
492
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
630
Reaction score
474
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
1,058
Reaction score
492
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
630
Reaction score
474
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,819
Reaction score
1,368
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
1,058
Reaction score
492
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

Veteran
Veteran
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
Veteran
Joined
Oct 11, 2018
Messages
480
Reaction score
195
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 Posts

Latest Profile Posts

Ooops ended up trying out making my own A2 tile page instead of testing doors everywhere. Went well so far I think.
I guess I'm done making a blue squirrel's life difficult for posting new threads on different forums.
That's just for today so don't get used to this, squirrel-ish friend! :p
Got new hard drive, now trying to install the softwares I lost to the dead drive, and more than half of them won't install because they're already installed on the dead drive, and uninstallers won't run because they can't find where their programs are installed. So I take it having a drive die on you screws you in more ways than just data loss. >:\
PC got fixed finally. Back online again. Turns out I have no business trying to self repair pcs because it was getting to like 176F / 80C. Shop installed a totally new cooling system and now it runs fine and is super quiet.
When you're making major progress, but have to stop to go to work.

Forum statistics

Threads
131,485
Messages
1,220,209
Members
173,225
Latest member
ZecaVn
Top