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 serverStartUp event will be triggered after loading a new script.
  • sys.os() Client OS name
  • 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

Helpers

  • 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)
  • 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 an object with additional functions.

client.network().sendChanMessage(channel, message) Sends a message to all players in channel. This function calls the server's chatMessage events, so you could also execute server commands

client.network().CPUnban(player_name) Unbans player_name

client.network().sendPM(player, message) Sends a PM to player. PMs content is message

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.

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.seeRanking(tar) Opens the ranking window and selects tar
  • client.seeInfo(tar) Opens the trainer info of tar

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
  • client.ban(tar) Bans a player (player must be online through that the player ID is required). Will not work if you are moderator.

Own Client

These functions will only affect yourself.

  • client.cancelFindBattle(verbose) Cancels finding a battle.
  • client.hasChannel(channelid) Returns true if you are currently in the channel with the specified channelid, false otherwise.
  • 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.currentChannel() Returns the id of the channel you are currently on.
  • client.ownId() Returns your own player id.
  • client.ownAuth() Returns your own authority level.
  • client.defaultChannel() Returns the name of your default channel.
  • client.reconnect() Reconnects
  • client.openTeamBuilder() Opens teambuilder (it's the same as pressing ctrl + o)
  • client.newConnection()
  • client.goAway(bool) Sets you to "afk" if bool is true

Battles

  • client.openBattleFinder() Opens the battle finder window
  • 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

Channels

  • 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