• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

[Scripting Question] Help needed for two New abilities in the works!

60
Posts
5
Years
Hey forums!

I've been working on a pair of abilities (partly for fun, partly to use for a game in the future), but I am not super confident in Ruby coding, and I was hoping to get some help with the scripts!

Ability 1: Verdure (Name under development a.k.a still bad)
Basically the idea is to have a terrain and a weather condition summoned on entry/on gaining this ability. I want the effects of drought and Grassy terrain for this ability particularly.
So far I have the basic idea jotted, and As of posting this I will be reading through the Basics of Ruby code to try and refine it.
Code:
#(PokeBattle_Battle)
if self.hasWorkingAbility(:VERDURE)
    @battle.terrain=PBTerrain(:GRASSYTERRAIN)
      @battle.terrainduration=-1
      @battle.pbCommonAnimation("GrassyTerrain",nil,nil)
    @battle.weather=PBWeather(:HARSHSUN)
      @battle.weatherduration=-1
      @battle.pbCommonAnimation("HarshSunlight",nil,nil)
    @battle.pbDisplay(_INTL("#{pbThis}'s Verdure has caused Harsh Sunlight and Grassy Terrain!"))
    PBDebug.log([Ability triggered]"#{pbThis}'s Verdure")
end
#===========================================================

#This below is the code for Primordialweather Harsh Sun, which will be the base for verdure..sort of

when PBWeather::HARSHSUN
    for i in 0...4
      if isConst?(@battlers[i].ability,PBAbilities,:VERDURE) &&
         !@battlers[i].fainted?
        hasabil=true; break
      end
      if !hasabil
        @weather=0
        pbDisplayBrief("The harsh sunlight faded!")
      end
    end

Sorry if it is painfully filled with errors, as I say I am fairly new to this and I am still working on it! :)

The second ability is Tetratox:
The idea is to accelerate the effects of bad poisoning when the Pokemon is hit with a contact move by the owner of this ability

I only just started this, so it's unfinished, but the basic gist, again is here.

Code:
if hasWorkingAbility(:TETRATOX) && onContact
    for 1 in 0...4
        if pbIsOpposing?(self) && [email protected][self].feinted && @battle.battlers[self].pbstatus(:POISON){
            oncontact{
                @battle.battler[self].pbstatus(:POISON) dmglevel=+1
                PBDebug.log([Ability triggered]"#{pbThis}'s Tetratox Accellerated the poisoning!")
            }
        else
            #physical move poisons the target or, if they are poisoned, it accelerates it, making it badly poisoned
        end
    end
end

Again, I really apologise for the poor structure and lack of completion, but I am working on it and I wanted to run the code by some pro's to get some assistance!
 
285
Posts
5
Years
  • Age 21
  • Seen Oct 1, 2023
Hey forums!

I've been working on a pair of abilities (partly for fun, partly to use for a game in the future), but I am not super confident in Ruby coding, and I was hoping to get some help with the scripts!

Ability 1: Verdure (Name under development a.k.a still bad)
Basically the idea is to have a terrain and a weather condition summoned on entry/on gaining this ability. I want the effects of drought and Grassy terrain for this ability particularly.
So far I have the basic idea jotted, and As of posting this I will be reading through the Basics of Ruby code to try and refine it.
Code:
#(PokeBattle_Battle)
if self.hasWorkingAbility(:VERDURE)
    @battle.terrain=PBTerrain(:GRASSYTERRAIN)
      @battle.terrainduration=-1
      @battle.pbCommonAnimation("GrassyTerrain",nil,nil)
    @battle.weather=PBWeather(:HARSHSUN)
      @battle.weatherduration=-1
      @battle.pbCommonAnimation("HarshSunlight",nil,nil)
    @battle.pbDisplay(_INTL("#{pbThis}'s Verdure has caused Harsh Sunlight and Grassy Terrain!"))
    PBDebug.log([Ability triggered]"#{pbThis}'s Verdure")
end
#===========================================================

#This below is the code for Primordialweather Harsh Sun, which will be the base for verdure..sort of

when PBWeather::HARSHSUN
    for i in 0...4
      if isConst?(@battlers[i].ability,PBAbilities,:VERDURE) &&
         !@battlers[i].fainted?
        hasabil=true; break
      end
      if !hasabil
        @weather=0
        pbDisplayBrief("The harsh sunlight faded!")
      end
    end

Sorry if it is painfully filled with errors, as I say I am fairly new to this and I am still working on it! :)

