• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Script: [v16/v17/v18/v19/v20/v21] Cable Club (Online Trades/Battles)

1,680
Posts
8
Years
  • Age 23
  • Online now
Yep, you read that correctly, we got v19.1 support, and MKXP too! That means you can connect to the server from Linux (and probably Mac OS) too!

One catch, you need to update to MKXP-Z 2.2.3, since it takes advantage of a larger standard library to require 'sockets'
https://gitlab.com/mkxp-z/mkxp-z/-/releases/v2.2.3

Oh, and also the game segfaults in debug mode when the shell is open. Don't know why. It doesn't happen if you launch it normally. Don't really care either, I can't fix a segfault.

Also, minor improvements to the server scripts for v16/v17/v18 too, since its a big deal. A crashing game will no longer crash the server. Instead, the server gracefully disconnects the problem player, and their partner if they had one.
 
1,680
Posts
8
Years
  • Age 23
  • Online now
Both versions of the script get an update here. v19.1 goes to 2.1, while v16-18 goes to 1.6, because we got some changes!

First on the list, Online Trainer Types. Since the Union Room used to assign trainer types for an overworld, this is basically that. You can call pbChangeOnlineTrainerType to have a premade method that works with the ONLINE_TRAINER_TYPE_LIST array. It uses the text that the Psychic in DPPt had.

ONLINE_TRAINER_TYPE_LIST is an array of arrays or symbols. An array would use the value of the trainer's gender to gender lock certain trainer types. The regular symbol is not gender locked.

With this change, I also streamline how data is sent to the server. Normally, the trainer type is passed around every time it's needed. Now, we only send it once, while we search for a partner, and save that result.

YOU HAVE TO UPDATE YOUR PYTHON SERVER BECAUSE OF THIS CHANGE!

Also added, an optional serverinfo.ini file, for if you want to let your players set up their own servers. Of course, they will still need the PBS files, same as any server. The ini file contains up to 2 lines, a HOST = X.X.X.X line, and a PORT = XXXX line. Technically you can have more, but only the last HOST and PORT will work. These override the settings in the script. You don't need to define both in the file either.
Makes testing easier too.

Valid serverinfo.ini Files
Spoiler:
 
27
Posts
4
Years
  • Age 26
  • Seen Jul 19, 2023
Hello,
I still encounter a few issues with v17.2 of Essentials.
1. Sometimes, I crit with an attack on my game, but in the game of my opponent, I dont.
2- When I use attacks that hit multiple times (for example fury swipe), it is possible that I attack 3 times in my game but only 2 times at my opponents game.
Is there any way to fix this, because this makes the plugin unplayable.
Awesome plugin regardless, I realy want to fix this issue somehow to use it without problems.^^
 
1,680
Posts
8
Years
  • Age 23
  • Online now
Hello,
I still encounter a few issues with v17.2 of Essentials.
1. Sometimes, I crit with an attack on my game, but in the game of my opponent, I dont.
2- When I use attacks that hit multiple times (for example fury swipe), it is possible that I attack 3 times in my game but only 2 times at my opponents game.
Is there any way to fix this, because this makes the plugin unplayable.
Awesome plugin regardless, I realy want to fix this issue somehow to use it without problems.^^

Oh sorry. I commented out a method that didn't seem like it was working properly a couple of versions ago, which would affect v16 and 17 projects. def pbPriority.

You can't miss it, big block of green half way down, just delete the =begin and =end.
 
27
Posts
4
Years
  • Age 26
  • Seen Jul 19, 2023
Oh sorry. I commented out a method that didn't seem like it was working properly a couple of versions ago, which would affect v16 and 17 projects. def pbPriority.

You can't miss it, big block of green half way down, just delete the =begin and =end.


I tried this out and it seems to work for the second problem. I need to test a little bit more to see, if the problem with the crits is also fixed by this, thank you.^^

