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.

Semi-Individualized Item Effects/Item Allergy

I'm currently attempting to write a script which can be used to check both an elements individual element property (eg. contains dairy) against the character ID to determine a semi-individualized item effects. I originally tried doing this with the pre-existing element_correct function, but that didn't work either. I'm a little new to this and very rusty when it comes to programming at all, so bear with me. Everything I'm editing is under game_battler 3. At the moment, the error is simply that healing items are working normally.

Calling the function:
Code:
      if allergy_control(item.element_set) == 1
        self.hp == 1
      end
      if allergy_control(item.element_set) == 0
        self.damage = -recover_hp
      end
Here, I modified the pre-existing self.damage = -recover_hp function to try to detect the item's element and give it an additional function after the element_control function has already been used (and thus should be independent of it).

Lookup/determiner function
Code:
def allergy_control(element_set)
      if element_set == [19] and self.id == 1 
        return 1 #Has allergy
      end
      if element_set == [22] and self.id == 3
        return 1 #Has allergy
      end
      if element_set == [20] and self.id == 5
        return 1 #Has allergy
      end
      if element_set == [18] and self.id == 6
        return 1 #Has allergy
      end
      if element_set == [21] and self.id == 7
        return 1 #Has allergy
      end
      return 0
end
tried modeling this after the element_correct function, but have obviously failed somewhere. Probably some noob mistake. Any help would be appreciated1
 
Hmm...
Code:
if element_set == [19]
That would only return true if element 19 was the only element that item had.

Try using these:
Code:
      if allergy_control(item.element_set)
        self.hp == 1
      else
        self.damage = -recover_hp
      end

And:
Code:
def allergy_control(element_set)
      if element_set.include?(19) and self.id == 1 
        return true #Has allergy
      end
      if element_set.include?(22) and self.id == 3
        return true #Has allergy
      end
      if element_set.include?(20) and self.id == 5
        return true #Has allergy
      end
      if element_set.include?(18) and self.id == 6
        return true #Has allergy
      end
      if element_set.include?(21) and self.id == 7
        return true #Has allergy
      end
      return false
end
 
Thanks for the help! I had to edit just a little bit more to get it to work properly, but here it is if anyone who wants to use it for any reason. Thanks again, Fomar0153!

About:
This will invert recovery functions based on the character ID and the element ID of the item. In other words, you can have certain characters that will hurt some characters while healing others based on those functions.

Instructions:
Add all of this to game_battler 3. The first bit of code should replace some of the pre-existing code (starts at around line 259 if you are using unedited game_battler 3 script). The last bit of code I put just before the final end, but that may or may not matter. Make sure to change the appropriate element and character (self) ids to whatever they are in your game!

The function to call/handle an allergy.
Code:
     if allergy_control(item.element_set)
        self.damage = recover_hp
        # HP and SP recovery
        last_hp = self.hp
        last_sp = self.sp
        self.hp -= recover_hp
        self.sp -= recover_sp
        effective |= self.hp != last_hp
        effective |= self.sp != last_sp
      else
        self.damage = -recover_hp
        # HP and SP recovery
        last_hp = self.hp
        last_sp = self.sp
        self.hp += recover_hp
        self.sp += recover_sp
        effective |= self.hp != last_hp
        effective |= self.sp != last_sp
      end

... and the control function, to determine if the character is allergic.
Code:
  def allergy_control(element_set)
      if element_set.include?(19) and self.id == 1 
        return true #Has allergy
      end
      if element_set.include?(22) and self.id == 3
        return true #Has allergy
      end
      if element_set.include?(20) and self.id == 5
        return true #Has allergy
      end
      if element_set.include?(18) and self.id == 6
        return true #Has allergy
      end
      if element_set.include?(21) and self.id == 7
        return true #Has allergy
      end
      return false
  end
 

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