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.

I need help with working with a spefifc varible operation

I'm working on a skill that's adds a 1% for every 24th of the target's maxhp knocked off, and so the percentage for something to happen. How do I do the part where it divides the value (that's what I think I'm supposed to do), and the conditonal branch to check for every 24th knocked off?
 
You can do this with scripting fairly easily, you should be able to this with variables in the event command aswell by using an extra variable to keep track of hp, then checking when the hp changed from the variable, then adding the 1%.

Rather than go into details, let me make sure I understand what you're trying to do first:
You have a variable that has a value 1 to 100 representing a probability.
Everytime an actor takes 1/24 of their max hp, this variable increases by 1.
Every so often, there is a chance equal to variable% something happens.

Questions
Does the losing 1/24 maxhp raises 1% happen for every actor, or just some of them?
If you lose 1/16 does the % go up 2 points, or just 1?
 
This should be fairly simple to do via scripting.

Go into the script editor and goto the Game_Enemy class.
At the top you'll see a bunch of attr_reader/attr_accessor's
At the bottom of this part, add attr_accessor :catch_offset.
Now, go into the initialize method and add in @catch_offset = 0.

Go to the Game_Battler3 tab.
Go to the attack_effect method and near the bottom you should see the block
Code:
if hit_result == true

   # State Removed by Shock

   remove_states_shock

   # Substract damage from HP

   self.hp -= self.damage

 
Dirctly above the self.hp -=self.damage line
add in
Code:
self.catch_offset += 1 if self.is_a?(Game_Enemy) and self.damage > self.maxhp/24

Go to the skill_effect method and towards the bottom you should see
Code:
# Substract damage from HP

last_hp = self.hp

self.hp -= self.damage

effective |= self.hp != last_hp

# State change

@state_changed = false
Right above this, add in
Code:
self.catch_offset += 1 if  self.is_a?(Game_Enemy) and self.damage > self.maxhp/24

Now, go into the item_effect method and directly beneath
Code:
self.damage = -recover_hp
add
Code:
self.catch_offset += 1 if  self.is_a?(Game_Enemy) and self.damage > self.maxhp/24

If you are using this as a variable in the sense of the event editor, then this is how you get it.
Suppose you are using a variable with id 20 for the monster with id 3.
Call a script an use
Code:
for i in $game_troop.enemies

$game_variables[20] += i.catch_offset if i.enemy_id == 3

end

As an alternative to my method above, you could do all of this by checking hp changes in Scene_Battle.

If a monster gets healed does it effect this at all?
A much simpler method would be to just use what percent the monsters hp are of their max, rather than the every time it lose 1/24th bit; just a suggestion:)

Finally, if you have any questions, please ask:)
 

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