I also found another problem: If you use a attack that repeats itself for multiple rounds, for example Petal Dance and you opponent switches the Pokémon for another one, then the switch does not appear for the Petal Dance user and the battle goes out of sync.
Doesnt know, why this happens. If you switch the Pokémon in any other situation, then it works without problem.
 
1,680
Posts
8
Years
  • Age 23
  • Online now
I tried this out and it seems to work for the second problem. I need to test a little bit more to see, if the problem with the crits is also fixed by this, thank you.^^

I also found another problem: If you use a attack that repeats itself for multiple rounds, for example Petal Dance and you opponent switches the Pokémon for another one, then the switch does not appear for the Petal Dance user and the battle goes out of sync.
Doesnt know, why this happens. If you switch the Pokémon in any other situation, then it works without problem.

Hmm, that second issue is no good. I'll look into it, thanks for the report.
 
1
Posts
2
Years
  • Age 27
  • Seen Jan 31, 2022
First, thanks! I was Searching functions like this since Aegisrox and Markz show us an implementation of Essentials with Blizzard's RMXOS! Keep going this is just fantastic!

Otherwise, I'm here because I found some "Sync Problems", if you use "Sand Attack" to decrease ACC of Pokemons you can test it, sometimes a Hit Counts on a Player Screen decreasing Pokemon HP, but this didn't happen on the other player Screen, because it counts as a Missed Attack.

Sorry for my english, and Thank you again!
 

Canal_do_Lontra

Oshawott uses Razor Shell
207
Posts
4
Years
Since the original script is abandonware, and I've been updating it, guess it's time to make my own thread for it.
Original Thread: https://www.pokecommunity.com/showthread.php?t=447015

Credits to mGriffin for the original script, and Khaikaa for commissioning it.

There's two parts:
  1. a plug and play script for Essentials in cable_club.rb. I call mine CableClub and put it directly above Main. You need to edit the HOST and PORT constants at the top to be the address and port of your server.
  2. a Python3 server in cable_club.py. It needs your PBS files to run, by default it looks in the directory you run it from, but you can pass --pbs_dir to change that. You can also pass --host and --port or alter the HOST and PORT constants at the top. You also need to set EBDX_INSTALLED to true if you have it, so the script can handle the extra data EBDX requires.

Connections are established via Trainer IDs, which can be found on the trainer card screen. Think of them as a bit like friend codes.

The v19 version of the script requires at least mkxpz 2.2.3. You do not need the std folder, just the included files.

For hosting the server you could try free-tier on Google Cloud. It shouldn't use much processing power (but I'd recommend setting up some sensible limits, because there's nothing in the protocol to stop somebody DDOSing it).

Newly added in v2.1, a online trainer type that is used in online battles, kind of like how you can appear as different sprites in the Union Room. Call pbChangeOnlineTrainerType to have an easy preset event that allows the player to change using the contents of ONLINE_TRAINER_TYPE_LIST.
ONLINE_TRAINER_TYPE_LIST is an array containing either length 2 arrays (for gender locked trainer types) or a single Trainer Type ID.

Also new in v2.1, an optional serverinfo.ini file, for if you want to let your players set up their own servers. Of course, they will still need the PBS files, same as any server. The ini file contains up to 2 lines, a "HOST = X.X.X.X" line, and a "PORT = XXXX" line. Technically you can have more, but only the last HOST and PORT will work. These override the settings in the script. You don't need to define both in the file either.
Makes testing easier too.