The second ability is Tetratox:
The idea is to accelerate the effects of bad poisoning when the Pokemon is hit with a contact move by the owner of this ability

I only just started this, so it's unfinished, but the basic gist, again is here.

Code:
if hasWorkingAbility(:TETRATOX) && onContact
    for 1 in 0...4
        if pbIsOpposing?(self) && [email protected][self].feinted && @battle.battlers[self].pbstatus(:POISON){
            oncontact{
                @battle.battler[self].pbstatus(:POISON) dmglevel=+1
                PBDebug.log([Ability triggered]"#{pbThis}'s Tetratox Accellerated the poisoning!")
            }
        else
            #physical move poisons the target or, if they are poisoned, it accelerates it, making it badly poisoned
        end
    end
end

Again, I really apologise for the poor structure and lack of completion, but I am working on it and I wanted to run the code by some pro's to get some assistance!

For the first ability, I think it can be a bit more simple because the abilities Drought and Grassy Surge already exist, and this ability is basically a combination of the two if I understand correctly. (Also, you used the weather condition HARSHSUN, which I believe is actually used for desolate land. Regular sunlight is SUNNYDAY.) I would recommend finding this line in Pokebattle_Battler: 'if self.hasWorkingAbility(:DROUGHT) && (@battle.weather!=PBWeather::SUNNYDAY || @battle.weatherduration!=-1)' and replacing it with
'if (self.hasWorkingAbility(:DROUGHT) || self.hasWorkingAbility(:VERDURE)) && (@battle.weather!=PBWeather::SUNNYDAY || @battle.weatherduration!=-1)'. This will set up sunlight when entering battle. You can do a similar thing if you already have Grassy Surge implemented. If not, paste the following code above Primordial Sea:
Code:
    if isConst?(ability,PBAbilities,:VERDURE) && @battle.field.effects[PBEffects::GrassyTerrain] == 0
      @battle.field.effects[PBEffects::ElectricTerrain]=0
      @battle.field.effects[PBEffects::MistyTerrain]=0
      @battle.field.effects[PBEffects::PsychicTerrain]=0
      @battle.field.effects[PBEffects::GrassyTerrain]=5
      @battle.pbCommonAnimation("GrassyTerrain",nil,nil)
      @battle.pbDisplay(_INTL("The terrain became grassy!"))
    end

For the second one, I would recommend pasting this code under the code for Poison Touch in Pokebattle_Battler (I didn't test this out and just pretty much copied it from the end of turn addition to the number of turns with toxic):
Code:
        if user.hasWorkingAbility(:TETRATOX,true) && target.status==PBStatuses::POISON &&
           i.statusCount>0
          i.effects[PBEffects::Toxic]+=1
          i.effects[PBEffects::Toxic]=[15,i.effects[PBEffects::Toxic]].min
        end
 
143
Posts
4
Years
  • Age 22
  • Seen Mar 26, 2024
Hey there,
I am no expert on coding but I'd say the first ability looks as if it would work out as intended. Are you sure though that you don't want to put a turn limit on the Grassy Terrain? How it currently is the Grassy Terrain will stay active for the rest of the battle because the terrain timer won't tick down if it is at -1.
Code:
@battle.terrainduration=-1
It needs to be a positive number to tick down and eventually fade.

For the second ability I just remade it. It should now do the following:
- If the target isn't poisoned it gets poisoned (Right now the poison chance is 100% but you can alter that with the commented line in this script, it determines the chance for a poison to happen in this example 30% but that's up to you to decide)
-If the target is poisoned but not badly it gets poisoned badly
-Otherwise it increases Toxic damage by one stage

Put this code Inside "def pbEffectsOnDealingDamage(move,user,target,damage)"
below Weakarmor's code.
Spoiler:


If I made any mistakes or you have problems understanding anything or need additional help feel free to answer me. :)
 
