Skip to content

Client Script Functions

Garma edited this page Jul 14, 2013 · 32 revisions

Scripting/Client/Functions

Utility

  • timerID = sys.setTimer(call, time, repeats) Calls the code in call after time milliseconds. If repeats is true then this call repeats itself until unset. Gives a timerID that can be used to unset the timer.
  • sys.unsetTimer(timerID) Cancels a timer function
  • sys.unsetAllTimers() Cancels all timers. Good for dealing with buggy scripts sometimes.
  • sys.sha1(toHash) returns the sha1 hash of the string
  • sys.md4(toHash) returns the md4 hash of the string (not recommended)
  • sys.md5(toHash) returns the md5 hash of the string
  • sys.changeScript(newScript, triggerStartUp) changes the script with the content. Can be used with webCall or getFileContent to do cool stuff. If optional triggerStartUp is true clientStartUp event will be triggered after loading a new script. This function can also be used in combination with sys.scriptsFolder (explained below) to build a reload command for your client scripts: sys.changeScript(sys.scriptsFolder + 'scripts.js', true);
  • sys.changeBattleScript(newScript) changes battlescripts with the content given in newScript. Can also used with sys.scriptsFolder to build a reload command. The battlescripts filename is 'battlescripts.js'.
  • sys.os() Client OS name ('windows', 'mac', 'linux')
  • sys.eval(script) Runs the script given in parameter. Returns the result.
  • sys.stopEvent() if called before an event occurs, if possible, stop the events from happening. If called in an event that starts by "before", stops the event from happenning. For example stops your messages being sent in the beforeSendMessage event or stops another player's from been displayed through the beforeChannelMessage event.
  • sys.scriptsFolder Returns the absolute path to the client scripts folder (for example /home/your_name/.local/share/Dreambelievers/Pokemon-Online/Scripts/ on linux). scriptsFolder is a property of the sys object and NOT a function
  • sys.version() Returns the client's version (for example: 2.0.22)

