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.

Please help! Variable's not increasing after battle.

can somebody please help me with this? for RMXP

I have a simple job system where you get xp and gold when you kill a set amount of a certain type of monster.

I have a variable for each type of monster.

I have, on the troop screen, When [monster]'s HP < 0 then [monster]'s variable increase +1. I have it set to Turn for the span.

I realized after a while that the Turn span is flawed, as it checks each turn, and, for every turn that that specific monster's hp is below 0, it adds +1. Which is great if it lasts only 1 turn after it dies. But if, say, it lasts 10 turns more as you kill the other monsters in it's group, you get +1 for every turn. So it registers as 10 kills.

So I tried this instead in the troop screen.
I added a conditional branch.
If self switch A is on
[do nothing]
Else
Increase [monster]'s variable +1
self switch A = on

So this seems to work for stopping it from counting 10 or whatever number of turns it is after it dies.

EDIT: ^^ The above conditional doesn't work after all. I guess self switches don't work in the troop window? because it's still registering for every turn it is dead, which, I assume, is because self switch A is not turning on and thus not triggering the conditional branch of A=on...

But, let's say I'm fighting 2 Goblins.
If I kill both in the same turn, ending the battle, it only registers 1.
If I use a skill that attacks all monsters at once, and it kills everything on the screen on the first turn, it doesn't register at all!

I tried setting it to moment and it froze the battle screen.
I tried setting it to battle and it only registers 1.


Please somebody help!
 
no they should. Your branch should look like this:

condition monster 1 is incapacitated
condition self switch a is off
add 1 to job var
switch a = on
EXIT EVENT PROCESSING
ELSE
EXIT EVENT PROCESSING
 
EDIT:

Thanks to ForeverZero for making me this script. This adds 1 to the variable at the end of battle to whatever enemy is specified, completely fixing all my problems! Thanks again ForeverZero!


"Place the script anywhere below Game_Enemy and fill out the simple configuration at the top of the script."

Code:
class Game_Enemy

 

#-------------------------------------------------------------------------------

# CONFIGURATION

#-------------------------------------------------------------------------------

#  Define the variable used for each enemy here. Follow this pattern:

#

#    when ENEMY_ID then VARIABLE_ID

#

#  If more than one eneky share the same variable, you can define multiple

#  IDs on one line. For example, say you had a Goblin whose ID was 1, and an

#  Orc whose ID was 17. You wanted both of them to be of the same "type", and

#  use the variable with ID of 6:

#

#     when 1, 17 then 6

#

#-------------------------------------------------------------------------------

 

  def enemy_variable(enemy_id)

    return case enemy_id

    when 1 then 1

    when 2 then 2

    when 3 then 3

    when 4 then 4

    when 5 then 5

    end

  end

 

#-------------------------------------------------------------------------------

# END CONFIGURATION

#-------------------------------------------------------------------------------

 

  def increase_count(enemy_id)

    var_id = enemy_variable(enemy_id)

    if var_id != nil

      $game_variables[var_id] += 1

    end

  end

 

  alias zer0_enemy_type_attack attack_effect

  def attack_effect(attacker)

    result = zer0_enemy_type_attack(attacker)

    if self.dead? && @counted == nil

      increase_count(@enemy_id)

      @counted = true

    end

    return result

  end

 

  alias zer0_enemy_type_skill skill_effect

  def skill_effect(user, skill)

    result = zer0_enemy_type_skill(user, skill)

    if self.dead? && @counted == nil

      increase_count(@enemy_id)

      @counted = true

    end

    return result

  end

 

  alias zer0_enemy_type_item item_effect

  def item_effect(item)

    result = zer0_enemy_type_item(item)

    if self.dead? && @counted == nil

      increase_count(@enemy_id)

      @counted = true

    end

    return result

  end

end
 

Eventing_Guy

Awesome Bro

It is Possible to do it through Eventing; but it involved about 8 switches, a lot of Variables, Conditional branches, & Common events.

Then you had to place the correct once in the Monster Group.

(a lot of WORK.)


LOL, but That Script simplifies what I was doing.

Even though I didn't do anything I am happy you found a solution. :biggrin:
 
Thanks for trying to help! I just playtested this script and it works flawlessly! You kill 2 monsters you get 2 increases, no matter when they are killed, how they are killed, or how many turns apart they are killed. Simple and effective!
 

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