143
Posts
4
Years
  • Age 22
  • Seen Mar 26, 2024
Hey there,
I am no expert on coding but I'd say the first ability looks as if it should work like silverlime explained it.
For the first ability, I think it can be a bit more simple because the abilities Drought and Grassy Surge already exist, and this ability is basically a combination of the two if I understand correctly. (Also, you used the weather condition HARSHSUN, which I believe is actually used for desolate land. Regular sunlight is SUNNYDAY.) I would recommend finding this line in Pokebattle_Battler: 'if self.hasWorkingAbility(:DROUGHT) && (@battle.weather!=PBWeather:: SUNNYDAY || @battle.weatherduration!=-1)' and replacing it with
'if (self.hasWorkingAbility(:DROUGHT) || self.hasWorkingAbility(:VERDURE)) && (@battle.weather!=PBWeather:: SUNNYDAY || @battle.weatherduration!=-1)'. This will set up sunlight when entering battle. You can do a similar thing if you already have Grassy Surge implemented. If not, paste the following code above Primordial Sea:
if isConst?(ability,PBAbilities,:VERDURE) && @battle.field.effects[PBEffects::GrassyTerrain] == 0
@battle.field.effects[PBEffects::ElectricTerrain]=0
@battle.field.effects[PBEffects::MistyTerrain]=0
@battle.field.effects[PBEffects::PsychicTerrain]=0
@battle.field.effects[PBEffects::GrassyTerrain]=5
@battle.pbCommonAnimation("GrassyTerrain",nil,nil)
@battle.pbDisplay(_INTL("The terrain became grassy!"))
end
Are you sure though that you don't want to put a turn limit on the Grassy Terrain? How it currently is the Grassy Terrain will stay active for the rest of the battle because the terrain timer won't tick down if it is at -1.
Code:
@battle.terrainduration=-1
It needs to be a positive number to tick down and eventually fade.

For the second ability I just remade it. It should now do the following:
- If the target isn't poisoned it gets poisoned (Right now the poison chance is 100% but you can alter that with the commented line in this script, it determines the chance for a poison to happen in this example 30% but that's up to you to decide)
-If the target is poisoned but not badly it gets poisoned badly
-Otherwise it increases Toxic damage by one stage

Put this code Inside "def pbEffectsOnDealingDamage(move,user,target,damage)"
below Weakarmor's code.
Spoiler:


If I made any mistakes or you have problems understanding anything or need additional help feel free to answer me. :)
 
143
Posts
4
Years
  • Age 22
  • Seen Mar 26, 2024
For Tetratox maybe something like this?
This ability does the following:
-If the target isn't poisoned it poisons it
-if the target is poisoned but not badly it gets poisoned badly
-otherwise the toxic counter is raised one level
Just insert this inside "def pbEffectsOnDealingDamage(move,user,target,damage)"
below the Poison Touch function.
Spoiler:
 
60
Posts
5
Years
Whoa! That looks about perfect! I'll put that into the script today and see if it works out well, and i'll be sure to post a screenshot as well!

I do have a question for you both however:

What is each part of the code doing, 'cause it's all well and good for me to just get given the code, but I want to understand what it does to improve my own ability in the future
 
143
Posts
4
Years
  • Age 22
  • Seen Mar 26, 2024
Glad you liked it!
I don't know exactly how good your Ruby or programming knowledge in general is but here is a guide to get you started if you want to be able to do those things yourself.
https://www.pokecommunity.com/showthread.php?t=410026

Now for my example:
Spoiler:

I hope this helped and don't be scared to ask more questions! :)
 
