-
Notifications
You must be signed in to change notification settings - Fork 171
Client Script Functions
NightfallAlicorn edited this page Mar 22, 2016
·
32 revisions
-
timerID = sys.setTimer(call, time, repeats)
Calls the code incall
aftertime
milliseconds. Ifrepeats
is true then this call repeats itself until unset. Gives atimerID
that can be used to unset the timer. -
sys.unsetTimer(timerID)
Cancels a timer function. If this is placed inside asys.setTimer()
function, make sure it's the last action inside else it will crash your client. -
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 withsys.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 innewScript
. Can also used withsys.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)
-
sys.htmlEscape(string)
Escapes HTML -
sys.isSafeScripts()
Returns a boolean whether safe scripts is enabled or not. -
sys.showingWarnings()
Returns a boolean whether show script warnings is enabled or not. -
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)
Returns a boolean if the input is a valid color name or hex color. (e.g. #FF0000 is valid, #5Y6789 is not.) -
sys.hexColor(color)
Converts a color (such as "red") into a hexadecimal color. -
client.channel(channelId).addChannelLinks(string)
Returns a string with click-able hash channel links. Use this when messages lose their links on client.printHtml(html) or client.printChannelMessage(message, channelId, html) with html true. This is sadly a badly coded function since you're required to be in thechannelId
. Use something like this if you can't be positive you be in one:
function addChannelLinks(string) {
return client.channel(client.channelId(client.myChannels()[0])).addChannelLinks(string);
}
-
sys.writeToFile(fileName, content)
Writescontent
to the file atfilename
. Will remove any existing content. -
sys.appendToFile(filename, content)
Appendscontent
to the end of the file atfilname
. -
sys.getFileContent(fileName)
Returns the content of the file atfilename
. -
sys.fileExists(fileOrFolderName)
Returns a bool if a file or folder exists inside the PO application folder. Example: sys.fileExists("example_file.txt"), sys.fileExists("exmaple_folder"), sys.fileExists("folder/example_file_in_folder.txt"). -
sys.saveVal(key, value)
Storesvalue
to the data.ini file withkey
. -
sys.getVal(key)
Returns the value ofkey
in the data.ini file. -
sys.removeVal(key)
Removes the value ofkey
in the data.ini file. -
sys.getValKeys()
Returns the keys stored in the in the data.ini file. -
sys.getRegVal(key)
Returns the value ofkey
in the registry. -
sys.removeRegVal(key)
Removes the value ofkey
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 directorydir
into a zipfile namedfile
. -
sys.extractZip(file, dir)
Extracts zip filefile
.dir
is an optional parameter to extract into a specific directory. -
sys.dirsForDirectory(dir)
Returns an array of folder names in the path ofdir
. Having "" for path returns an array of folder names for app directory. -
sys.makeDir(folderName)
Makes a directory withfolderName
being the name. It only allows you to create a directory inside the app's location folder or deeper. Example sys.makeDir("a/b/c") will make folder a first, b in a and c in b same time. -
sys.removeDir(folderName)
Deletes empty directoryfolderName
. If the directory contains a file, it won't work. Only works in the app's directory or deeper. Note it will remove all folders deep in one folder regardless of input. -
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 indir
-
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.
-
client.printLine(line)
Prints the text specified in all channels. Channel tabs don't turn green also. -
client.printHtml(html)
Prints the html text specified in all channels. Channel tabs don't turn green also. -
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.
-
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)
returns an array of base stats forpokeNum
-
sys.baseStats(pokeNum, stat, gen)
returns a specific base stat (0=HP, 1=Atk, ...) for a specific gen. -
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 forid
-
sys.genderNum(genderName)
Returns a gender's id
-
client.getTierList()
Returns an array of existing tiers
-
client.playerExist(playerId)
Returns true if a player with that id exists on the server, false otherwise. -
client.name(playerId)
Gets the name of the player on the server with that playerId. Returns "Unknown" if not online. -
client.id(playerName)
Gets the id of a player name. Returns -1 if not online. -
client.auth(playerId)
Returns the authority level of a player on the server (returns undefined if the player is offline). -
client.color(playerId)
Returns the colour of a player. -
client.tier(playerId)
Returns only the first tier that a player is currently in as a string. -
client.tiers(playerId)
Returns the tiers that a player is currently in as an array. -
client.startPM(playerId)
Opens PM window. -
client.closePM(playerId)
Closes PM window. -
client.seeRanking(playerId)
Opens the ranking window and selectsplayerId
. -
client.seeInfo(playerId)
Opens the trainer info ofplayerId
. -
client.ignore(playerId, bool)
Will ignoreplayerId
ifbool
is true. Will unignoreplayerId
ifbool
is false. You can also call this function with only 1 argument:client.ignore(playerId)
behaves the same asclient.ignore(playerId, true)
. -
client.isIgnored(playerId)
Returns true ifplayerId
is ignored. -
client.removeIgnore(playerId)
Same asclient.ignore(playerId, false)
. -
client.isIgnored(playerId)
Returns true if the player you specified is ignored, false otherwise.
These functions will only work if your auth is 1 or higher.
-
client.tempban(playerId, duration)
Bans a player temporarily.duration
can be arbitrary high (even if you use it as mod). -
client.kick(playerId)
Kicks someone. -
client.controlPanel(playerId)
Opens the mod control panel and selectsplayerId
. 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(playerId)
Bans a player (player must be online through that the player ID is required). Will not work if you are moderator. -
client.requestBan(playerName)
Bans someone. Can also ban offline players though that no player ID is required. -
client.requestTempBan(playerName, duration)
Likeclient.requestBan()
but can be limited in time. -
client.tempban60(playerId)
Bans someone temporarily, but with a fixed value of 60 minutes (1 hour). -
client.tempban1440(playerId)
Bans someone temporarily, but with a fixed value of 1440 minutes (1 day).
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.newConnection()
-
client.sendRegister()
Opens the "register" window. It's the same as clicking "register" on a server. -
client.changeName(new_name)
Changes your name tonew_name
-
client.done()
Makes you leave the server and returns the current tab to the main menu (same as pressing 'Exit').
-
client.goAway(bool)
Sets you to "afk" ifbool
is true -
client.openSoundConfig()
Opens the sound configuration window -
client.changeBattleLogFolder()
Opens filebrowser to change the battle log folder. -
client.saveBattleLogs(bool)
bool
is either true or false whether your client logs battles. You have to relog in order to see the option updated in the menu -
client.animateHpBar(bool)
bool
is either true or false whether HP bars are animated -
client.enableLadder(bool)
Will enable ladder ifbool
is true -
client.sortPlayerByTiers(bool)
Will sort players by their tiers ifbool
is true -
client.sortPlayersByAuth(bool)
Will sort players by auth ifbool
is true -
client.enablePlayerEvents()
Will activate all player events when executed -
client.disablePlayerEvents()
Will disable all player events when executed -
client.getEventsForChannel(channel_name)
Returns an integer representing the activated player events in that channel. 1 is for idle events, 2 for battle events, 4 for general channel events (login, logout) and 8 for team change events. So if you get 10, battle and team change events are enabled in that channel -
client.showIdleEvents(bool)
Returns if you have idle events enabled -
client.showBattleEvents(bool)
Returns if you have battle events enabled -
client.showChannelEvents(bool)
Returns if you have general channel events enabled -
client.showTeamEvents(bool)
Returns if you have team change events enabled -
client.ignoringGlobalMessage(channel_name)
Returns if you are ignoring global messages in that channel -
client.showTimeStamps(bool)
Hides timestamps ifbool
is false, shows them ifbool
is true -
client.movePlayerList(bool)
Moves player list to the right side ifbool
is true, leaves it left otherwise client.useOldShortcuts(bool)
client.ignoreServerVersion(bool)
-
client.changeExitWarning(bool)
Will show exit warning before leaving a server ifbool
is true -
client.showExitWarning()
Returns if your client show the exit warning before leaving a server -
client.toggleIncomingPM(bool)
Will reject incoming PMs ifbool
is set to true -
client.togglePMTabs(bool)
Will show PMs in tabs ifbool
is true -
client.togglePMNotifications(bool)
Will activate PM notifications ifbool
is true -
client.togglePMLogs(bool)
Will log PMs ifbool
is true
-
client.openBattleFinder()
Opens the battle finder window -
client.cancelFindBattle(verbose)
Cancels finding a battle. -
client.sendChallenge(tar, clauses, mode)
Sends a challenge totar
with activatedclauses
with fightmodemode
-
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
-
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(channel_id)
Returns true if you are currently in the channel with the specified channel_id, 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 -
client.channel(channel_id).players()
Returns an array of each player id in the specified channel. To get their names, you would need to loop the array after with client.name(player_id) for each value. The id values of the array are string typeof and you will need to parseInt loop the values to number so they work with indexOf checking for player_id given by an event. Lastly, you will need to be in the channel or it will return an error.
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 forclient.windowTitle
. Note that you can also useclient.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 forclient.styleSheet
. Note that you can also useclient.styleSheet
to set a custom stylesheet, as it has a getter and a setter. -
client.close()
Similar toclient.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 (seeclient.show()
andclient.hide()
). Is both a setter and a getter (client.visible = false
is the same asclient.hide()
). -
client.show()
Used to reverse the effects ofclient.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.