1. Before you ask anything, make sure that you've read the FAQ

Tutorial The Basics of Modding in Zerahypt.

Discussion in 'Modding Tutorials' started by Magiichan, May 26, 2015.

  1. Magiichan

    Magiichan Administrator

    • Admin
    • Coder
    Joined:
    May 25, 2015
    Messages:
    243
    Likes Received:
    151
    ~[The Basics of Modding]~
    Before we start making the mod, make sure that you've downloaded all the files from the sticky thread [Required Mod Assemblies].

    Start Visual Studio & Start a new project.
    (File>New>Project)

    Make it a Visual C# Class Library file & name it to Mod_<Insert Name> (ex: Mod_DisplayText)
    Then remove all the generated code from the class.
    [​IMG]

    In order to implement any code into the game, we'll need a reference to the game engine's assembly.
    These files can be found at ".../Zerahypt/Zerahypt_Data/Managed"

    Since we're making a simple mod, we'll only have to add the UnityEngine & Mod Foundation DLL.
    Right Click on References in the Solution Explorer>Add Reference
    [​IMG]

    Remove all the code in ur class & replace it with the following:
    PHP:
    using System.Collections;
    using UnityEngine;

    public class <
    InsertClassName> : MonoBehaviour
    {

    }
    [​IMG]

    Now we want to specify to the modloader that we want to run this script.
    We do this by adding the [Mod_Instance] attribute from Mod_Foundation.
    [​IMG]

    Now let's set the correct build settings.
    Go to Project>Properties
    > Make sure you know where the build location is set.
    > Set the target framework to .NET Framework 2.0 (Unity uses this version)
    > Save all the scripts
    > Press F6 to compile the scripts to ensure that there are no errors.
    [​IMG]

    Now lets add code to display text!
    This goes in between the brackets of the class.
    PHP:
        void OnGUI()
        {
            
    GUI.color Color.red;
            
    string text "Mod Loaded! :D";
            
    GUI.Label(new Rect(00Screen.widthScreen.height), text);
        }
    [​IMG]

    Now rebuild/recompile the code & go to the output folder.
    There should be a DLL file with the name of ur Mod.
    Move this file into the Zerahypt/Zerahypt_Data/Mods/ folder.
    Now run Zerahypt & let the magic happen!
    [​IMG]
     
    Last edited: Jun 5, 2015
  2. leddy231

    leddy231 New Member

    Joined:
    May 26, 2015
    Messages:
    2
    Likes Received:
    2
    ooooooooo modding? This I like! Going to try to make something with this tomorrow.
     
    Magiichan likes this.
  3. Gwonam

    Gwonam Member

    Joined:
    May 26, 2015
    Messages:
    8
    Likes Received:
    4
    Very well-structured and helpful! The only modding I've done before is of N64 games, but I can see myself giving this a shot sometime.
     
    Magiichan likes this.
  4. Magiichan

    Magiichan Administrator

    • Admin
    • Coder
    Joined:
    May 25, 2015
    Messages:
    243
    Likes Received:
    151
    @leddy231 @Gwonam
    Thank you guys, I'll gradually make more complex mod tutorials!
     
    Catblaster likes this.
  5. Gwonam

    Gwonam Member

    Joined:
    May 26, 2015
    Messages:
    8
    Likes Received:
    4
    @Magiichan
    Not at all! I especially like the use of gifs, it makes things very easy to understand.
     
  6. MechanizedIT

    MechanizedIT New Member

    Joined:
    May 27, 2015
    Messages:
    3
    Likes Received:
    2
    @Magiichan Thanks for the tutorial, its very well done. I can't wait to dive in and see what is possible.
     
  7. Catblaster

    Catblaster Veteran Member

    Joined:
    May 25, 2015
    Messages:
    138
    Likes Received:
    67
    I did not know this and will delete le post

    Still nice and clean tutorial, didn't get any feet stuck in fridges during the process

    All me being stupid aside,
    Is there a way to keep things going while switching levels/maps?
    Every time you load into a new map or do the shift + 0 thing (or die by jumping off) The text, and whatever one might put in the mod, Isgone
     
    Last edited: May 27, 2015
  8. Magiichan

    Magiichan Administrator

    • Admin
    • Coder
    Joined:
    May 25, 2015
    Messages:
    243
    Likes Received:
    151
    PHP:
        void Awake() {
            
    DontDestroyOnLoad(this.gameObject);
        }
     
    Last edited: Jun 10, 2015
    Catblaster and Azai like this.
  9. Catblaster

    Catblaster Veteran Member

    Joined:
    May 25, 2015
    Messages:
    138
    Likes Received:
    67
    Senpaiwa

    thanks.
     
    Last edited by a moderator: Jun 10, 2015
  10. BluetoothBoy

    BluetoothBoy Well-Known Member

    • Coder
    Joined:
    Jun 3, 2015
    Messages:
    74
    Likes Received:
    45
    Just did a successful build of the above (although I had to use Unity's version of MonoDevelop, as VS didn't have all the correct project options). Now that I have it working, it's time to do some fun stuffs!

    Also, is it possible to load in custom models? And if so, how? This is my first time modding a game that uses the Unity engine.
     
    Magiichan likes this.
  11. Magiichan

    Magiichan Administrator

    • Admin
    • Coder
    Joined:
    May 25, 2015
    Messages:
    243
    Likes Received:
    151
    Yeah, but it's very annoying.
    The documentation states that u need to use asset bundles.
    But since they are quite outdated, you'd probably be better off using a custom library for it.
    I'll see if I can make a tutorial for it =P

    Great to see that people are also doing stuff :3
     
  12. BluetoothBoy

    BluetoothBoy Well-Known Member

    • Coder
    Joined:
    Jun 3, 2015
    Messages:
    74
    Likes Received:
    45
    That would be great if you could. Also, is there any way for me to use UnityScript (which I'm far more familiar with)? If not, I can just use C# - not too hard to get used to.
     
  13. Magiichan

    Magiichan Administrator

    • Admin
    • Coder
    Joined:
    May 25, 2015
    Messages:
    243
    Likes Received:
    151
    Sorry I don't know how you'd go about compiling a unityscript/javascript file.
     
  14. BluetoothBoy

    BluetoothBoy Well-Known Member

    • Coder
    Joined:
    Jun 3, 2015
    Messages:
    74
    Likes Received:
    45
    It's ok - I realize that (especially from a modding perspective) UnityScript is more limited than C# anyway. I'll just have to get used to the new syntax/requirements. :P
     
  15. Magiichan

    Magiichan Administrator

    • Admin
    • Coder
    Joined:
    May 25, 2015
    Messages:
    243
    Likes Received:
    151
    Don't worry, it isn't that much different :o
     
  16. BluetoothBoy

    BluetoothBoy Well-Known Member

    • Coder
    Joined:
    Jun 3, 2015
    Messages:
    74
    Likes Received:
    45
    Yeah, I mean I've done a little, so it's not a stretch. ;)

    Also, I am currently working on a console that will be useful for others to create mods in the future. Some of the things it will display:

    World coordinates
    List of currently-loaded objects
    Level names
    List of components attached to a specific object
    Unity version
    (Syrsa needs to update! We'll get things like shadows if he does!)

    These will be accessible via a command in the console. Any other suggestions for useful commands?
     
    Magiichan likes this.
  17. Magiichan

    Magiichan Administrator

    • Admin
    • Coder
    Joined:
    May 25, 2015
    Messages:
    243
    Likes Received:
    151
    Cool, can't wait to see the progress :3