60
Posts
5
Years
Awesome! I did get what it was doing for the most part, but honestly My inability to code my own stuff without errors mostly comes from inexperience. I'm not confident with this yet. I recognize some part not too different from other coding languages I have used before, but as I said, I'm not too confident and that is why I wanted you guys to explain the code. Since you guys know more about it and are confident in using it, hope to gain more from hearing how your, uh process (Dunno if that's the right word but whatever!) flows when you make these scripts! Again, I'll put these into the scripts today sometime and be sure to screenshot it!

Thanks for the explanation and the help, it was really helpful!
 
285
Posts
5
Years
  • Age 21
  • Seen Oct 1, 2023
Whoa! That looks about perfect! I'll put that into the script today and see if it works out well, and i'll be sure to post a screenshot as well!

I do have a question for you both however:

What is each part of the code doing, 'cause it's all well and good for me to just get given the code, but I want to understand what it does to improve my own ability in the future
I think Turn20Negate did a good job explaining specifically what each line of code does and many of the methods he/she covered are similar to the ones I used, but I hope that this will help more with the overall implementation of any new moves/abilities so that making new ones in the future is easier. My strategy for adding new moves/abilities/items is to look for existing ones that have similar qualities to the ones that I want to implement and just adapting them to mimic those existing ones (use [Ctrl] + [Shift] + [F] to look for a piece of code in all scripts in the script editor and [Ctrl] + [F] to find a piece of code in the current script). This does, however, require you to know what all (or most) of the abilities and moves do so you know which ones to look for. I am also new to ruby and only had knowledge of programming in Java because that's what I learned in school, but I found that many things work similarly and just needed to adapt the syntax. I kind of follow the same formula for making all my new moves/abilities and find this to be effective:

Moves are more simple because all of the function codes are taken care of in the same script (Pokebattle_MoveEffects) with little need to go to other scripts (technically you should also use Pokebattle_AI but new moves will function without this). I usually just copy parts from existing move effects and combine them to make the effect I want.

For abilities, it is often a bit more complicated, and I tend to first find an ability or something else that has a similar effect to the one I want to implement (in the case with Tetratox, the end-of-round toxic damage increase). For more complex abilities, I sometimes find multiple that will be able to produce a similar effect to the one I want to implement when they are combined. I then find an ability or something else that activates at the same time that I want the ability to activate (with Tetratox, it activates upon making contact just like Poison Touch). Then, I paste the ability or whatever else that has a similar effect to the one I'm implementing above or underneath the ability or whatever else that activates at the same time I want the new ability to activate. Then, I change the pasted effect so that it does what I want. There are like 5 different scripts you'll need to be familiar with: Pokebattle_Battler (this basically is for the Pokemon in battle and deals with all their attributes), Pokebattle_BattlerEffects (this deals with effects on Pokemon in battle such as status conditions and stat increases/reduction), Pokebattle_Move (this deals with moves that Pokemon in battle are using and what modifies them), Pokebattle_Battle (you'll often use this for effects that apply at the end of a round), and Pokebattle_AI (this deals with decisions that the AI will make, which is not technically required, but is good to use when defining new abilities).

Also make sure that you use the correct variables when calling methods because when you're calling methods on battlers. The scripts have many different ways of addressing them (they often use user, target, opponent, attacker, or even i, and it's important to know which ones to use because I've gotten many errors from sloppily pasting code and not realizing that they changed the variable names in different methods).
 
Last edited:
60
Posts
5
Years
OH man!! That really helps. That's kinda how I imagined I should be going about it, but particularly the part where you explained the Pokebattle_Battler, Pokebattle_BattlerEffects, Pokebattle_Move, PokeBattle_battle and Pokebattle_AI. One of the big issues I had was trying to figure out what each did and where to put my code! That really helps me out! Thank you
 
60
Posts
5
Years
WOOOHOOO! Thanks guys, the Tetratox ability worked perfectly!
Screenshot (30).png
Screenshot (31).png

I did have an issue with verdure though. My game does not have Grassy terrain yet, so I used the section you described above primordial sea, but it complained that there was an uninitialized constant (Psychic terrain) that prevented it from activating on entry correctly. The battle will start, but after I send out my pokemon, the error occurs/causes a crash.

Screenshot (32).png
Screenshot (33).png

any suggestions considering you are the people who came up with the code for this?
 
60
Posts
5
Years
I discovered that specifically the line
Code:
@battle.field.effects[PBEffects::PsychicTerrain]=0
was causing issues, and when commented out, the ability works correctly. Should I be checking for any sort of PBS issues or maybe some error in th ecode that initialises the pokemon on-entry?
 
285
Posts
5
Years
  • Age 21
  • Seen Oct 1, 2023
I discovered that specifically the line
Code:
@battle.field.effects[PBEffects::PsychicTerrain]=0
was causing issues, and when commented out, the ability works correctly. Should I be checking for any sort of PBS issues or maybe some error in th ecode that initialises the pokemon on-entry?

Did you mean that your game does not have Psychic Terrain yet? If it doesn't, then you should be fine commenting out or deleting that line (you'll need it later if you choose to add Psychic Terrain to your game). I kind of just assumed that you had Psychic Terrain implemented already.
 
60
Posts
5
Years
Yeah, I went through and found that, despite having the other terrains, I have not yet added Psychic terrain. not up to implementing Gen 7, just yet! :)
Thanks again. I'll get to adding Gen7 now that I at least have added gen 6 and EBS!
thanks!
 
