1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Guest, PO has ceased our separate tiering and adopted Smogon tiers for SM. More information and updates here.

    Dismiss Notice

[Server Scripting] Script changes for update after 2.0.05

Discussion in 'Server and Client Scripting' started by coyotte508, Jul 11, 2012.

  1. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    167
    Script changes of last update

    Added 4 new functions:

    • Qt.lighter(color, factor=1.5): gives a lighter color than the one given
    • Qt.darker(color, factor=2.0): gives a darker color than the one given
    • Qt.tint(baseColor, tintColor): gives the base color with a tint of the second color. For example, Qt.tint("lightsteelblue", "#10FF0000") will give a slight red tint to the light steel blue color (notice the "10" at the beginning that says the color is 1/16 opaque)
    • Qt.lightness(color): returns the lightness of the color

    The reason I added those functions, is I want to display pokemon bot as their type colors, but sometime their color is too light so I detect that with Qt.lightness(color) and then use Qt.darker(color)!
     
    Last edited: Jul 11, 2012
  2. Crystal Moogle

    Crystal Moogle Ayaya~

    Joined:
    Jul 19, 2010
    Messages:
    3,204
    Likes Received:
    530
    PO Trainer Name:
    Hanako
    2.0.06 Changes

    Server and Client Functions
    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[/HIDE]

    Client Functions
    onPlayerJoinChan(id, channel)
    -gets called everytime someone joins a channel you're in. id is the player's id and channel is the channel's id. Unstoppable Event.

    onPlayerLeaveChan(id, channel)
    -gets called everytime someone leaves a channel you're in. id is the player's id and channel is the channel's id. Unstoppable Event.[/HIDE]
     
    Last edited: Nov 15, 2012
  3. Crystal Moogle

    Crystal Moogle Ayaya~

    Joined:
    Jul 19, 2010
    Messages:
    3,204
    Likes Received:
    530
    PO Trainer Name:
    Hanako
    2.0.07 Changes

    Server Functions

    sys.setTimer(script, milliseconds, repeats)
    - Sets a timer to run script. Use milliseconds to define how often it is run and repeats is true/false depending on whether or not you want to make it run continously. Returns a timerId to be used in unsetTimer()

    sys.unsetTimer(timerId)
    - Unsets a previously set timer with timerId

    sys.unsetAllTimers()
    - Unsets all current timers

    sys.battlingIds()
    - Gives a list of all the current battles in ID form

    sys.prepareItems(battleid, playerslot, items)
    - Gives items to players before a battle starts (Be careful with this as players on < 2.0.07 clients will crash when given items). battleid is the battle you want to give the items to, playerslot is which player you want to give them to and items is a list of items you want to give (e.g. {"124":3} gives 3 sacred ash) Item ids are available in db/items/items.txt or using the sys.itemNum function. [/HIDE]

    Server Events

    warning(function, message)
    - Gets called everytime a warning is displayed. function is the function that gives the warning (e.g. getFileContent(filename)) and message is the warning message itself (e.g. Error when opening file). Stoppable Event.

    unloadScript()
    - Gets called when the script gets unloaded. Unstoppable Event.

    loadScript()
    - Gets called when the script gets loaded. Stoppable Event.

    switchError(newscript)
    - Gets called when a new script gives an error. newscript is the error in the new script. Unstoppable Event.

    beforeIPConnected(ip)
    - Gets called when an IP connects to the server. ip is the IP trying to connect. It calls before they even fully enter the server, so it can be used to block nameless IPs. Stoppable Event.[/HIDE]

    Client Functions


    sys.version()
    - Returns the version the client is on (e.g. 2.0.07).

    sys.beep()
    - Plays a beep sound from your operating system.

    sys.playSound(wavfile)
    - Plays a sound file. wavfile must be a valid WAV filetype.

    sys.htmlEscape(string)
    - Uses PO's built in html escaper to escape string. Also automatically turns http(s)/ftp urls into links.[/HIDE]

    Client Events

    beforeNewMessage(message, html)
    - Gets called before a global message is received. message is the message itself and html is a booleon (true/false) representing whether or not it's a html message. Stoppable Event.

    afterNewMessage(message, html)
    - Same as beforeNewMessage, except called after a global message is received. Unstoppable Event.[/HIDE]
     
    Last edited: Jun 30, 2013
  4. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    167
    Changes for 2.0.08

    Server Functions

    [secret]sys.addPlugin(path): add the plugin from that path. Prints an error on failure
    sys.listPlugins(): List plugins loaded
    sys.removePlugin(index): remove the plugin at index (you can guess indexes from listPlugins())

    Note: If you want to update a plugin (i.e. remove it, readd it), be cautious. The WebServer plugin can be updated instantly, but the usage stats plugin will only be fully removed once all the wifi battles it was loaded in are past the team selection phase, and the battle logs plugin will be removed once all the battles that had started are finished. You should readd the plugin after it's fully removed, preferably.[/secret]
     
  5. Crystal Moogle

    Crystal Moogle Ayaya~

    Joined:
    Jul 19, 2010
    Messages:
    3,204
    Likes Received:
    530
    PO Trainer Name:
    Hanako
    2.0.10 Changes

    Server functions
    [secret]sys.changePokeHp(playerId, team, slot, hp)
    - Changes hp stat of pokemon in slot, on team of playerId to hp

    sys.changePokeStatus(playerId, team, slot, status)
    - Changes status of pokemon in slot, on team of playerId to status

    sys.changePokePP(playerId, team, slow, moveslot, pp)
    - Changes PP of move in moveslot of pokemon in slot, on team of playerId to pp

    sys.teamPokeStat(playerId, team, slot, stat)
    - Return value of stat of pokemon in slot on team of playerId

    sys.teamPokeHP(playerId, team, slot)
    - Return HP of pokemon in slot on team of playerId

    sys.teamPokeStatus(playerId, team, slot)
    - Return status of pokemon in slot on team of playerId

    sys.teamPokeHP(playerId, team, slot, moveslot)
    - Return PP of move in moveslot of pokemon in slot on team of playerId

    sys.pokeBaseStats(pokeNum)
    - Return an array of baseStats for pokeNum

    sys.swapPokemons(playerId, team, slot1, slot2)
    - Swaps the pokemon in slot1 for the pokemon in slot2 on team of playerId

    sys.setTeamToBattleTeam(playerId, team, battleId)
    - Sets the team of playerId of the team they had at the end of battleId. Only works when used in beforeBattleEnded. For example if at the end of the battle he had 5 pokemon koed, then at the next battle he'll only have one pokemon not koed[/secret]

    Client Functions
    [secret]client.autojoinChannels()
    - Returns an array of names of autojoin channels you have for the current server

    client.myChannels()
    - Returns an array of channels names that you are currently in

    client.channel(channel).players()
    - Returns an array of playerIds in channel

    client.acceptChallenge(cId)
    - Accepts a challenge with id of cId

    client.sendChallenge(playerId, clauses, mode)
    - Sends a challenge to player with playerId, with clauses and mode.

    sys.setTimer(script, milliseconds, repeats)
    - Sets a timer to run script. Use milliseconds to define how often it is run and repeats is true/false depending on whether or not you want to make it run continously. Returns a timerId to be used in unsetTimer()

    sys.unsetTimer(timerId)
    - Unsets a previously set timer with timerId

    sys.unsetAllTimers()
    - Unsets all current timers

    sys.pokeAbility(pokemon, slot, gen)
    - Returns the ability in slot for pokemon. Gen is optional parameter for past gens, default is 5

    sys.type(typenum)
    - Returns the type for typenum. Typenum is a number between 0 and 17

    sys.typeNum(type)
    - Returns the typeNum for a type.

    sys.baseStats(pokemon, stat, gen)
    - Returns the base stat for a stat for pokemon. Stat is any number between 0 and 5 (0 being HP, 1 being atk, etc). Gen is optional parameter for past gens, default is 5.[/secret]

    Client Events
    [secret]beforeChallengeReceived(challengeId, opponentId, tier, clauses)
    - Gets called before a challenge is sent to you. challengeId is the id of the challenge, opponentId is the id of the person sending the challenge, tier is the name of the tier and clauses is an integer represting the clauses. Stoppable event

    afterChallengeReceived(challengeId, opponentId, tier, clauses)
    - Gets called after a challenge is sent to you.[/secret]
     
    Last edited: Jan 12, 2013
  6. Nightfall Alicorn

    Nightfall Alicorn Left Pokémon Online, most likely not coming back.

    Joined:
    Oct 15, 2013
    Messages:
    491
    Likes Received:
    171
    PO Trainer Name:
    Nightmare Moon
    Thought I note that the typeof values are string not number. I had issue trying to
    Code (JavaScript):
    1. var arr = client.channel(channelId).players();
    2. if (arr.indexOf(playerId) > -1) {
    3.  
    4. }
    because of the type value.
    (18:15:12) ++Cheato: Eval Printing: client.channel(0).players()[0]
    (18:15:12) ++Cheato: Type: 'string'
    (18:15:12) ++Cheato: Value: '34798'

    I had to loop and parseInt the values.
     
  7. MidwayMarshall

    MidwayMarshall woof Forum Moderator Developer Forum Moderator Developer

    Joined:
    Jun 13, 2014
    Messages:
    303
    Likes Received:
    170
    Indeed it is a string collection

    Code (c++):
    1. Q_INVOKABLE QStringList players();
    2.  
    3. QStringList Channel::players() {
    4. QStringList players;
    5. foreach(int player, ownPlayers) {
    6. players.push_back(QString::number(player));
    7. }
    8. return players;
    9. }
    However there is a much better solution for the Channel class
    Code (javascript):
    1. bool has = client.channel(int).hasPlayer(int)
    Here is a reflection list of the channel object in javascript
    activated(Channel*)
    addChannelLinks(QString)
    addEvent(int)
    anchorClicked(QUrl)
    battleReceived2(int,Battle)
    checkFlash(QString,QString)
    deleteLater()
    destroyed()
    destroyed(QObject*)
    eventEnabled(int)
    hasPlayer(int)
    hasRemoteKnowledgeOf(int)
    id()
    isReadyToQuit()
    makeReadyToQuit()
    name()
    objectNameChanged(QString)
    pactivated(Channel*)
    players()
    printHtml(QString)
    printHtml(QString,bool)
    printHtml(QString,bool,bool)
    printLine(QString)
    printLine(QString,bool)
    printLine(QString,bool,bool)
    printLine(QString,bool,bool,bool)
    quitChannel(int)
    removeEvent(int)
    resetEvents()
    restoreEventSettings()
    showContextMenu(QPoint)
    sortAllPlayersByTier()
    sortAllPlayersNormally()
     
    Last edited: Nov 5, 2015