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

Code:
p @problem# => nil
Wanted to wait awhile before "bumping" this, but it seems to have been buried, so I'll ask again! Still looking for all that lovely element/state resistance syntax. Thanks!

(Also sorry if repeating an unanswered question is against the forum rules or something)

Another RMXP question for you guys. Thanks for all of your time and effort, really appreciated.

I've re-purposed the dex_f and agi_f values (since I won't be needing Dexterity or Agility-based attacks) to allow for more control over applying states with skills. The bit of code I added looks like this:

Code:
if skill.dex_f > 0  if rand(100) < skill.dex_f    # Removes state to restart turn count    if self.state?(skill.agi_f)      self.remove_state(skill.agi_f)    end    self.add_state(skill.agi_f)    endend
 

I'm not a scripter by any means, so apologies if that code is cringe-worthy, but it gets the job done. Setting a skill in the database with Dex-F of 75 and an Agi-F of 2 makes the skill apply poison 75% of the time on top of whatever else the skill does. The thing is, this obviously overwrites the A-F state resistances that the target has. I've looked through the code to see what kind of syntax I would have to use to add that functionality to what I have, but I'm at a loss.

 

I know where to find and modify what values A-F have, but I have no idea how to properly add them into my code. Say I wanted a D rating to cut the success chance in half, I could change D's value elsewhere to 2, and do this:

 


Code:
rate = skill.dex_f / [state resistance modifier]if rand(100) < rate[etc...]

 

I could add an if case for if the rating is F, maybe at the very top, like: [if rating is not F, (do state calculations)] so that if won't even run the code if the target's immune to that state.

 

Basically I'm looking for the syntax to call the value of the state resistance letter (A-F). Or really, any and all syntax available dealing with element and state resistance ratings. Answers will probably lead to more questions, but again, I appreciate your time. Thanks in advance!
So I'm curious, are these the param ids?

def mhp;  param(0);   end               # MHP  Maximum Hit Points  def mmp;  param(1);   end               # MMP  Maximum Magic Points  def atk;  param(2);   end               # ATK  ATtacK power  def def;  param(3);   end               # DEF  DEFense power  def mat;  param(4);   end               # MAT  Magic ATtack power  def mdf;  param(5);   end               # MDF  Magic DeFense power  def agi;  param(6);   end               # AGI  AGIlity  def luk;  param(7);   end               # LUK  LUcK  def hit;  xparam(0);  end               # HIT  HIT rate  def eva;  xparam(1);  end               # EVA  EVAsion rate  def cri;  xparam(2);  end               # CRI  CRItical rate  def cev;  xparam(3);  end               # CEV  Critical EVasion rate  def mev;  xparam(4);  end               # MEV  Magic EVasion rate  def mrf;  xparam(5);  end               # MRF  Magic ReFlection rate  def cnt;  xparam(6);  end               # CNT  CouNTer attack rate  def hrg;  xparam(7);  end               # HRG  Hp ReGeneration rate  def mrg;  xparam(8);  end               # MRG  Mp ReGeneration rate  def trg;  xparam(9);  end               # TRG  Tp ReGeneration rate  def tgr;  sparam(0);  end               # TGR  TarGet Rate  def grd;  sparam(1);  end               # GRD  GuaRD effect rate  def rec;  sparam(2);  end               # REC  RECovery effect rate  def pha;  sparam(3);  end               # PHA  PHArmacology  def mcr;  sparam(4);  end               # MCR  Mp Cost Rate  def tcr;  sparam(5);  end               # TCR  Tp Charge Rate  def pdr;  sparam(6);  end               # PDR  Physical Damage Rate  def mdr;  sparam(7);  end               # MDR  Magical Damage Rate  def fdr;  sparam(8);  end               # FDR  Floor Damage Rate  def exr;  sparam(9);  end               # EXR  EXperience Rate
If so, where is the experience give? when you kill an enemy, you get Experience... how do I manipulate that? Is EXR the experience gain?
In Game_Actor you have this method:

#-------------------------------------------------------------------------- # * Get EXP (Account for Experience Rate) #-------------------------------------------------------------------------- def gain_exp(exp) change_exp(self.exp + (exp * final_exp_rate).to_i, true) endso you see the formula is just current_exp + (troop_max_exp * final_exp_rate)

final_exp_rate looks like this:

  def final_exp_rate    exr * (battle_member? ? 1 : reserve_members_exp_rate)  endSo yes, exr is the experience rate.

So you can make states, equipment which changes the exr of an actor, so he would gain more or less exp.
Well I wanted to know because i'm using a Difficulty setting, I was going to increase Experience based on difficulty. 

I have one more question, how can I break up a when statement? I have:

case $game_variables[Bloody_Difficulty:😀ifficulty_Variable]        when 0 then (bloody_param(param_id) * Bloody_Difficulty::Easy).to_i        when 1 then (bloody_param(param_id) * Bloody_Difficulty::Normal).to_i        when 2 then (bloody_param(param_id) * Bloody_Difficulty::Hard).to_i        when 3 then (bloody_param(param_id) * Bloody_Difficulty::Insane).to_i
However, I'm about to make a rehaul on my difficulty script, and I need to be able to put more then 1 line for each. do I just need to put a comma after each line?
Code:
case #somethingwhen :something  #then do codewhen :toerhthing  #then do this codeend
You can do this:

Code:
case $game_variables[Bloody_Difficulty::Difficulty_Variable]        when 0           (bloody_param(param_id) * Bloody_Difficulty::Easy).to_i           # next line            # next line           # and so on        when 1           (bloody_param(param_id) * Bloody_Difficulty::Normal).to_i           # next line           # next line           # and so on        when 2           (bloody_param(param_id) * Bloody_Difficulty::Hard).to_i        when 3          (bloody_param(param_id) * Bloody_Difficulty::Insane).to_i        else         # if you need else        end
I'm so ninja!
So... there is no need to put the then in there?
Nope, but if you are only using a small line of code then it looks much neater if you do.

Also, could simply end the line with ';' rather than using then, like this

Code:
case $game_variables[500]when 0 ; # codewhen 1 ; # codeelse   ; # codeend
I see, so can I use a module for numbers when using when?

when Bloody_Difficulty:😀ifficulty_Numbers:😀ifficulty_Easy          (bloody_param(param_id) * Bloody_Difficulty::Easy).to_i
This line:

when Bloody_Difficulty:😀ifficulty_Numbers:😀ifficulty_Easy

is supposed to be when 0 (or whatever the player has it at.)
You could, I dont really see what the point would be though. For such a system it is best to have fixed numbers defined. It causes less chance of users causing random errors and inundating you with questions on why [x] doesn't work 😛
Hm, true. Good point.

Thank you both for your help 🙂
p Object.const_defined?🙂Problem)# => false 😉
Ehh, one more problem... lol.

if Blood::Simple::Simple == false    def param(1)      case $game_variables[Bloody_Difficulty:😀ifficulty_Variable]        when 0          (bloody_param(1) * Blood::Easy::MHP).to_i
Would this be correct? Don't pay attention to the false, it has nothing to do with anything that I'm asking, I know thats right. But the

def param(0) then

 when 0

          (bloody_param(0) * Blood::Easy::MHP).to_i

I feel like this might be wrong.
why are you inputting the number 1 where the variable 'param_id' should be?

That will cause quite a few problems with calculating stats.
Because I want to manipulate each param individually, multiplying them all by a set amount is funky, and it will be easier to balance if I can control every param. I'm assuming thats not how you do that?
You would want to do something like this i think...

  def param(param_id)    case $game_variables[500]    when 0      case param_id      when 0 then #id 0 = mhp      when 1 then #id 1 = mmp      when 2 then #id 2 = atk      when 3 then #id 3 = def      when 4 then #id 4 = mat      when 5 then #id 5 = mdf      when 6 then #id 6 = agi      when 7 then #id 7 = luk      end    when 1      #...    end  endEdit:

That seems like it could get somewhat lengthy. Proably best to have it call another method based on the difficulty settings and having each param mod take place within that.

Code:
  def param(param_id)    case $game_variables[500]    when 0 then (alias_name(param_id) * easy_param_mod(param_id)).to_i    when 1      #...    end  end   def easy_param_mod(param_id)    case param_id    when 0 then return 1.5    when 1 then return 1.5    when 2 then return 1.2    #...    end  end
Hm, that seems a bit confusing, wouldn't this:

def param(param_id)      case $game_variables[Bloody_Difficulty:😀ifficulty_Variable]        when 0          (bloody_param(0) * Blood::Easy::MHP).to_iDo the same thing?

EDIT: Out of all the confusion happening here, I think I need to post my full script.

Spoiler
Code:
#--------#Script By: Bloodmorphed#Difficulty Script v1.0##Change Log:#v1.0#Simple version. Checks difficulty and multiplies based on the difficulty, also#easily modified.####--------#-----------------# Determines what variable, and the multiplier based on difficulty## Feel free to edit these. Make sure you are using the right variable!#-----------------module Blood  #--------------------------------------------------------------  # True or false, this determines to use the simplified version of the code, or  # not. True means it will use it, false means it wont.  #--------------------------------------------------------------  module Simple    Simple = true    Simple_Easy = 0.5        #If Simple = true this will be used for easy    Simple_Normal = 1        #If Simple = true this will be used for normal    Simple_Hard = 2          #If Simple = true this will be used for hard    Simple_Insane = 4        #If Simple = true this will be used for insane  end # ends Simple  #--------------------------------------------------------------  # Variable to use.  #--------------------------------------------------------------  module Variable    Difficulty_Variable = 100     # Which variable to use? Default is 100  end #ends variable  #--------------------------------------------------------------  # This part of the script gives you precise control over which gets edited  #  # MHP - Maximum Hit Points  # MMP - Maximum Mana Points  # ATK - Attack Power  # DEF - Physical Defense  # MAT - Magic Attack  # MDF - Magic Defense  # AGI - Agility  # LUK - Luck  # EXR - Experience Rate  #  # Default for Easy is 0.5  # Default for Normal is 1  # Default for Hard is 2  # Default for Insane is 4  #  # Please note that this is MULTIPLYING not ADDING, so make small increments  # otherwise you will have an extreme vamp.  #  #  #--------------------------------------------------------------  module Easy    MHP = 0.5    MMP = 0.5    ATK = 0.5    DEF = 0.5    MAT = 0.5    MDF = 0.5    AGI = 0.5    LUK = 0.5    EXR = 0.5  end #ends easy  module Normal    MHP = 1    MMP = 1    ATK = 1    DEF = 1    MAT = 1    MDF = 1    AGI = 1    LUK = 1    EXR = 1  end #ends normal  module Hard    MHP = 2    MMP = 2    ATK = 2    DEF = 2    MAT = 2    MDF = 2    AGI = 2    LUK = 2    EXR = 2  end #ends hard   module Insane    MHP = 4    MMP = 4    ATK = 4    DEF = 4    MAT = 4    MDF = 4    AGI = 4    LUK = 4    EXR = 4  end #ends insaneend #ends Blood #===============================================================================class Game_Enemy#===============================================================================  #-----------------------------------------------------------------------------  # List Of Aliased Methods  #-----------------------------------------------------------------------------  alias :bloody_param :param :bloody_sparam :sparam  #-----------------------------------------------------------------------------  # Method to determine value of enemies params based on difficulty.  #-----------------------------------------------------------------------------   if Blood::Simple::Simple == true    def param(param_id)      case $game_variables[Blood::Difficulty_Variable]        when 0          (bloody_param(param_id) * Blood::Simple::Simple_Easy).to_i        when 1          (bloody_param(param_id) * Blood::Simple::Simple_Normal).to_i        when 2          (bloody_param(param_id) * Blood::Simple::Simple_Hard).to_i        when 3          (bloody_param(param_id) * Blood::Simple::Simple_Insane).to_i      end #ends case    end #ends def  end #ends if   if Blood::Simple::Simple == false    def param(param_id)      case $game_variables[Blood::Difficulty_Variable]        when 0          (bloody_param(1) * Blood::Easy::MHP).to_i        end #ends class
def param(param_id)      case $game_variables[Bloody_Difficulty:😀ifficulty_Variable]        when 0          (bloody_param(0) * Blood::Easy::MHP).to_iDo the same thing?
Nope.

That code would check what the difficulty level is, if it was easy, it would return the value of (mhp * Blood::Easy::MHP).to_i for all params.

Edit:

Your script is somewhat excessive. Also, for a specific script you really should have a unique thread for it. This thread is more for simple questions that can be answered in one or two replies. 🙂

You could do something using a hash and arrays, like this...

module Blood   Difficulty_Settings = {     :easy => [2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 2.0],     :medi => [1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5, 1.5],     :hard => [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],  }end class Game_Enemy  def param(param_id)    case $game_variables[500]    when 0      (alias_name(param_id) * Blood:😀iffiulty_Settings[:easy][param_id]).to_i    when 1      (alias_name(param_id) * Blood:😀iffiulty_Settings[:medi][param_id]).to_i    when 2      (alias_name(param_id) * Blood:😀iffiulty_Settings[:hard][param_id]).to_i      #...    end  endend
That would dramatically reduce your code size.

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