Helpers

  • sys.htmlEscape(string) Escapes HTML
  • sys.isSafeScripts() Whether the script is using safe scripts.
  • sys.showingWarnings() Whether the script is showing warnings.
  • sys.rand(min, max) Returns an integer value between min (inclusive) and max (exclusive).
  • sys.time() Returns the number of seconds since 1 Jan 1070.
  • sys.validColor(color) determines whether color is a valid hexadecimal string (eg #123456 is valid, #5Y6789 is not) or color name (such as 'green').
  • sys.hexColor(color) Converts a color (such as 'red') into a hexadecimal color.

File I/O

  • sys.writeToFile(filename, content) Writes content to the file at filename. Will remove any existing content.
  • sys.appendToFile(filename, content) Appends content to the end of the file at filname.
  • sys.readFile(filename) Returns the content of the file at filename.
  • sys.saveVal(key, value) Stores value to the data.ini file with key.
  • sys.getVal(key) Returns the value of key in the data.ini file.
  • sys.removeVal(key) Removes the value of key in the data.ini file.
  • sys.getValKeys() Returns the keys stored in the in the data.ini file.
  • sys.getRegVal(key) Returns the value of key in the registry.
  • sys.removeRegVal(key) Removes the value of key in the registry.
  • sys.getRegKeys() Returns the keys stored in the in the registry.
  • sys.zip(file, dir) Puts all the files (not any directories though...) from directory dir into a zipfile named file.
  • sys.extractZip(file, dir) Extracts zip file file. dir is an optional parameter to extract into a specific directory.
  • sys.makeDir(name) Makes a directory with name name
  • sys.removeDir(name) Deletes empty directory name
  • sys.getCurrentDir() Returns the absolute path for the directory the client is saved in
  • sys.filesForDirectory(dir) Return an array of files that are located in dir

Network I/O

  • sys.synchronousWebCall(url) calls the web url given, waits for the reply, and returns the reply.
  • sys.synchronousWebCall(url, args) calls the web url given with the args as POST arguments, waits for the reply, and returns the reply.
  • sys.webCall(url, script) calls the web url given, and when the reply is received runs the script given in parameter. At that moment the variable "resp" will contain the response of the web server.
  • sys.webCall(url, script, args) calls the web url given with the args as POST arguments, and otherwise behaves the same way as the previous function.
  • client.network() Returns a Network object with additional functions, to communicate with the PO server we're connected to.

Messages

  • client.printLine(line) Prints the text specified in all channels.
  • client.printHtml(html) Prints the html text specified.
  • client.printChannelMessage(message, channelId, html) Prints a message in the specified channel. HTML is optional. Be aware that this function calls the ChannelMessage event. Wrong use of both (the event and the function) combined can lead to infinite loops which will make your client crash!
  • client.sendText() Sends the text in the current chat window.

Game Information

  • sys.item(num) returns the name of the item.
  • sys.itemNum(name) returns the number of the item.
  • sys.move(num) returns the name of the move.
  • sys.moveNum(name) returns the num of the move.
  • sys.nature(num) returns the corresponding nature.
  • sys.natureNum(name) returns the number corresponding to that nature.
  • sys.pokeAbility(poke_id, slot, gen) returns id of an ability that Pokémon can have. slot is either 0, 1, or 2 (which ability to return). gen is optional and last gen is used when omitted. Will return undefined if Pokémon is unknown or slot is out of range.
  • sys.baseStats(pokeNum) Return an array of base stats for pokeNum
  • sys.pokemon(num) returns the name of the Pokémon.
  • sys.pokeNum(name) returns the number of the Pokémon.
  • sys.pokeType1(pokeId, gen) returns Pokémon's primary type id. If optional gen is not specified last supported Generation will be used.
  • sys.pokeType2(pokeId, gen) returns Pokémon's secondary type id. If optional gen is not specified last supported Generation will be used. Returns 17 (i.e. type() from it would be "???") if there is none.
  • sys.type(id) returns Pokémon type's display name by id.
  • sys.typeNum(typeName) returns Pokémon type's id by name.
  • sys.gender(id) Returns the corresponding gender name for id
  • sys.genderNum(genderName) Returns a gender's id

Tiers

  • client.getTierList() Returns an array of existing tiers

Players

  • client.playerExist(id) Returns true if a player with that id exists on the server, false otherwise.
  • client.name(id) Gets the name of the player on the server with that id. Returns "Unknown" if not online.
  • client.id(name) Gets the id of a player name. Returns -1 if not online.
  • client.auth(id) Returns the authority level of a player on the server (returns undefined if the player is offline).
  • client.isIgnored(id) Returns true if the player you specified is ignored, false otherwise.
  • client.color(id) Returns the colour of a player.
  • client.tiers(id) Returns the tiers that a player is currently in.
  • client.startPM(tar) Opens PM window
  • client.closePM(tar) Closes PM window
  • client.seeRanking(tar) Opens the ranking window and selects tar
  • client.seeInfo(tar) Opens the trainer info of tar
  • client.ignore(tar, bool) Will ignore tar if bool is true. Will unignore tar if bool is false. You can also call this function with only 1 argument: client.ignore(tar) behaves the same as client.ignore(tar, true).
  • client.isIgnored(tar) Returns true if tar is ignored
  • client.removeIgnore(tar) Same as client.ignore(tar, false)

These functions will only work if your auth is 1 or higher.

  • client.tempban(tar, duration) Bans a player temporarily. duration can be arbitrary high (even if you use it as mod)
  • client.kick(tar) Kicks someone
  • client.controlPanel(tar) Opens the mod control panel and selects tar. Though you can open the control panel with scripts as a normal user, you will not be able to do anything (not even load the banlist or see someones alts)
  • client.ban(tar) Bans a player (player must be online through that the player ID is required). Will not work if you are moderator.
  • client.requestBan(user_name) Bans someone. Can also ban offline players though that no player ID is required.
  • client.requestTempBan(user_name, duration) Like client.requestBan() but can be limited in time.

Own Client

These functions will only affect yourself.

  • client.ownName() Returns the name you are currently on.
  • client.battling() Returns true if you are battling, false otherwise.
  • client.busy() Returns true if you are busy (ie unable to accept challenges), false otherwise.
  • client.away() Returns true if you are on idle, false otherwise.
  • client.ownId() Returns your own player id.
  • client.ownAuth() Returns your own authority level.
  • client.reconnect() Reconnects
  • client.openTeamBuilder() Opens teambuilder (it's the same as pressing ctrl + o)
  • client.loadTeam() Opens the "Load team" window. It's the same as pressing ctrl + l.
  • client.openSoundConfig() Opens the sound configuration window
  • client.changeBattleLogFolder() Opens filebrowser to change the battle log folder.
  • client.newConnection()
  • client.goAway(bool) Sets you to "afk" if bool is true
  • client.sendRegister() Opens the "register" window. It's the same as clicking "register" on a server.
  • client.changeName(new_name) Changes your name to new_name
  • client.done() Makes you leave the server and returns the current tab to the main menu (same as pressing 'Exit').

Battles

  • client.openBattleFinder() Opens the battle finder window
  • client.cancelFindBattle(verbose) Cancels finding a battle.
  • client.sendChallenge(tar, clauses, mode) Sends a challenge to tar with activated clauses with fightmode mode
  • client.acceptChallenge(challenge_id) Accepts a challenge (can be used in afterChallengeReceived for something like auto-accept challenges script)
  • client.watchBattleOf(player1_id) Lets you spectate a battle
  • client.stopWatching(battle_id) Stops spectating a battle
  • client.forfeitBattle(battle_id) Forfeits a battle

Channels

  • client.defaultChannel() Returns the name of your default channel.
  • client.join(channel_name) Lets you join a channel
  • client.channelId(channel_name) Returns the ID of a channel
  • client.channelName(channel_id) Returns the name of a channel
  • client.channelNames() Returns an -> object <- (not an array) of existing channels
  • client.currentChannel() Returns the id of the channel you are currently on.
  • client.hasChannel(channelid) Returns true if you are currently in the channel with the specified channelid, false otherwise.
  • client.autojoinChannels() Returns an array of channels you automatically join. Server dependant
  • client.myChannels() Returns an array of all channels you are currently in. Server dependant

Qt

Note: These are provided by Qt and version dependent. They may change at any time.

  • client.windowTitle Returns the name of the server, or "" if you've never been connected to one in the tab. Can also be set to change the part before "- Pokemon Online" in the window's title. The player has to change their tab (or create a new one) to see the changes.
  • client.setWindowTitle(newName) Setter function for client.windowTitle. Note that you can also use client.windowTitle to set the window title, as it has a getter and a setter. The player has to change their tab (or create a new one) to see the changes.
  • client.styleSheet Returns a custom stylesheet set by the script. Can control the chat area (mainchat, channel tabs, announcement, control buttons (find battle etc.)). Can be used to set or get. Is an empty string by default.
  • client.setStyleSheet(newStyleSheet) Setter function for client.styleSheet. Note that you can also use client.styleSheet to set a custom stylesheet, as it has a getter and a setter.
  • client.close() Similar to client.done(), but is provided by Qt and returns the player to the server list instead. Arguably more useful.
  • client.visible If the client is visible (see client.show() and client.hide()). Is both a setter and a getter (client.visible = false is the same as client.hide()).
  • client.show() Used to reverse the effects of client.hide()
  • client.hide() Hides the chat, player list, etc. Can be undone by changing tabs or calling client.show() (via a timer or something similar).
  • client.layoutDirection If the playerlist is to the left (0) or to the right (1). Same as Move player list to right option. Can be used to set or get.
  • client.isActiveWindow If the client is the active window (if, say, a battle window has focus, the client doesn't). This doesn't mean that the player can't see the chat. Unlike many other Qt properties, this does not have a setter.