60
Posts
5
Years
I ran into another issue, actually with my following Pokemon. As I was adding it, i found that it works, but only with the first Pokemon in my party when I trigger the event. at least, visually. However any other party members, if I switch them to the front, they are still technically there, but their character does not display..

I also was wondering about the placement of abilities that trigger during the battle. Say I wanted an ability that triggers at half my Pokemon's hp, and it was a stat being raised, would I put it into the Pokebattle_BattlerEffects? if so what can i look for to know what line of code it can be put in?

Thanks, and sorry for all the questions! On the positive, I've completely finished adding EBS and Gen6.
 
285
Posts
5
Years
  • Age 21
  • Seen Oct 1, 2023
I ran into another issue, actually with my following Pokemon. As I was adding it, i found that it works, but only with the first Pokemon in my party when I trigger the event. at least, visually. However any other party members, if I switch them to the front, they are still technically there, but their character does not display..

I also was wondering about the placement of abilities that trigger during the battle. Say I wanted an ability that triggers at half my Pokemon's hp, and it was a stat being raised, would I put it into the Pokebattle_BattlerEffects? if so what can i look for to know what line of code it can be put in?

Thanks, and sorry for all the questions! On the positive, I've completely finished adding EBS and Gen6.

I'm not using the following Pokemon script, but I can help you with the ability. Pokebattle_BatterEffects deals mostly with general cases of status conditions and stat increases/decreases, and the methods in it are mostly for applying status conditions or stat modifications. These methods are usually called from other scripts instead of editing that script itself. You would probably want to put the code in the 'pbEffectsOnDealingDamage' method of Pokebattle_Battler under 'if !target.damagestate.substitute && damage>0'. Then I would recommend using this line to check if the ability should activate (I assume you're talking about Berserk):
'if target.hasWorkingAbility(:BERSERK) && target.hp+damage>target.totalhp/2 && target.hp<target.totalhp/2'

This should be all you need to do for Berserk. Doing only this will make it so the ability will only trigger when an attack makes the Pokemon's HP drop below half, but if you wanted the ability to activate from poison damage, burn damage, aftermath damage, etc. then you might want to instead include the code in 'def pbReduceHPDamage' in Pokebattle_Move and
'def pbReduceHP' in Pokebattle_Battler.
 
60
Posts
5
Years
Found a line similar to the one you were talking about, but it's not quite the same. It is :
if damage>0
if !target.damagestate.substitute
...
Yeah Berserk is great, But i was working on an Ability I came up with that boosts speed at half hp.
thank you for also helping me by writing how I can, well, write totalhp/2. I assume it doesn't matter if it says 'target, since it is only counting whether the target has the ability or not and doesn't care if it is the opponent or my stuff

Thank you again. It seems the real practice I need to do is understand where to put my code in! :)
 
Back
Top