Skip to content

Client Script Functions

SongSing edited this page Jul 7, 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.

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.

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.

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.