Google Cloud instructions:
  1. Set up the desired port in the python script, and set the host to "0.0.0.0"
  2. Sign up for Google Cloud (this requires a credit card, even for the free trial).
  3. In the side bar, hover "Compute Engine" and select "VM Instances".
  4. Select "Create Instance".
  5. Under Machine Configuration, select E2-micro (one of the options supported by Google's free tier).
  6. Under Boot Disk, select Change, and make it a Ubunto 18.04 (this comes with python 3.6).
  7. Click Create.
  8. In the side bar, hover "VPC Networks" and select "External IP Addresses".
  9. The IP address for the VM we just created should show here. Select CHANGE to reserve it as a static address and give it a name. Copy this address and put it in the ruby script file as the HOST.
  10. In the side bar, select "Firewall" and create a new Firewall rule, an Ingress rule for all ips (0.0.0.0/0) on TCP port 9999 (or whatever you have it in the script).
  11. Return to the VM Instances, and press the SSH button to enter the terminal for the VM.
  12. You are now in the home folder of the VM. You can use the gear to manually upload files one at a time. You need to upload the python script, and the PBS files it requires. (You can also use git to clone the files into the VM.)
  13. To test, you can run "python3 cable_club.py"
  14. The server auto shuts down when the ssh session is closed but at that point you have to set up boot scripts for the VM.

Boot Scripts for Google Cloud VMs
  1. You need to change the python script's PBS property to "./home/YOUR_USERNAME_HERE". YOUR_USERNAME_HERE is the green part of the name before the @. This sets it to the home folder that you log into, adjust further if the PBS files are in a sub folder.
  2. In "VM Instances", click the name of your VM instance, and select Edit.
  3. Scroll down to the Custom Metadata section.
  4. Set the key to "startup-script" (no quotes), and the value to
    Bash:
    #! /bin/bash
    nohup python3 /home/YOUR_USERNAME_HERE/cable_club.py &
    If your server is in a sub folder, adjust the second line to it's proper location.
  5. Save the edits, and stop and reboot the VM.

Version 2.1: https://www.mediafire.com/file/3akzs1os67mktr2/cable_club_port.zip/file

oh i didn't understand a lot if i need to pay something or not, i really wanted a lot to get online features in my fan game of my dreams that i always wanted and wished to finish.
 
1,680
Posts
8
Years
  • Age 23
  • Online now
oh i didn't understand a lot if i need to pay something or not, i really wanted a lot to get online features in my fan game of my dreams that i always wanted and wished to finish.

Ah, well, it's kind of yes and no? Like the free tier for google cloud doesn't charge you for 1 vm, the external IP that goes with it, and 1 GB of network traffic, but if you exceed those limits you start getting charged. Plus you need a credit card.

I suppose you can always find a different hosting provider, or even host yourself, with port forwarding, but that's beyond the scope of this script, and I only know how to work it locally or with google cloud.
 

Canal_do_Lontra

Oshawott uses Razor Shell
207
Posts
4
Years
Ah, well, it's kind of yes and no? Like the free tier for google cloud doesn't charge you for 1 vm, the external IP that goes with it, and 1 GB of network traffic, but if you exceed those limits you start getting charged. Plus you need a credit card.

I suppose you can always find a different hosting provider, or even host yourself, with port forwarding, but that's beyond the scope of this script, and I only know how to work it locally or with google cloud.

yo, so, i need to pay with my credit card the google cloud right? maybe i need to grow more to get jobs and work to get money, so it makes me sad about the fact that i can't do that without paying, but thanks for explaining about the things, i said about i didn't understand a lot because i was confuse, but you made a great resource, thanks and nice work, and i almost forgot, have a nice day/afternoon/evening, cya.
 
1,680
Posts
8
Years
  • Age 23
  • Online now
Sure, v20 has been out for a while, but I've been very busy. But now I'm free.
And that means updates, and with is, a new major number, because I'm pretty sure that's how SemVer works, and I can't be bothered to double check.

I know that trades and battles still work of course, and I haven't reintroduced previously fixed bugs insofar as I'm aware, based off the bug fix comments I left in the code.

v20 already has a sufficient version of mkxp-z so you do not need to update your mkxp-z version like with v19.

I technically only tested it with v20.1.

No new features client side.
Server side, it now sends the game version, so you can decline players on an out of date version of the game.
 
Last edited:

StCooler

Mayst thou thy peace discover.
9,289
Posts
4
Years
  • Age 28
  • Seen today
Hello,
I still encounter a few issues with v17.2 of Essentials.
1. Sometimes, I crit with an attack on my game, but in the game of my opponent, I dont.
2- When I use attacks that hit multiple times (for example fury swipe), it is possible that I attack 3 times in my game but only 2 times at my opponents game.
Is there any way to fix this, because this makes the plugin unplayable.
Awesome plugin regardless, I realy want to fix this issue somehow to use it without problems.^^

I tried this out and it seems to work for the second problem. I need to test a little bit more to see, if the problem with the crits is also fixed by this, thank you.^^

I also found another problem: If you use a attack that repeats itself for multiple rounds, for example Petal Dance and you opponent switches the Pokémon for another one, then the switch does not appear for the Petal Dance user and the battle goes out of sync.
Doesnt know, why this happens. If you switch the Pokémon in any other situation, then it works without problem.

First, thanks! I was Searching functions like this since Aegisrox and Markz show us an implementation of Essentials with Blizzard's RMXOS! Keep going this is just fantastic!

Otherwise, I'm here because I found some "Sync Problems", if you use "Sand Attack" to decrease ACC of Pokemons you can test it, sometimes a Hit Counts on a Player Screen decreasing Pokemon HP, but this didn't happen on the other player Screen, because it counts as a Missed Attack.

Sorry for my english, and Thank you again!

Hello both of you;

I've run into the same problem as you (loss of synchronicity between the two players).
After some investigation it turns out that, in my specific case, I had many scripts that change how battles work (I have Z-moves, Dynamax, as well as a dozen other custom scripts) and thus, many things that are not transfered by the Cable Club script. If for example, Player A uses a Z-move, while Player B uses a normal move, then Player A (using a Z-move) runs a bit of code that Player B doesn't (because the Cable Club script doesn't transfer Z-moves), which may call the "rand" function a bit more times for Player A and not Player B, causing asynchronicity.

