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

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
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.
Oh I forgot to remove the parameters, edited
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.
Spoiler: Case
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).
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?
Not sure if this warrants its own thread. I've seen other threads for this issue, but they've went unsolved. Just let me know if I should move this post.

Moved to this thread: https://forums.rpgmakerweb.com/inde...atb-yanfly-battle-engine-addon-script.150507/
Not sure if this warrants its own thread.
Yes, it does.
Yes, it does.
Okay, thank you. I'll repost in it's own thread and delete that post.
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
For RPG Vx Ace, I'm looking for a snippet that plays a SE only once as soon as the title screen appears.
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
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).
Weird, I clearly defined it inside Scene_Title for a reason... I'd have to check the default scripts later on.
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?
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
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.
no need to initialize such a global variable for nil is treated like a false value
yes of course, I see. Setting to false if not needed.
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!
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.
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.

Original thread: https://forums.rpgmakerweb.com/threads/ruby-rgssx-questions-that-dont-deserve-their-own-thread.150/