• Do not use Discord to host any images you post, these links expire quickly! You can learn how to add images to your posts here.
Geolocating the Player

Geolocating the Player 2017-03-06

Pokémon Essentials Version
v16.2 ➖
What's this?
This is a simple script that downloads information from an API to geolocate the player, since the one included in Pokémon Essentials died sometime ago.

Usage
Place in a section above Main in your Script Editor:
Code:
Expand Collapse Copy
def getLocation
  # See http://ip-api.com/docs/api:returned_values#selectable_output
  # for other returned values
  query=pbDownloadToString("http://ip-api.com/line/?fields=status,country,city")
  formatted=query.split(/\n+/)
  if formatted[0]=="success"
	Kernel.pbMessage(_INTL("You came from {1}, {2}.",formatted[2],formatted[1]))
  end
end
Use 'getLocation' in a script call.

Design Notes
As far as I'm aware, only Vivillion forms need to rely on this, but you can be creative with it!

Instead of using it in a text message, you could also store the values for future use, all inside the script. The values are stored into an array, that will look something like:
Code:
Expand Collapse Copy
formatted=[status,country,city]

Where "status" will be either "success" or "fail", if the API failed to retrieve the information. The script will not print the information in a message unless the API returns "status" as "success". You should also be doing that all times, and stop storing the remaining (faulty or non-existant) information.

That said, you can store 'formatted[x]' at will instead of printing it into a text message. Where X is 1 for Country, 2 for City, 0 for Status. See the API's Documentation for other possible fields it can return.
Credits
h7zpBm0.png

Please give credit if used to:

Mr. Gela

Please do not redistribute this anywhere resource anywhere else. If you wish to share this, link to this site.

xa1A2iB.png

Por favor da créditos si lo utilizas a:
Mr. Gela

Por favor no redistribuyas este recurso en ningún otro lugar. Si quieres compartir esto, utiliza un enlace a este sitio.
Author
Mr. Gela
Views
1,578
First release
Last update

Ratings

0.00 star(s) 0 ratings

More resources from Mr. Gela

Back
Top