This is my first tutorial, so, i'll try to do my best.
What you will need to do this (C2 included):
- Windows Notepad, Notepad++ or any notepad program that support and recognize and let you save as PHP file.
Before starting, i'll let you know: i am brazilian, so, the objects name are in portuguese. The only word i use in portuguese in this tutorial is 'pegaip' that means 'getip' in english, ok?
With that said/wrote, let's go:
As image show, you must create an object that, when players click, game get their IPs. It can be a login button or something like that. In this tutorial, object is called 'pegaip'.
An Ajax object is a must-need.
The text object is optional and you can do other things with IP that you get, like using an Ajax action to send it to your MySQL database or to your server as a text log file.
So, basically what you need to do in Construct 2 is:
- Create an On Clicked Event for 'pegaip' object.
- Create an Ajax Request URl action on it, with specified tag and URL.
On that part, i will specify better:
Tag can be anything that you want to it be. 'But exactly what?' You can ask me. Well, all Ajax actions must be very well setup or any mistake, you can mess up all your online data. So, be very careful when naming it!
In our case, it will be 'pegaip' (explained early why of that name and what it means in english) and it will identify what we are wanting to get from our database.
With that explained, lets go on explain what URL is for this.
The URL will contain your website database file path. Where say "(...)/pegaip.php" is the PHP file that we will get the necessary stuff to get players IP. The PHP file can named as you want, BUT, put the EXACT PHP file name or you will get error!
So, in our case, will be "http://polargames.com.br/pegaip.php".
With that done, lets go for the next event:
- Create an Ajax On Completed event ( remember the tag mentionated before? you will put it's name here too!) put the tag name we created before.
- Create a Text Set Text action where in Text, you put Ajax.LastData. WAIT! Why put that, right? It's because you always works with the Last Data Ajax was using (it don't save all data it work with, just the last one).
Note: You can create another action, like Ajax one, but, how the purpose of this tutorial is to be simple and show how to get IP from players, will be like that.
With that said/wrote, let's continue:
To get players IP, your C2 game is complete, BUT, only by the game itself, you won't be able to get the IPs! For that, you will have to use a PHP file! PHP do that work for you! ;]
Create a PHP file with your favorite notepad program with code show on image, that is:
Thats it! I don't know that much about PHP, just the basic of the basic, so, i can't tell how exactly this code works. But, if someone, in comments, explain how it works, i'll put here with the right credits! But also have some youtube tutorials that explain how PHP works, so, you can search there also! =]
By the way, this tutorial was only possible thanks to a friend that showed me how to do this and his name is Willian Zarpellon! THANKS A LOT, DUDE!
I hope you all enjoy this tutorial and make nice games! =]