So I would like to check whether it's the same for you. You don't necessarily have a script for Z-moves or Dynamax, but you probably have some script that alter battles. Is that the case?

You can check where the asynchronicity comes by pasting this script somewhere:

Code:
alias __real__rand rand
def rand(*args)
  ret = __real__rand(*args)
  File.open("errorlog.txt", "a") { |f|
    f.write(_INTL("{1} => {2}", args[0], ret)+ "\n")
  }
  return ret 
end

and check how the file "errorlog.txt" evolves in the Game folder (not the save folder) of both players. When you use a function / script / something that is not transfered by the Cable Club script, you should see an asynchronicity happen because the lines this script prints in the file will start to differ at some point.

Don't forget to remove my small script when you're done testing!
Also note that I'm on v18, you should check if "def rand(*args)" exists in your version as well.
 
Last edited:
1,680
Posts
8
Years
  • Age 23
  • Online now
With this update, the v20 and v19 versions of the scripts are now up to v3.1 and v2.2 respectively.

This update reorganizes the plugin folder and adds Record Mixing. Record Mixing allows for the transfer of data between games, and other scripts can implement their own Record Mixing registrations if so they desire.

Unfortunately, the v16/17/18 version of the script is missing a critical component to implement this feature, so officially, they are now Legacy versions, meaning that they will only receive bug fix updates from this point onwards.
Unofficially though, if you copied class HandlerHashBasic from v20, and the respective 005_RecordMixer.rb file, you could still implement the record mixer by referencing def self.connect_to

Some corrections were made to the server scripts in all versions to prevent crashes.
 
1,680
Posts
8
Years
  • Age 23
  • Online now
This version fixes bugs relating to desyncing, as well as post battle clean up.

The v16/v17/v18 version of the script now gains the Record Mixer feature, as I was back in the script anyways

