Male
The Ozone Layer
Seen 3 Hours Ago
Posted 1 Day Ago
51 posts
1.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.
#(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) &&
         [email protected][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.

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!
Male
New York
Seen 3 Hours Ago
Posted 10 Hours Ago
67 posts
1.9 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.
#(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) &&
         [email protected][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.

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:
    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):
        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
Currently developing Pokemon Vengeance
Seen 3 Hours Ago
Posted 1 Week Ago
12 posts
110 Days
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.
@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 user.hasWorkingAbility(:TETRATOX) && !target.fainted? #&& @battle.pbRandom(10)<3 # uncomment this for a 30% chance for the whole thing to happen
          if target.status!=PBStatuses::POISON
            if target.pbCanPoison?(nil,false) #&& @battle.pbRandom(10)<3 # uncomment this for a 30% chance for the poisoning to happen
              target.pbPoison(nil,(_INTL("{1}'s Tetratox poisoned {2}!",user.pbThis,target.pbThis)),false)
            end
          elsif target.status==PBStatuses::POISON && target.statusCount==0
            target.statusCount=1
            @battle.pbDisplay(_INTL("{1}'s Tetratox amplified {2}'s poisoning!",user.pbThis,target.pbThis))
          elsif target.status==PBStatuses::POISON && target.statusCount==1
            target.effects[PBEffects::Toxic]+=1
            @battle.pbDisplay(_INTL("{1}'s Tetratox accelerated {2}'s poisoning!",user.pbThis,target.pbThis))
          end
        end


If I made any mistakes or you have problems understanding anything or need additional help feel free to answer me. :)
Seen 3 Hours Ago
Posted 1 Week Ago
12 posts
110 Days
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.
@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 user.hasWorkingAbility(:TETRATOX) && !target.fainted? #&& @battle.pbRandom(10)<3 # uncomment this for a 30% chance for the whole thing to happen
          if target.status!=PBStatuses::POISON
            if target.pbCanPoison?(nil,false) #&& @battle.pbRandom(10)<3 # uncomment this for a 30% chance for the poisoning to happen
              target.pbPoison(nil,(_INTL("{1}'s Tetratox poisoned {2}!",user.pbThis,target.pbThis)),false)
            end
          elsif target.status==PBStatuses::POISON && target.statusCount==0
            target.statusCount=1
            @battle.pbDisplay(_INTL("{1}'s Tetratox amplified {2}'s poisoning!",user.pbThis,target.pbThis))
          elsif target.status==PBStatuses::POISON && target.statusCount==1
            target.effects[PBEffects::Toxic]+=1
            @battle.pbDisplay(_INTL("{1}'s Tetratox accelerated {2}'s poisoning!",user.pbThis,target.pbThis))
          end
        end


If I made any mistakes or you have problems understanding anything or need additional help feel free to answer me. :)
Seen 3 Hours Ago
Posted 1 Week Ago
12 posts
110 Days
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:
#======Tetratox======#
        if user.hasWorkingAbility(:TETRATOX) && !target.fainted? #&& @battle.pbRandom(10)<3 # uncomment this part if you want a probability for the whole ability to happen
          if target.status!=PBStatuses::POISON
            if target.pbCanPoison?(nil,false) #&& @battle.pbRandom(10)<3 # uncomment this part if you want a probability for the poisoning to happen
              target.pbPoison(user,_INTL("{1}'s {2} poisoned {3}!",user.pbThis,PBAbilities.getName(user.ability),target.pbThis))
            end
          elsif target.status==PBStatuses::POISON && target.statusCount==0
            target.statusCount=1
            @battle.pbDisplay(_INTL("{1}'s {2} amplified {3}'s poisoning!",user.pbThis,PBAbilities.getName(user.ability),target.pbThis))
          elsif target.status==PBStatuses::POISON && target.statusCount!=0
            target.effects[PBEffects::Toxic]+=1
            @battle.pbDisplay(_INTL("{1}'s {2} accelerated {3}'s poisoning!",user.pbThis,PBAbilities.getName(user.ability),target.pbThis))
          end
        end
Male
The Ozone Layer
Seen 3 Hours Ago
Posted 1 Day Ago
51 posts
1.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
Seen 3 Hours Ago
Posted 1 Week Ago
12 posts
110 Days
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:
if user.hasWorkingAbility(:TETRATOX) && !target.fainted? #&& @battle.pbRandom(10)<3
This line checks wether the user has the ability Tetratox and if the target is still alive ("&&" means that both have to apply)("!" means no or the opposite)(The lasts part takes a random number between 1 and 9 and then checks if it's below 3(0,1 or 2) So it makes the thing happen 30% of the time)
if target.status!=PBStatuses::POISON
This line checks wether the target is poisoned
if target.pbCanPoison?(nil,false) #&& @battle.pbRandom(10)<3
This line checks if the target can be poisoned (If it's not Poison or Steel type etc.) it also doesn't display the usual "It doesn't affect..." message because of the "false" in the parentheses
target.pbPoison(user,_INTL("{1}'s {2} poisoned {3}!",user.pbThis,PBAbilities.getName(user.ability),target.pbThis))
This line poisons the target and displays a message in which the {}'s are replaced by the words listed at the end in numerical order.(ex. {1} is replaced by user.pbThis which is the holder of the ability.)
end
elsif target.status==PBStatuses::POISON && target.statusCount==0
When this line doesn't apply "if target.pbCanPoison?(nil,false) #&& @battle.pbRandom(10)<3" this lines checks if the target is poisoned and not badly poisoned(target.statusCount==0)
target.statusCount=1
If that is the case this line sets the status count to 1 which together with a normal poisoning translates to bad poisoning
@battle.pbDisplay(_INTL("{1}'s {2} amplified {3}'s poisoning!",user.pbThis,PBAbilities.getName(user.ability),target.pbThis))
This is just another message with the same formula
elsif target.status==PBStatuses::POISON && target.statusCount!=0
If the first and second cases don't apply this checks if the target is badly poisoned
target.effects[PBEffects::Toxic]+=1
This increases the toxic countdown by one stage
@battle.pbDisplay(_INTL("{1}'s {2} accelerated {3}'s poisoning!",user.pbThis,PBAbilities.getName(user.ability),target.pbThis))
This is just another message
end
end

I hope this helped and don't be scared to ask more questions! :)
Male
The Ozone Layer
Seen 3 Hours Ago
Posted 1 Day Ago
51 posts
1.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!
Always designing something new!
Male
New York
Seen 3 Hours Ago
Posted 10 Hours Ago
67 posts
1.9 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
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).
Currently developing Pokemon Vengeance
Male
The Ozone Layer
Seen 3 Hours Ago
Posted 1 Day Ago
51 posts
1.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
Always designing something new!
Male
The Ozone Layer
Seen 3 Hours Ago
Posted 1 Day Ago
51 posts
1.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?
Always designing something new!
Male
New York
Seen 3 Hours Ago
Posted 10 Hours Ago
67 posts
1.9 Years
I discovered that specifically the line
@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.
Currently developing Pokemon Vengeance
Male
The Ozone Layer
Seen 3 Hours Ago
Posted 1 Day Ago
51 posts
1.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.
Always designing something new!
Male
New York
Seen 3 Hours Ago
Posted 10 Hours Ago
67 posts
1.9 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.
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.
Currently developing Pokemon Vengeance
Male
The Ozone Layer
Seen 3 Hours Ago
Posted 1 Day Ago
51 posts
1.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! :)
Always designing something new!