Tuesday, April 28, 2015

G.U.I Button ARMA 3 Style

I love the ARMA series for one good reason, it allows custom scripts or mods. It's a sandbox game that is based off my personal career in the National Guard. That skill is combat but enough about me let me tell you my history with this game. I started to play this game because I remember my late twin brother was playing ARMA Gold and I happen to see ARMA II Combined Ops at Wal-Mart and at that moment I decided to  pick it up. I was trying to get closer to my brother after his death in Afghanistan. Well it was the best decision I made because it gave me the desire to code and develop. I found the gift of developing and I have been increasing my development skills ever since. So my blog will basically be my personal development with Java and other languages but also ARMA 3 content. So to get back on course I want to talk about ARMA's use of G.U.I's. With ARMA I feel it is harder to learn G.U.I.'s or dialogs as the game calls it. I took me weeks to learn how to create a button and I hope by sharing my success others will fare a lot easier than me. I'm going to list the steps to get one button to write a message on screen.
1. Start up ARMA 3 and select Editor and select any map it doesn't matter and create a new mission.

2. Save the mission. It can be anything you want but remember the name.

3. Once you save it, place one playable unit down and click preview.

4. Inside the game press escape and look for GUI EDITOR on the bottom and select it.

5. Press escape and you should now be in the GUI EDITOR you should have a grid in front. A few tips, pressing 'H' brings up the help menu and it tells you all the commands needed to operate the editor.

6. Right-click anywhere and a dialog will pop up, select RscButton near the top and watch it appear on your screen.

7. Right-click on that button and another menu pops up and this menu allows you to edit the button to your liking.



8. I'll go through what I've done

  • Class: This is the variable name to refers to this button
  • Text: This will appear on the button
  • Text color: This will be the color of the button.
    • Look at Active color and to see what each value means. It's a RGB scale with Alpha
  • Tooltip: When a mouse hovers over the button a this text will appear.
  • Position type: Always put Safezone, I don't know why but all tutorials I've read say so.
9. Click okay and you're almost ready. Now you have to save your script. But first you have to export your parent classes. This is needed and you'll see why in a minute.  Press 'H' and look for export Parent Class.


As you can see it's Ctrl + P. This will copy information to your clipboard. Alt tab out of the game and open up any text editor preferably Notepad++, and paste the information inside a text document. You should see something like this.


10. Now save this file as defines.hpp Now go back in the game and look for Export to config format. It's Shift + Ctrl + S. This will ask you to name the project and you can name it anything. Once it is saved it will also copy to your clipboard. So open up a new file and paste it.


11. As you can see some of the information I posted in the game is here in the document. Now we have to add a few more lines of code. Look at the next picture and you can see what I had to add to make this button work.

12. I had to make class RJ_Example_Button: RscButton a subclass of class controls which is a subclass of class RJ47_Example. Read the comments in the picture to learn more. Make sure to add action line to the button config. It is important as nothing will happen if you don't define that.

13. Save the file as button.hpp. Now open up the mission folder which it should be in this directory
C:\Users\Ramon\Documents\Arma 3 - Other Profiles\yourusername\missions\RJ47_Example.Stratis
Now this is my file path to my mission and we need to save both defins and button.hpp in this folder.

14. After we saved these files we need to create a new file inside this directory and call it description.ext


These are the files you should have inside the directory.

15. Open up description.ext and add 2 lines of code. The ordering is important.

  1. #include "defines.hpp" 
  2. #include "button.hpp"

16. Now save this file and head back into ARMA 3 and lets spawn the button. Add a pole to the mission and edit the initialization block of the pole and add this code
  • this addAction["Spawn G.U.I.",{createDialog "RJ47_Example";}];

17. Click okay, save it, then preview the mission and head towards the pole and you should see your addAction title show up by looking at the pole. Select this and then boom your button is spawned on the screen. Now nothing will happen until you click your button. Click it and the message will spawn that was defined in the action code in the button.hpp.






This concludes this tutorial.