1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. GTA Network forum is now in archive mode.

Tutorial: Setting Up a Development Environment on macOS

Discussion in 'Tutorials/Documentations' started by SnowDog, Sep 30, 2016.

  1. SnowDog

    SnowDog Member

    Messages:
    18
    Likes Received:
    10
    Joined:
    Aug 9, 2016
    I've noticed there have been a few people asking about this topic in the Discord server, so I figured I would post a tutorial to avoid having to explain the process over and over again.

    Prerequisites
    Setting up your development environment for GTANetwork scripting is quite easy on macOS. However, there are a few things you will need before you get started.
    The installation of both applications are automated and install like any other application on macOS. Mono has no graphical interface so you will not see it in Launchpad or your applications after installing.

    If you are running OS X El Capitan or later, you will need to run this command in your terminal after installing mono before attempting to use it:
    Code:
    export PATH=/Library/Frameworks/Mono.framework/Versions/Current/bin/:${PATH}
    Without going into too much detail, you basically need to perform that command or the mono command in your terminal will not be found when you attempt to run the server executable later.

    Setting Up The Project
    Before you setup the project in Xamarin Studio, make sure you have an appropriate directory to place your projects in. I created a directory called Projects in my home folder. Also be sure you have extracted the GTANetwork server files somewhere. For this tutorial, my server files will be extracted to ~/Downloads/server.

    [​IMG]

    Launch Xamarin Studio. You will be greeted by a welcome screen with recent projects listed on the left-hand pane. At the top of the left-hand pane there is a "New Solution" button. Click this to create a new project and solution. The project type you need to select is a .NET Library (C#).

    [​IMG]

    On the next screen it will ask you to name your project and select the location of it. As a practical example, I have named my project StuntServer and placed it in my Projects directory I created earlier.

    [​IMG]

    Now that the project is created you should have an empty class inside of a namespace named after your project. The last thing we need to do before we dive into scripting is reference the GTANetwork API libraries. You can do this by right-clicking the References section on the left-hand pane of your project and clicking "Edit References..."

    [​IMG]

    Select the .NET Assemblies tab and click the "Browse" button. Browse to the folder where you extracted your server files and select both the GTANetworkServer.exe and GTANetworkShared.dll.

    [​IMG]

    After they are imported, make sure the check box next to both of them is checked. They should both show in the "Selected References" section of the window as shown below. Please ignore the duplicates in my list as they were from another project.

    [​IMG]

    Now be sure to place the using lines at the top of your .cs file to access the namespaces of the libraries you just referenced. You also need to extend the Script class in any class you wish to use the API in. You can do this by adding : Script at the end of any new class as shown below. I also renamed my main class to Gamemode.

    [​IMG]


    Now you're ready to start scripting! For this example, we'll use the API to print a "Hello World!" string to our server console. This code is placed in the constructor of our class, which is ran when the script is first called. However, for most cases, you will want to call any code you want ran when the resource is loaded using the onResourceStart event. We just kept it simple for this example.

    [​IMG]

    There are a lot of different ways you can organize your project and your GTANetwork resources. Personally, I find it easiest to split my project up into different classes within the project, based on functionality, and then compile it to a DLL before placing it into my GTANetwork resource folder. You can also copy over the C# files (.cs) directly from the project into the resource folder and run them that way. Just be sure they are all listed in your resource meta file properly. More information on creating a new resource and meta file can be found here.

    For this example, I created a new resource folder and meta file and copied over my finished Gamemode.cs file. Now I can run the server using the mono command in the terminal, and see my "Hello world!" string print.

    [​IMG]
    As you can see, my script worked perfectly and the GTANetworkServer.exe is running flawlessly under macOS.

    Conclusion
    Setting up a development environment on macOS is fairly simple and very similar to using Visual Studio on Windows, aside from having to run the executable through mono. There are, of course, other ways to go about it such as using a simple text editor and creating .cs files directly. Visual Studio and Xamarin Studio are nice because Intellisense with the library references are extremely convenient when referencing methods in the API.

    If you have any questions, feel free to ask in the thread and I will do my best to help. Have fun scripting!
     
    Lowi, Trust37, Kemula and 2 others like this.
  2. Kemula

    Kemula Active Member Language Board Moderator

    Messages:
    86
    Likes Received:
    26
    Joined:
    Aug 6, 2016
    Really helpful for those who works on a Mac :=D Thanks
     
  3. Trust37

    Trust37 Well-Known Member

    Messages:
    181
    Likes Received:
    49
    Joined:
    Sep 6, 2016
  4. SnowDog

    SnowDog Member

    Messages:
    18
    Likes Received:
    10
    Joined:
    Aug 9, 2016
    Trust37 likes this.
  5. Cyril

    Cyril New Member

    Messages:
    1
    Likes Received:
    0
    Joined:
    Oct 1, 2016
  6. izcream

    izcream Member

    Messages:
    8
    Likes Received:
    0
    Joined:
    Jul 9, 2017
    i run GTA server with mono but got this error
    i try use blank gta:n blank gt-mp server but it's still got same error
    my mono version is 5.0.1.1
    osx sierra 10.12.5
    vs 2017

    how do i solve it? Thanks

    [​IMG]
     
  7. -Andreas

    -Andreas Well-Known Member

    Messages:
    172
    Likes Received:
    25
    Joined:
    Sep 29, 2016
    If you're trying to get support for an issue related to GT:MP you should use their forums instead..
     
  8. izcream

    izcream Member

    Messages:
    8
    Likes Received:
    0
    Joined:
    Jul 9, 2017
    Sorry i try to all both gta:n and gt-mp all error same
    but now i can solve this problem. just downgrade mono to 4.3

    Thanks for all advice
     
  9. MeDead

    MeDead Member

    Messages:
    16
    Likes Received:
    0
    Joined:
    May 27, 2017
  10. izcream

    izcream Member

    Messages:
    8
    Likes Received:
    0
    Joined:
    Jul 9, 2017
    i update to mono 5.4 it still error but when i downgrade mono to 4.3 its work

    thanks
     
  11. MeDead

    MeDead Member

    Messages:
    16
    Likes Received:
    0
    Joined:
    May 27, 2017
    im using mono 5.0... no problems with both systems
     
  12. izcream

    izcream Member

    Messages:
    8
    Likes Received:
    0
    Joined:
    Jul 9, 2017
    can u explain me more when i used 5.0 i got winsock error
     
  13. izcream

    izcream Member

    Messages:
    8
    Likes Received:
    0
    Joined:
    Jul 9, 2017
    solve it buy install mono 4.8.2 in cli and 5.0.11 for vs-mac.

    Thanks all for helping my issue clap~~
     

Share This Page