The RPG Maker Resource Kit

RMRK General => General Chat => RMRKMon => Topic started by: Roph on April 22, 2014, 05:41:42 AM

Title: RMRKMon JSON API
Post by: Roph on April 22, 2014, 05:41:42 AM
Not sure if anyone will use this, but whatever. Here's a method to retreive a user's data from RMRKMon in JSON format (http://en.wikipedia.org/wiki/Json).

JSON Encoder/Decoder (http://rmrk.net/index.php/topic,45213.0.html)s for RMVXA exist, maybe someone would like to make a pokemon themed game for the next GIAW that lets RMRK users play with their own pokemon?  :drsword:

Download RMRKMon Images (including pokemon graphics etc) here (http://rmrk.net/index.php/topic,49014.msg560065.html#msg560065).

[edit]

Dat documentation:

Pokemon Data Dump

Attached to this post (http://rmrk.net/index.php?action=dlattach;topic=49014.0;attach=29135) you'll find a .json dump of RMRKMon's pokemon info. This includes each pokemon's name, type (fire, steel etc), appearance chance rate, evolution from/to paths and version affinity. It also includes a description of the type array we use (1:Bug all the way to 18:Water), as well as the IDs, names and colours for our Versions (tyria/lisera).

This data is static so you should simply download it and reference it alongside your project. However, occasionally we may tweak chances and eventually we'll add newer generations of pokemon. If you care to be up to date after such changes, you can grab a fresh dump ( :drsword: ) right here (http://rmrk.net/pokemon/api.php?pokedump;raw).

Notes On Data

Pokemon IDs / Shininess
As a collecting / trading minigame, RMRKMon stores pokemon in a trainer's profile literally as a list of pokemon IDs - comparable to a list of trading cards owned. Pokemon do not have unique entries and cannot have unique attributes assigned to them (as if they were real pokemon with levels, names, moves, genders, forms and so on). The only exception to this is shiny status. A shiny pokemon is represented by an additional decimal point. So for example, Pikachu is 25. Shiny pikachu is 25.3.

I would suggest creating a function in your script/app that simply uses floor, intval, round, or some other similar function and compares the result to the input to check if a pokemon is shiny or not. In PHP, RMRKMon's boolean is_shiny() function is this:

Spoiler for:
function is_shiny($v) {
    $shinytest = floor($v);
   if ($shinytest != $v) return true;
   else return false;
}

Data that may not exist
While all trainers are RMRK members, not every RMRK Member is a trainer. Members automatically get a trainer profile created for them upon their first encounter with a pokemon. A trainer profile is created also in the event that a pokemon is gifted to a user with no profile. Because of this, even if a trainer profile exists, you cannot be sure that it has any owned pokemon or pokedex entries.

Trainers always have a trainer picture set (by default, 1.gif), but favourite pokemon are optional. As are the additional favourite pokemon. A user is not forced to choose 5 extra favourites either, they may choose just one if they wish. However, a user cannot choose extra favourite pokemon until they have a main favourite pokemon.

Inventories
Assuming an active trainer, the trainer will have three similar but distinct inventories. First is pokemon, which is simply the pokemon they own. Duplicates are allowed, as are shiny pokemon.

Next is seen, which uniquely logs each pokemon encountered. Shiny pokemon are counted seperate to their normal variants, but no duplicates are allowed.

Dex is only made up of pokemon the user owns or has owned at some point. As in the games, the dex ignores shiny status. Capturing or receiving a shiny Mewtwo will place a 150 in a user's pokedex.

Discrepancies
Capture and encounter events were not always logged, thus some trainers who were quite active at the start may have total_encounters and total_catches that are impossibly low compared to their current inventories. As time goes on this becomes less of an issue - especially with the introduction of trading (which increases neither tally).

Querying User Data

Identifying which user's data you want can can be done through two methods - either their RMRK account ID, or their username. The request parameter is different depending on each one.

A little note for JSON decoders that don't quite meet the spec (such as the RMVXA one by game_guy) - while JSON allows whitespace to make it human readable, some decoders don't account for this and only properly decode json if it's all on a single line. You can force such output from the RMRKMon API with a raw parameter. e.g. http://rmrk.net/pokemon/api.php?trainer=273;raw

ID Request: trainer parameter
http://rmrk.net/pokemon/api.php?trainer=273
Name Request: user parameter
http://rmrk.net/pokemon/api.php?user=Roph

While it's more user friendly to ask a user for their name than give their ID, inside your game/application you should try to avoid making user requests. This is because usernames may change, or new users may exist with conflicting display names (the API selects the first match found). If your game or app is making a one off request then fine, but if you plan to pull updates in the future, save the id from the response and then use it for subsequent trainer requests.

Response Structure

Error Responses
You should check for the existence of an "error" key before proceeding. If an error is encountered, ONLY the error key is returned and no extra information is (or can be) output. The error key has 2 entries, [error][code] (Integer) and [error][description] (String).

1: Missing Parameters, e.g. you made no request or your misspelled one.

2: Trainer Does Not Exist. All trainers are RMRK Members, but not all RMRK Members are trainers.

3: Email Lookup Forbidden. Usernames only are allowed for user requests.


Normal Response

response_time (Integer) | Always Set
UNIX Timestamp of when this response was generated. Use it for caching, or to make sure your data is within a certain age boundry.


name (String) | Always Set
Their RMRK Username


id (Integer) | Always Set
Their RMRK Account ID


gender (String) | Always Set, Default: null
Their RMRK Account's gender setting. Male/Female/null


member_since (Integer) | Always Set
UNIX Timestamp of their RMRK registration


trainer_since (Integer) | Always Set
UNIX Timestamp of their first sighting (and thus when they became a trainer)


last_login (Integer) | Always Set
UNIX Timestamp of when they were last active on either RMRKMon or RMRK (whichever is most recent)


last_caught (Integer) | Always Set, Default: 0
UNIX Timestamp of last pokemon capture receival of a gift


is_online (Boolean) | Always Set
Online status, duh


page (String) | Always Set
URL of their RMRKMon trainer page, eg http://rmrk.net/pokemon/?trainer=273


profile (String) | Always Set
The URL of their RMRK profile, eg http://rmrk.net/index.php?action=profile;u=273


picture (Array) | Always Set
Images related to this user


                                        id (Integer) | Always Set, Default: 1
                                        The number of which trainer pic they are using


                                        href (String) | Always Set
                                        URL to said trainer picture (though you should display a local copy)


                                        avatar_href (String) | Always Set, Default: (RMRK's "no avatar" image)
                                        URL to their forum avatar. Typically 105x150, though may be smaller or in some cases larger.


fave (Numeric) | Optional
The ID of their favourite pokemon, if any.


extrafave (Numeric Array) | Optional
An array of up to 5 extra favourite pokemon. Again optional, though a user cannot choose extra faves without first having a main fave.


total_trades (Integer) | Always Set, Default: 0
A tally of the trainer's completed trades


total_encounters (Integer) | Always Set, Default: 0
A tally of the trainer's encounters on the forum.


total_catches (Integer) | Always Set, Default: 0
A tally of the trainer's successful catch events.


total_pokemon (Integer) | Always Set, Default: 0
A tally of the trainer's pokemon inventory


badges (Incremental Array) | Always Set, Default: Empty Array
Contains as many sub-arrays as the user has badges, each having 2 entries. [0] being the badge's "ID" (aka its filename without the .png),[1] being its description.


total_seen (Integer) | Always Set, Default: 0
The number of unique pokemon the trainer has seen. For instance, seeing a blastoise for the first time and then seeing 5 more blastoises would still only increase this by 1.


total_dex (Integer) | Always Set, Default: 0
How many pokedex entries this trainer has.


pokemon (Array) | Optional
The user's current pokemon inventory


                                        string (String) | Always Set
                                        A comma separated string of their inventory.


                                        raw (Numeric Array) | Always Set
                                        An array of their inventory by ID


                                        named (Associative Array) | Always Set
                                        An ID => Name array of their inventory. For example, [pokemon][named][25.3] = Pikachu (Shiny).


seen (Array) | Optional
Pokemon this user has seen


                                        string (String) | Always Set
                                        A comma separated string of their sighted pokemon.


                                        raw (Numeric Array) | Always Set
                                        An array of their sighted pokemon by ID


                                        named (Associative Array) | Always Set
                                        An ID => Name array of their sighted pokemon. For example, [seen][named][9] = Blastoise.


dex (Array) | Optional
Pokedex entries for this trainer.


                                        string (String) | Always Set
                                        A comma separated string of their dex.


                                        raw (Numeric Array) | Always Set
                                        An array of their dex by ID.


                                        named (Associative Array) | Always Set
                                        An ID => Name array of their dex pokemon. For example, [dex][named][151] = Mew.


                                        percentage (Numeric) | Optional
                                        Their pokedex completion against all pokemon in RMRKMon as a percentage, represented to 2 decimal places. e.g. 29.41

Response Structure Notes

[dex][percentage] is calculated based on all pokemon that exist in RMRKMon, even those that are disabled. So as of this writing, pokedex percentages are based on 720 pokemon in total, even though gens 5 and 6 (#494 and beyond) are disabled.

the [named] parts of the [pokemon], [dex] and [seen] arrays, by being associative, cannot represent duplicate pokemon. This is only an issue with [pokemon][named], as a trainer's seen/dex entries forbid duplicates. If a user owns 10 charizards, only one is in this array as charizard's key ([6]) is in use. Thus, don't iterate or foreach( key=>value ) through the [pokemon][named] array thinking you will be showing their full inventory. Use it for reference.
Title: Re: RMRKMon JSON Data
Post by: Roph on April 22, 2014, 02:10:16 PM
Reference PHP Implementation

Find attached to this post a .zip containing a PHP based reference implementation. Just unzip this and upload it to a PHP-compatible web-server and then visit in your browser. I've uploaded a copy here:

http://rose.roph.eu/rmrkmon/?trainer=Roph

The link above is on a seperate server to the one that RMRK and RMRKMon runs on. It gets its data through the JSON API. All the files and source code behind it are in the .zip :) Feel free to use it to learn more about using such data.
Title: Re: RMRKMon JSON Data
Post by: Roph on April 22, 2014, 05:14:59 PM
RMRKMon Data

Here you can get all the required images you might want to use. RMRKMon specific images (badges, trainers etc) and pokemon image collections in general. RMRKMon has many sets of images, and they are:

RMRKMon Specific: Badges, Bases, Trainers, Types - Grab all of them here (http://dump.roph.eu/rmrkmon/_rmrkmon.zip)

Pokemon Image archives:
Animated BW style (Normal+Shiny 96x96 gif) (http://dump.roph.eu/rmrkmon/anim-bw.zip)
Animated XY style (Normal+Shiny, various resolution transparent gifs) (http://dump.roph.eu/rmrkmon/anim-xy.zip)
Global Link Art, SVG - auto-generated .svg vector graphics (http://dump.roph.eu/rmrkmon/art-global-svg.zip)
Various pre-rendered resolutions of the above global link art, all transparent png: 300x300 (http://dump.roph.eu/rmrkmon/art-global.zip), 900x900 (http://dump.roph.eu/rmrkmon/art-global900.zip), 2000x2000 (http://dump.roph.eu/rmrkmon/art-global2000.zip)
Ken Sugomori Art (Various resolutions, transparent png) (http://dump.roph.eu/rmrkmon/art-ken.zip)
CSS Sprite Sheets + required .css (http://dump.roph.eu/rmrkmon/css-sprites.zip) - basic instructions are included in the .css file
Icons (Normal+Shiny 32x32 transparent png) (http://dump.roph.eu/rmrkmon/icons.zip)
Named cards (Normal+Shiny 96x110 png) (http://dump.roph.eu/rmrkmon/named.zip)
Static back sprites (Normal+Shiny 96x96 transparent png) (http://dump.roph.eu/rmrkmon/static-back.zip)
Static front sprites (Normal+Shiny 96x96 transparent png) (http://dump.roph.eu/rmrkmon/static-front.zip)

Alternatively, you can grab ALL the above images in one giant file (http://dump.roph.eu/rmrkmon/_rmrkmon_allinone.zip).
Title: Re: RMRKMon JSON Data
Post by: exhydra on April 24, 2014, 01:16:06 AM
I am tinkering with something, yes. I barely have any knowledge of Pokemon, and no real desire to create a Pokemon game by myself ... but creating a script to communicate with the backend seems fun. I wish the HTTP API was available natively for Ruby within RPG Maker ... ah well. Time to do everything by hand.

Also, kind of a minor aspect, but could the gender of the trainer be made available through JSON data as well (to preemptively answer the 'are you a boy or girl' question, perhaps)?
Title: Re: RMRKMon JSON Data
Post by: strike on April 24, 2014, 04:22:05 AM
careful or roph will call you cis scum. :V
Title: Re: RMRKMon JSON Data
Post by: Roph on April 24, 2014, 05:33:26 AM
Hmm. I could go from the RMRK account's gender selection (if any), or it could be figured out from the trainer picture. Some users have conflicting entries.
Title: Re: RMRKMon JSON Data
Post by: Roph on April 24, 2014, 09:52:09 AM
Also wow, passing RMRKMon's PNGs through one of those optimizer tools (followed link in your sig), on average they're all being shrunk by ~35% ;8
Title: Re: RMRKMon JSON Data
Post by: exhydra on April 24, 2014, 06:15:23 PM
Yeah, surprised me how much metadata and other information could be stripped and still maintain the quality of the PNG.  :o    Can save quite a bit of space.
Title: Re: RMRKMon JSON Data
Post by: Roph on April 25, 2014, 04:23:30 PM
I should add, picture => id refers to the trainer picture they've chosen in RMRKMon. Always set, 1 by default. I did start on a fancy documentation post on my local copy of RMRK, but it started to look wrong with longer descriptions, and SMF's bbcode tables aren't so fun.

Trainerpics aren't included in that RMRKmon image archive, so here they are attached:
Title: Re: RMRKMon JSON Data
Post by: Roph on April 25, 2014, 05:46:26 PM
Added some proper documentation to the first post :zwink:
Title: Re: RMRKMon JSON Data
Post by: exhydra on April 25, 2014, 07:53:57 PM
Awsomeness. Now, if I can just cobble together a front end ...
Title: Re: RMRKMon JSON Data
Post by: PhoenixFire on April 25, 2014, 10:35:32 PM
hmm... this really could be an interesting idea if done properly..
Title: Re: RMRKMon JSON Data
Post by: exhydra on April 26, 2014, 02:01:23 AM
Success! Now to tinker around some more ...

(https://dl.dropboxusercontent.com/u/34748352/Pictures/RMRK/rmrkmon-webconnect.png)
Title: Re: RMRKMon JSON Data
Post by: exhydra on April 26, 2014, 08:03:02 AM
What is the proper content type for JSON? I have been trying 'application/json' and 'application/javascript', but neither seem to be working (or I am doing something incorrect). I keep getting JSON in HTML format.
Title: Re: RMRKMon JSON Data
Post by: Roph on April 26, 2014, 08:26:44 AM
application/json: http://en.wikipedia.org/wiki/JSON#MIME_type

This is what's sent from RMRK:

(https://rmrk.net/proxy.php?request=http%3A%2F%2Fpuu.sh%2F8nXAq.png&hash=b0aa9fcd612d9ed4198f24f539e3cbb03925b5a8)

I can try changing it to something else if you like?
Title: Re: RMRKMon JSON Data
Post by: exhydra on April 26, 2014, 01:21:58 PM
No, just means that the content type is not being passed along as it should be. Bah ...
Title: Re: RMRKMon JSON Data
Post by: Roph on April 26, 2014, 01:28:12 PM
Hmm. Either way, it's just plain text. That RMVXA JSON script just appears to interpret a given string as JSON. What would content-type have to do with that?
Title: Re: RMRKMon JSON Data
Post by: Roph on April 26, 2014, 04:19:01 PM
Just added a gender entry to the response :)
Title: Re: RMRKMon JSON Data
Post by: exhydra on April 26, 2014, 05:03:04 PM
Hmm. Either way, it's just plain text. That RMVXA JSON script just appears to interpret a given string as JSON. What would content-type have to do with that?

Well, what happens is that extra line feeds and padding is added to the JSON, and the JSON decoding script chokes. For the script to work, everything needs to be on a single line, basically ... no formatting. Now, I am not entirely sure ... is that because of the content type, or is that something that is done for human readability?

EDIT: Now, I could just lop off the line feeds and probably remove the padding ... but I figured something was wrong on my end to make that happen in the first place.
Title: Re: RMRKMon JSON Data
Post by: Roph on April 26, 2014, 05:10:38 PM
Ah, that's on my end. I'm using an option in PHP's json encoder to make it human readable. Whitespace shouldn't interfere with anything though :o

Blame game_guy for his non-JSON-compliant script :P

I just added an option to disable any whitespace formatting with a raw parameter. Just add ;raw on the end.

http://rmrk.net/pokemon/api.php?trainer=273;raw
http://rmrk.net/pokemon/api.php?pokedump;raw
Title: Re: RMRKMon JSON Data
Post by: exhydra on April 26, 2014, 07:55:44 PM
Is there any upper limit on characters allowed for user names on the forums?
Title: Re: RMRKMon JSON Data
Post by: Roph on April 26, 2014, 08:08:36 PM
Somewhere yes. I made a user with the longest name possible on my local SMF install, and it ended up as "the really long named user derp dongs ham sandwiches with mu"
Title: Re: RMRKMon JSON API
Post by: exhydra on April 28, 2014, 06:54:55 PM
Hmm, the outputted error messages are ignoring the 'raw' option and coming out formatted.
Title: Re: RMRKMon JSON API
Post by: Roph on April 28, 2014, 06:56:37 PM
Ah, of course. I do those manually. Will fix =o
Title: Re: RMRKMon JSON API
Post by: Roph on April 28, 2014, 06:59:28 PM
Fixed :D http://rmrk.net/pokemon/api.php?trainer=99999999
Title: Re: RMRKMon JSON API
Post by: exhydra on April 28, 2014, 07:25:23 PM
Hurrah!  :D
Title: Re: RMRKMon JSON API
Post by: Roph on April 29, 2014, 05:26:29 PM
Won't be available just yet since I need to finish some underlying functions, but soon both a user's badges (if any) and the time a response was generated will be included in the responses :)
Title: Re: RMRKMon JSON API
Post by: Roph on May 02, 2014, 12:48:59 PM
Added badges and a timestamp to responses. Also sorted out three image archives, find them in the third post  ;8

I'll also add which base image a pokemon has been assigned into the pokedump  :)
Title: Re: RMRKMon JSON API
Post by: exhydra on May 02, 2014, 09:22:02 PM
What characters are not allowed to be used during account registration? I am trimming the amount of letters on the name entry screen.
Title: Re: RMRKMon JSON API
Post by: Roph on May 02, 2014, 09:26:42 PM
The list is quite small. Or rather, I mean that SMF allows unicode characters in usernames. I don't know what it does/doesn't support, but it's far beyond your simple alphanumeric with a few áccénted characters thrown in. 99% of users only use alphanumeric with some punctuation sprinkled here and there though.

Why do you have a name entry screen? :o
Title: Re: RMRKMon JSON API
Post by: exhydra on May 02, 2014, 09:31:06 PM
The player can enter their RMRK user name in-game instead of their user id, basically. I honestly doubt I could accommodate user names larger than thirty or so characters, but eh.
Title: Re: RMRKMon JSON API
Post by: Roph on May 02, 2014, 09:33:34 PM
May as well just allow alphanumeric and basic punctuation, like the games. Currently, every single trainer falls under these boundries  =o

[edit] You should join IRC, faster turnaround ^_^
Title: Re: RMRKMon JSON API
Post by: exhydra on May 03, 2014, 09:14:00 AM
(https://dl.dropboxusercontent.com/u/34748352/Pictures/RMRK/rmrkmon-nameentry.png) (https://dl.dropboxusercontent.com/u/34748352/Pictures/RMRK/rmrkmon-queen.png)
(https://dl.dropboxusercontent.com/u/34748352/Pictures/RMRK/rmrkmon-exhydra.png) (https://dl.dropboxusercontent.com/u/34748352/Pictures/RMRK/rmrkmon-roph.png)


Extremely basic, at the moment ... not to mention the horrific, ugly code. But, I will continue to tinker with everything.
 
Yes, the game window is that small. No, I am not entirely sure why; I thought operating in a smaller area would be interesting. The background parallax scrolls diagonally. Neither trainer or pokemon is animated.
Title: Re: RMRKMon JSON API
Post by: Roph on May 03, 2014, 09:38:37 AM
 :oomg:
Title: Re: RMRKMon JSON API
Post by: Roph on May 03, 2014, 05:03:48 PM
I should also add, what's interesting about the string parts of a user's inventories is that it could be used to figure out roughly the chronological order of them acquiring pokemon.

The string is how a user's pokemon is stored in the database, and captures or receiving a gift/trade just add the pokemon on the end. Removing pokemon either through releasing or losing through a trade plucks the relevant IDs from their string, but keeps the order.
Title: Re: RMRKMon JSON API
Post by: exhydra on May 07, 2014, 11:06:44 PM
Code is still somewhat of a mess as I have been adding whatnot in, and there is no title graphic as of yet ... but here is a download for the current incarnation of the RMRKMon ... 'RPGM client', I suppose. Not certain if I will continue on with an actual game, as I was mostly interested in the coding portion.

EDIT: The 'trainer name' is just the user name on the forum. Also, if you hit 'A' on the keyboard while in the name screen, you can paste a name in from the Windows clipboard.

Download 0.6 (https://db.tt/OK9xRjYR)
Title: Re: RMRKMon JSON API
Post by: Roph on May 08, 2014, 12:05:48 AM
 :oyayy: