Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

[XP] Hard-Coding Passive Abilities and Weapon Abilities

Coding in RMXP.

Okay, so I'm trying increase my knowledge of scripting in Ruby. Overall, I'm pretty good at taking already created scripts and editing them, but I still struggle a LOT scripting on my own with definitions and syntax, so I'm trying to learn.

I know there's some Passive Skill scripts out there, but I want to make some passive skills do things that aren't in these scripts such as:

1. Increase Critical % in battle
2. Increase damage/number of attacks with a certain weapon type
3. Increase XP/Gold gain after combat (Gando's script, for some reason, is incompatible with my skill learning system)
etc.

For the most part, I know where to find most of these things in the basic script, it's just a matter of adding them. I'm having a lot more trouble with skills, where it is a situation of "if this character knows skill 1, then increase (insert whatever)."

1. How do I code this?: "If character i knows skill 1, then increase critical by 3%"

I think I have equipment down. So, weapon 21 is +3% critical and weapon 5 is +5% critical. Does this look okay?:
Code:
      if self.damage > 0

        if attacker.weapon_id = 21

          crit = 3

        eslif attacker.weapon_id = 22

          crit = 5

        end

        # Critical correction

        if rand(100) < (4 * attacker.dex / self.agi) + crit

          self.damage *= 2

          self.critical = true

        end

2. Again, I'm not sure how to code skills into this.

If I wanted to create equipment with similar effects...say I have an accessory called "Gauntlet" at Armor ID: 100, and I want it to increase damage by 50% for all swords (Weapon ID: 1-20), could I just add code like this in at the end of the damage script?

Code:
if attacker.armor4_id = 100 and attacker.weapon_id <= 20

    self.damage *= 1.5

end

3. This one is more tricky. Gando's script increased the party XP by a certain amount, but I want to increase just one character's XP gain, not everyone. How would I go about editing the script here to include skill and/or equipment bonuses?

XP:
Code:
    # Obtaining EXP

    for i in 0...$game_party.actors.size

      actor = $game_party.actors[i]

      if actor.cant_get_exp? == false

        last_level = actor.level

        actor.exp += exp

        if actor.level > last_level

          @status_window.level_up(i)

        end

      end

    end

 
Gold:
Code:
        gold += enemy.gold

Again, thank you for any help you can provide. I'm really wanting to learn how to define skills and equipment in the code so I can do this stuff on my own.
 
To 1: It would basically work (if you fix spelling errors like 'eslif' ;) ), but is horribly unflexible. For a system with 10 weapons, this would be alright - for a system with 50, you'd already go into performance and lazyness regions you'd rather not be in.
Instead, try to find a way around. Since you're working with XP, you sadly can't use my Database Flag Reader, which would be perfect for your cause... (if you still want to check it out, it's in my signature) that means you have to find another way. One would be to find a field not required, for example 'hp increase' (don't know if weapons have it). Now, just do this:
Code:
crit = $data_weapons[attacker.weapon_id].hp_increase # set critical chance
It won't look awesome, but the only thing wrong with it is the name - you get perfect functionality with perfect database linkage. Plus you can do skills pretty much the same way.

Another popular approach is by going the element_id way. Problem with this is that you can only pass boolean values, so you'd have to create elements for set_crit_to_3, set_crit_to_5, and so on... which is bullshit, since you need to include every single one of that in the script again. If it's just 'double critical - yes or no', then it's a valid choice, though, considering you don't have the option to go the VX way and using notes.

To 2: In a conditional, you have to use == instead of =. Aside from that, it's functional (however again, not very flexible, as everything's hardcoded).

To 3:
Code:
   # Obtaining EXP

    for i in 0...$game_party.actors.size

      actor = $game_party.actors[i]

      unless actor.cant_get_exp? # made better

        last_level = actor.level

 

        # this is where your stuff needs to go, i.e.

        exp *= 3 if actor.weapon_id == 1

 

        actor.exp += exp

        if actor.level > last_level

          @status_window.level_up(i)

        end

      end

    end
 
Thanks BlueScope, that definitely helps.

I like the idea of using the stat increases to create new variables with database linkage. There isn't an hp.increase, but there is magic defense. Also, I want to create different speeds (using an ACB similar to FF6/7/etc.) and combo chances for different weapon types, so I think your method would be perfect for that. As far as the amount of weapons, most would be standard. I have over 100 weapons and probably only a dozen that would have unique affects, so I think hard coding will suffice.

What about passive skills? Say, if actor 1 knows skill 1, then increase damage by X. I'm completely clueless on the syntax for this. Also, I want it just for the character with the skill, not the entire party.
 

Atoa

Member

I don't remember any method to check if actor has an skill, but you can access the public variable "@skill" from game battler. it stores de the IDs of the actors skill.
actor.skills.include?(X)
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top