PO Server JavaScript Help

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;
  }
 }
 
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.
 
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.
 
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.");
  }
  */
}
 

Users Who Are Viewing This Thread (Users: 1, Guests: 0)

Top