Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

C# Prototype MMORPG Game. Still in Experimental Stages.

Discussion in 'Works In Progress - Archive' started by GameCode4878, Apr 12, 2016.

  1. GameCode4878

    GameCode4878

    Joined:
    Jan 5, 2016
    Posts:
    173
    I am working to build an MMORPG. In my previous threads, I have given a progress report on how well that is going, and so far it is actually doing good.

    So let me tell you what I am up to... I am trying to create an MMORPG game without using paid for assets. Everything is made from scratch, the codes, scenery, and models are all scratch made. The only exception to the "all scratch made part" is the game's textures. Textures to me, are really hard to make on my own and make look realistic.

    The most unique parts of my game so far are the scratch made codes. I have recieved much help putting them together, but hey, we all started as noobs and needed help. The login system alone is a complicated three part system:

    part 1: The user inputs his username and passcode.
    part 2: The client sends the input to the php files using WWWForms.
    part 3: The php files send the input to the online database and checks to see if the username and passcode are correct. If they are, the php files telll the client to give the go ahead to log the user in.

    As all that happens, at the same time, if the password and username is correct, the username is temporarily stored to player prefs, and the login screen creates the player prefab.

    The player prefab has a script on it that retrieves the username from player prefs. At the same time the username is sent to the database once again to retrieve that player's info, such as their amount of in-game money, the items in their inventory, and their combat level.

    I will continue to update this thread and may even one day post the experimental codes here. Disclaimer: The codes are still in developmental stages, they are not garunteed to work. The login system does work, but is not 100% secured from hackers.

    Leave your comments in this thread if you would like to see me post the expiramental codes.
     
    Last edited: Apr 12, 2016
    GarBenjamin likes this.
  2. GameCode4878

    GameCode4878

    Joined:
    Jan 5, 2016
    Posts:
    173
    Here is the code for the experimental inventory so far:
    note that "Item" is a script that describes all the attributes to the items in the game:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. public class Inventory : MonoBehaviour {
    6.     //Create the inventory class:
    7.     [System.Serializeable]
    8.     public class ItemList {
    9.         public List<Item> items;
    10.     }
    11.     //Create the inventory:
    12.     public ItemList inventory;
    13.     //Create the item the player is holding:
    14.     public Item itemInHand;
    15.     //Create the area for the GUI to appear in:
    16.     public Rect GUIArea = new Rect(0, 0, 0, 0);
    17.     //Is the inventory loaded?:
    18.     public bool invLoaded = false;
    19.     //Is the inventory open?:
    20.     public bool invOpen = false;
    21.     //Is the main menu open?:
    22.     public bool menuOpen = false;
    23.     //Create the inventory's update functions:
    24.     void Update () {
    25.         //Load the inventory if it has not been already loaded:
    26.         if(invLoaded == false){
    27.             //Load the inventory:
    28.             LoadInv();
    29.         }
    30.         //Set invOpen equal to true if the "E" key is pressed:
    31.         if(Input.GetKeyDown(KeyCode.E)){
    32.             invOpen = true;
    33.         }
    34.         //Set invOpen equal to false if the "Escape" key is pressed and if the inventory GUI is open:
    35.         if((invOpen == true) && (Input.GetKeyDown(KeyCode.Escape))){
    36.             invOpen = false;
    37.         }
    38.         //Open the Main Menu if the "Escape" key is pressed when the inventory GUI is closed:
    39.         if((invOpen == false) && (Input.GetKeyDown(KeyCode.Escape))){
    40.             menuOpen = true;
    41.         }
    42.     }
    43.     //Create the GUIs:
    44.     void OnGUI () {
    45.         //Only open the inventory GUI if invOpen is set to true:
    46.         if(invOpen == true){
    47.             //Open the inventory GUI:
    48.             InventoryGUI();
    49.         }
    50.         //Only open the main menu GUI if menuOpen is set to true:
    51.         if(menuOpen == true){
    52.             //Open the main menu GUI:
    53.             MainMenuGUI();
    54.         }
    55.     }
    56.     //Create the inventory GUI:
    57.     void InventoryGUI () {
    58.         GUILayout.BeginArea(GUIArea);
    59.         GUILayout.BeginVertical();
    60.         //Create the item slots:
    61.         foreach(Item item in inventory.items){
    62.             //Check to see if their is an item in the slot:
    63.             if(item != null){
    64.                 //Create the item slot:
    65.                 if(GUILayout.Button(item.ItemName, GUILayout.Width(50), GUILayout.Height(50))){
    66.                     //Swap the item in the player's hand with the item in the slot clicked on:
    67.                     itemInHand = item;
    68.                 }
    69.             }
    70.         }
    71.     }
    72.     //Create the Main Menu GUI:
    73.     void MainMenuGUI () {
    74.         GUI.Box(new Rect(275, 200, 250, 300), "Menu");
    75.         //Create the log out button:
    76.         if(GUI.Button(new Rect(300, 240, 200, 20), "Log Out")){
    77.             //Save the player's inventory upon logging out:
    78.             SaveInv();
    79.         }
    80.     }
    81.     //Save the inventory:
    82.     void SaveInv () {
    83.         //Player prefs will soon be replaced with online database storage system.
    84.         //Save the player's inventory:
    85.         string SavedInv = JsonUtility.ToJson(inventory.items);
    86.         PlayerPrefs.SetString("SavedInv", SavedInv);
    87.     }
    88.     //Load the inventory:
    89.     void LoadInv () {
    90.         //Player prefs will soon be replaced with online database storage system.
    91.         //Load the player's inventory:
    92.         string LoadedInv = PlayerPrefs.GetString("SavedInv");
    93.         ItemList LoadedItems = JsonUtility.FromJson<ItemList>(LoadedInv);
    94.         inventory = LoadedItems;
    95.         //Stop the process of loading the inventory:
    96.         invLoaded = true;
    97.     }
    98. }
    DISCLAIMER: Code is still in development stages. The code is not 100% complete yet and may have errors.
     
  3. ikefrc

    ikefrc

    Joined:
    Jul 3, 2012
    Posts:
    81
    Both if statements would trigger in one frame, you need else if.