RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
Help! Variables not increasing after battles! [RMXP]

0 Members and 1 Guest are viewing this topic.

**
Rep: +0/-0Level 66
RMRK Junior
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!


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: [Select]
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
« Last Edit: September 26, 2011, 10:40:26 AM by djskagnetti »