1. GET SMOGON SHIRTS HERE! First time ever. Limited time only & next time the design will be different, so get it while you can!
  2. New to the forums? Check out our Mentorship Program!
    Our mentors will answer your questions and help you become a part of the community!
  3. Welcome to Smogon Forums! Please take a minute to read the rules.

PO Server JavaScript Help

Discussion in 'Pokemon Online' started by Exclamation!, Aug 7, 2012.

  1. Exclamation!

    Exclamation!

    Joined:
    Dec 21, 2010
    Messages:
    201
    Hi there! I'm currently in the process of starting a PO server with a bunch of people from another forum. We have got the tiers down, and the server's header is almost complete. Everything is pretty much done, besides scripting. However, none of us really knows JS that well, so I was wondering if someone with some knowledge on Javascript programming could take a look at the script we currently have written and answer a (few?) question(s).

    The way PO works now, complex bans (read: Drizzle+Swift Swim) have to be enforced through scripting. We have wrote the code for that, and the server's control pannel script check does not find any errors in the code. However, when selecting a tier where Drizzle+SS is banned, while using a team that contains the said ability combination, the server simply allows it, and no warning message pops up. I'm going to paste the code below, and would really appreciate it if someone could point out what is wrong.

    Code:
    ({ afterLogIn : function(source) {
      sys.sendMessage(source, "PkF Bot: Olá, " + sys.name(source) + "! Bem-vindo! Diverte-te no nosso server, e não te esqueças de dar uma vista de olhos aos fórums em http://www.pokeforum-pt.com! Não te esqueças que o server ainda se encontra em fase de testes");
     }
     })
     
    
     function drizzleswimcheck (src){ 
      var tier = sys.tier(src)
      if (["Wi-Fi/Standard UU", "Wi-Fi/Standard OU", "DW OU", "Wi-Fi/Standard RU", "Wi-Fi/Standard NU"].indexOf(tier) == -1) return false;
      var hasdrizzle = false;
      var hasswiftswim = false;
      var drizzle = sys.abilityNum("Drizzle")
      var swiftswim = sys.abilityNum("Swift Swim")
      for (var s=0; s<6; s++) {
       if (sys.teamPokeAbility(src, s) == drizzle) {
         hasdrizzle = true;
       }
       if (sys.teamPokeAbility(src, s) == swiftswim) {
         hasswiftswim = true;
       }
      }
      if (hasdrizzle && hasswiftswim) {
       sys.sendMessage(src, 'A tua team é inválida em '+tier+' pois a combinação de Drizzle e Swift Swim na mesma equipa encontra-se banida.');
       sys.changeTier(src, "Street PKMN")
       return true;
      }
      else {
       return false;
      }
     }
    
  2. Antar

    Antar Self-anointed Czar of LC UU
    is a Battle Server Administratoris a Programmeris a Super Moderatoris a Community Contributor
    Official Data Miner

    Joined:
    Feb 17, 2010
    Messages:
    3,168
    Hi, Exclamation!

    In general, you'll have more luck posting these questions over in the PO forums.

    You can also check out Smogon's scripts and modify them to suit your purposes.


    Regarding your actual question, I don't see anything wrong with your function, but where are you calling it? Just defining the function doesn't do anything. You have to call it from afterChangeTeam and beforeChangeTier.
  3. Exclamation!

    Exclamation!

    Joined:
    Dec 21, 2010
    Messages:
    201
    Thanks a lot for your help, Antar. So, basically, to call a function after a specific action I have to write "afterAction : function", right? And, logically, to call it before I'd have to do the same but with the word "before" replacing "after", right? But how am I able to do both? To call the fuction after and before two specific actions? Please keep in mind I am a total newcomer when it comes to coding, be it JavaScript or anything else.
  4. Antar

    Antar Self-anointed Czar of LC UU
    is a Battle Server Administratoris a Programmeris a Super Moderatoris a Community Contributor
    Official Data Miner

    Joined:
    Feb 17, 2010
    Messages:
    3,168
    Exclamation!, look at how it's done in the Smogon scripts I linked.

    But basically, swiftSwimCheck is a stand-alone script, and then you have:

    Code:
    function beforeChangeTier(playerId, oldTier, newTier) {
      swiftSwimCheck(playerId, newTier);
      droughtCheck(playerId, newTier);
      SmashPassBan(playerId,newTier);
      LightingRodPika(playerId,sys.tier(playerId));
      RS200(playerId,newTier);
      monotypecheck(playerId,newTier);
      AdvIngrainSmeargleBan(playerId,newTier);
      eventNatureCheck(playerId);
      /*
      if (!hasValidTier(playerId, newTier)) {
        sys.stopEvent();
        announce(playerId, "You cannot switch to this tier.");
      }
      */
    }
  5. Exclamation!

    Exclamation!

    Joined:
    Dec 21, 2010
    Messages:
    201
    I finally got it to work. Thanks, Antar!

Users Viewing Thread (Users: 0, Guests: 0)