The server now features proper logging features, and logs to a file, server.log. It defaults to level INFO, but you can pass a lower level with --log=LEVEL, where LEVEL is a logging level constant (see python docs).
 
1,680
Posts
8
Years
  • Age 23
  • Online now
This version fixes desyncing issues for all versions due to forfeiting.
It also fixes longstanding desyncing issues in v16 and v17, in which moves with altered priorities would cause the battlers to move in different orders on both sides, due to the altered priority being applied to the incorrect index.

All versions also get a minor reorganization with the forfeit bug fix, so all data is sent in a single package. This also separates battle mechanics from being sent for every battler in battle. This change would make it easier to implement additional battle mechanics, such as Z Moves, Dynamax, or Terastal Phenomenon. I am still in the process of testing such additions for bugs (not many but there are a few still), but it is possible and has already been done.

Finally, a change from v3.2 that I failed to point out, I added GameStats to online for v20 projects.
 
27
Posts
4
Years
  • Age 26
  • Seen Jul 19, 2023
With the new version, I still have problems with desync.
If I crit a opponent, this is only displayed on one side, but at the game of my friend, he wasnt crit.
Also, if I use a move that repeats itself, like Petal Dance for example, then the game will freeze for the user of this move, it will say waiting and nothing will happen anymore.
Also, if the Petal Dance user is defeated, an error occurs on the opponents game:

---------------------------
[Game Name]
---------------------------
[Pokémon Essentials version 17.2]

Exception: RuntimeError

Message: Unknown message: battle_data

OnlineSystem:1142:in `pbSwitchInBetween'

OnlineSystem:1130:in `update'

OnlineSystem:1130:in `pbSwitchInBetween'

OnlineSystem:1123:in `loop'

OnlineSystem:1145:in `pbSwitchInBetween'

OnlineSystem:1239:in `pbSwitch'

OnlineSystem:1233:in `each'

OnlineSystem:1233:in `pbSwitch'

PokeBattle_Battle:3877:in `__clauses__pbEndOfRoundPhase'

PokeBattle_Clauses:42:in `pbEndOfRoundPhase_ebs'



This exception was logged in

C:\XXX

Press Ctrl+C to copy this message to the clipboard.
---------------------------
OK
---------------------------



I'm using v17.2 and I have EBS installed.
 
Last edited:
1,680
Posts
8
Years
  • Age 23
  • Online now
v21 ported very nicely, with a grand total of 4 new lines to get it to work with the same code as v20. And none of them were AI related. It was Record Mixer.

All versions get a bump up in version number, and some long standing bugs are fixed.
The biggest, affecting all versions, is a struggle related bug fix. So move data is sent differently now.

v16\v17\v18 versions get a fancy new MersenneTwisterRandom class, much like the Random class used by v19+ versions of the script, to avoid unknown aspects changing the rand value underneath the Cable Club, causing desyncs.

The download now features a cute User Manual PDF, much like the one for Secret Bases Remade. This is much cleaner than the way the thread is now.

Finally, v20 is compatible with Essentials Deluxe, ZUD Mechanics, Terastal Phenomenon, Focus Meter System, and PLA Battle Styles online. If you get an error with the Script that can not be reproduced offline, please report it to me. But I am not fixing any errors with these scripts themselves.
 
1,680
Posts
8
Years
  • Age 23
  • Online now
Mini update that adds some optional requirements as PLA Battle Styles and Focus Meter System must be loaded before the cable club, so that it can patch a fix so online battles can work.
If you downloaded it between the last post and now, redownload it.
 
1,680
Posts
8
Years
  • Age 23
  • Online now
The RecordMixer now has a "prepareData" property, to set up variables before they are written or parsed.

A new RecordMixer example has been added to the thread, an implementation of Gen 2's Mystery Gift feature.

The v16\17\18 version of the script was missing the Event that triggered when the online trainer type was changed. The feature has also been documented in the user manual.
 
Back
Top