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.

Help with an AP Script?

Greetings!

I've taken the initiative and begun clumsily writing a script that will integrate an Ability Point system into the Battle System. The ability system is modeled after Chrono Trigger (in which it is called Tech Points), where characters earn Ability Points (AP) following battles in addition to EXP and GP. AP work almost identically to EXP but are used exclusively for the acquisition of skills: once a skill is learned, the "AP to next skill" is increased.

However, I've run into a small snag along the way.

Here's a snippet of my code. This is inserted into the Scene_Battle script and is modified based on Cogwheel's script.

Code:
    # AP Acquisition

      r = @troop_id

      ap_at_win = $monsterap[r]

    # 0 AP for enemies where nil is returned

      if ap_at_win == nil

        ap_at_win = exp/3

      end

    # Bonus Multiplier

      ap_multiplier = $game_variables [103]

      ap_at_win = ap_at_win*ap_multiplier

    # EXP Awarded

    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

        j = i + 1

        #j = i + 1                     

        h = 10                        # h = # of array values per character; 8 for skills, 1 for character id, 1 for number of skills learned

        $ap[j] += ap_at_win    

        for w in (1...h)         # A clumsy loop to repeatedly check to allow for learning multiple skills in a single battle.

          k = (h*i)                     # k is used to find the array value corresponding to the number of skills learned.

          m = k + 2 + $skillset[k].to_i # m = 2 m is used to find the array value corresponding to the AP needed to learn the next skill.

           if $skillset[k].to_i < 8  # A temporary loop that I included. 8 is the number of skills for each character in the array, but this can be changed to some variable so that characters can have a different quantity of skills to learn.

            if $ap[j] >= $skillap[m]       # If AP for character j is greater than the skill requirement, the character learns the next skill

              $ap[j] = $ap[j] - $skillap[m]   # Subtracting AP

              s = $skillset[m].to_i

              $skillset[k] += 1     # Number of skills learned + 1              

              actor.damage[[actor, 0]] = "New Skill!"

              actor.learn_skill(s)          # Teaches the new skill

            end

          end

        end

        if actor.level > last_level

          @status_window.level_up(i)

          actor.damage[[actor, -1]] = "Level up!"

          actor.up_level = actor.level - last_level

        end

      end

    end

The global arrays that are listed are defined in an auto-start event. This makes it easier to customize, because you don't have to edit the script to edit the traditionally customizable values. Here they are below:

Code:
$ap = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

# Character 1, 2, 3, 4, 5, 6, etc.

 

#NumberOfSkillsLearned, CharID, Skill 1, 2, 3, 

#4, 5, 6, 7, 8, repeat for character 2

$skillset = [0, 1, 1, 2, 3, 4, 5, 6, 

7, 8, 0, 2, 9, 10, 11, 12, 13, 14, 15, 

16, 0, 3, 17, 18, 19, 20, 21, 22, 23, 

24, 0, 4, 25, 26, 27, 28, 29, 30, 31, 

32]

 

#AP for level up. The positions deliberately correspond

#with the positions in $skillset so that for Aluxes

#to learn skill 1 (Heal), he has to earn 500 AP

$skillap = [0, 'Aluxes', 500, 2000, 5000, 

10000, 2000, 4000, 8000, 10000, 0, 

'Basil', 900, 900, 900, 900, 900, 900, 

900, 10000, 0, 'Cyrus', 100, 200, 300, 

400, 500, 600, 700, 800, 0, 'Dorothy', 200, 

400, 800, 1600, 3200, 6400, 12800, 

25600]

 

# AP Database for Monsters. 

#$monsterap[MonsterID] = APEarned

$monsterap = []

$monsterap[35] = 125

 

 

Now, the snag in my code is that this script awards AP to characters in a way differently than I intended. It assigns skills and AP values to the character based on their position in the current party rather than their ID in the actor database. Therefore, the script works if Aluxes and Basil are in the party (in that order), but it fails if Aluxes and Cyrus are in the party, because the script will begin teaching Cyrus the skills intended for Basil.

How can I instead award AP to party members only in the party but based on their ID in the database?

Thank you for any and all comments. :)
 
I know that the database ID is gotten from: $game_actors[ID]
I'm thinking maybe if you instead used: $game_party.actors[ID]
that that would find the order in the party...? I dunno... just a guess, anyway. I haven't tested it myself, because I can't think of a practical use for it yet. If it does work, please let me know, though.
 

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