• 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] Random Weather Move

155
Posts
10
Years
    • Seen Jun 11, 2021
    I'm trying to create a move that causes a random weather effect whenever it's used. However, when I try to use it in battle, it just skips the move completely.
    Code:
    class PokeBattle_Move_178 < PokeBattle_Move
      def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
        case @battle.weather
        when PBWeather::HEAVYRAIN
          @battle.pbDisplay(_INTL("There is no relief from this heavy rain!"))
          return -1
        when PBWeather::HARSHSUN
          @battle.pbDisplay(_INTL("The extremely harsh sunlight was not lessened at all!"))
          return -1
        when PBWeather::STRONGWINDS
          @battle.pbDisplay(_INTL("The mysterious air current blows on regardless!"))
          return -1
        [email protected](4)
      end
      
        case rnd
        when 0
          if PBWeather::RAINDANCE
            @battle.pbDisplay(_INTL("But it failed!"))
            return -1
          end
          pbShowAnimation(@id,attacker,nil,hitnum,alltargets,showanimation)
          @battle.weather=PBWeather::RAINDANCE
          @battle.weatherduration=5
          @battle.weatherduration=8 if attacker.hasWorkingItem(:DAMPROCK)
          @battle.pbCommonAnimation("Rain",nil,nil)
          @battle.pbDisplay(_INTL("It started to rain!"))
          return 0
        when 1
          if PBWeather::SUNNYDAY
            @battle.pbDisplay(_INTL("But it failed!"))
            return -1
          end
          pbShowAnimation(@id,attacker,nil,hitnum,alltargets,showanimation)
          @battle.weather=PBWeather::SUNNYDAY
          @battle.weatherduration=5
          @battle.weatherduration=8 if attacker.hasWorkingItem(:HEATROCK)
          @battle.pbCommonAnimation("Sunny",nil,nil)
          @battle.pbDisplay(_INTL("The sunlight turned harsh!"))      
    
          return 0
          
        when 2
          if PBWeather::SANDSTORM
            @battle.pbDisplay(_INTL("But it failed!"))
            return -1
          end
          pbShowAnimation(@id,attacker,nil,hitnum,alltargets,showanimation)
          @battle.weather=PBWeather::SANDSTORM
          @battle.weatherduration=5
          @battle.weatherduration=8 if attacker.hasWorkingItem(:SMOOTHROCK)
          @battle.pbCommonAnimation("Sandstorm",nil,nil)
          @battle.pbDisplay(_INTL("A sandstorm brewed!"))
          return 0
        when 3
          if PBWeather::HAIL
            @battle.pbDisplay(_INTL("But it failed!"))
            return -1
          end
          pbShowAnimation(@id,attacker,nil,hitnum,alltargets,showanimation)
          @battle.weather=PBWeather::HAIL
          @battle.weatherduration=5
          @battle.weatherduration=8 if attacker.hasWorkingItem(:ICYROCK)
          @battle.pbCommonAnimation("Hail",nil,nil)
          @battle.pbDisplay(_INTL("It started to hail!"))
          return 0
        end
        
        return true
      end
    end
    Did I enter something incorrectly?
     
    220
    Posts
    13
    Years
    • Seen Nov 29, 2021
    Well you have an "end" after rnd(4), which seems out of place.
    If you need to end cases, then it should still be before the random.
    If you don't need to do that, then it shouldn't be there at all.
     

    Ego13

    hollow_ego
    311
    Posts
    6
    Years
  • Try putting some extra lines in there (for debug purpose only) to wheter your code is being executed and if so how far.
    Just add
    Code:
    @battle.pbDisplay(_INTL("Check Point X"))
    in a few different spots.
    If you see these text messages in game you know the code is recognized. That helps pinpoint the problem.
     
    155
    Posts
    10
    Years
    • Seen Jun 11, 2021
    I just now tried that. It's not seeing the message at all.
    Code:
    class PokeBattle_Move_178 < PokeBattle_Move
      def pbEffect(attacker,opponent,hitnum=0,alltargets=nil,showanimation=true)
        case @battle.weather
        when PBWeather::HEAVYRAIN
          @battle.pbDisplay(_INTL("There is no relief from this heavy rain!"))
          return -1
        when PBWeather::HARSHSUN
          @battle.pbDisplay(_INTL("The extremely harsh sunlight was not lessened at all!"))
          return -1
        when PBWeather::STRONGWINDS
          @battle.pbDisplay(_INTL("The mysterious air current blows on regardless!"))
          return -1
      #end
        @battle.pbDisplay(_INTL("Check Point A"))
        [email protected](4)
        case rnd
        when 0
          if PBWeather::RAINDANCE
            @battle.pbDisplay(_INTL("But it failed!"))
            return -1
          end
          pbShowAnimation(@id,attacker,nil,hitnum,alltargets,showanimation)
          @battle.weather=PBWeather::RAINDANCE
          @battle.weatherduration=5
          @battle.weatherduration=8 if attacker.hasWorkingItem(:DAMPROCK)
          @battle.pbCommonAnimation("Rain",nil,nil)
          @battle.pbDisplay(_INTL("It started to rain!"))
          return 0
        when 1
          if PBWeather::SUNNYDAY
            @battle.pbDisplay(_INTL("But it failed!"))
            return -1
          end
          pbShowAnimation(@id,attacker,nil,hitnum,alltargets,showanimation)
          @battle.weather=PBWeather::SUNNYDAY
          @battle.weatherduration=5
          @battle.weatherduration=8 if attacker.hasWorkingItem(:HEATROCK)
          @battle.pbCommonAnimation("Sunny",nil,nil)
          @battle.pbDisplay(_INTL("The sunlight turned harsh!"))      
    
          return 0
          
        when 2
          if PBWeather::SANDSTORM
            @battle.pbDisplay(_INTL("But it failed!"))
            return -1
          end
          pbShowAnimation(@id,attacker,nil,hitnum,alltargets,showanimation)
          @battle.weather=PBWeather::SANDSTORM
          @battle.weatherduration=5
          @battle.weatherduration=8 if attacker.hasWorkingItem(:SMOOTHROCK)
          @battle.pbCommonAnimation("Sandstorm",nil,nil)
          @battle.pbDisplay(_INTL("A sandstorm brewed!"))
          return 0
        when 3
          if PBWeather::HAIL
            @battle.pbDisplay(_INTL("But it failed!"))
            return -1
          end
          pbShowAnimation(@id,attacker,nil,hitnum,alltargets,showanimation)
          @battle.weather=PBWeather::HAIL
          @battle.weatherduration=5
          @battle.weatherduration=8 if attacker.hasWorkingItem(:ICYROCK)
          @battle.pbCommonAnimation("Hail",nil,nil)
          @battle.pbDisplay(_INTL("It started to hail!"))
          return 0
        end
        end
        
        return true
      end
    end
     

    Ego13

    hollow_ego
    311
    Posts
    6
    Years
  • Why did you comment out the first end? Its needed to let the program know that the first case ends. Otherwise it will think that everything else belongs to the last when
     
    Back
    Top