GUI Stuff

Discussion in 'Rust Discussion' started by DylanSMR, Aug 6, 2015.

  1. So a few things.
    Lang:CS
    For a GUI
    How can I force one upon a player
    EXAMPLE:
    /GUI Player Message
    And 1 more thing.
    How would I change the position of the GUI on a screen
    So I could have it on the top right persay

    (I might have to add more to this later)
     
  2. Wulf

    Wulf Community Admin

  3. One more thing I didnt see, how do people align the xmax, xmin, ymax, ymin so perfectly?
     
  4. We are not doing it perfectly. We are trying to do it as good as possible... we know that 0.50 is the half of the screen and thats how i start positioning my GUIs.
     
  5. Anything look wrong in the code below?

    Code:
    using UnityEngine;
    using Rust;
    using Oxide.Core.Plugins;namespace Oxide.Plugins
    {
        [Info("PmGui", "DylanSMR", "0.0.1", ResourceId = 8902)]
        class PmGui : RustPlugin
        {  
            int PmDisappearTime = 15; //15 Seconds      
            System.Timers.Timer timer;
            bool canRun = true;
            #region JSON
            string json = @"[
                            {
                                ""name"": ""PmGui"",
                                ""parent"": ""Overlay"",
                                ""components"":
                                [
                                    {
                                         ""type"":""UnityEngine.UI.Image"",
                                         ""color"":""0.1 0.1 0.1 0.7"",
                                    },
                                    {
                                        ""type"":""RectTransform"",
                                        ""anchormin"": ""1 0.89"",
                                        ""anchormax"": ""0.86 1""
                                    }
                                ]
                            },
                            {
                                ""parent"": ""PmGui"",
                                ""components"":
                                [
                                    {
                                        ""type"":""UnityEngine.UI.Text"",
                                        ""text"":""From: {from}"",
                                        ""fontSize"":10,
                                        ""align"": ""MiddleCenter"",
                                    },
                                    {
                                        ""type"":""RectTransform"",
                                        ""anchormin"": ""0.92 0.90"",
                                        ""anchormax"": ""0.87 0.93""
                                    }
                                ]
                            },
                            {
                                ""parent"": ""PmGui"",
                                ""components"":
                                [
                                    {
                                        ""type"":""UnityEngine.UI.Text"",
                                        ""text"":""{msg}"",
                                        ""fontSize"":15,
                                        ""align"": ""MiddleCenter"",
                                    },
                                    {
                                        ""type"":""RectTransform"",
                                        ""anchormin"": ""0.87 0.85"",
                                        ""anchormax"": ""0.87 0.93""
                                    }
                                ]
                            }
                            {
                                ""parent"": ""PmGui"",
                                ""components"":
                                [
                                    {
                                        ""type"":""UnityEngine.UI.Text"",
                                        ""text"":""New Message:"",
                                        "'fontSize"":18,
                                        ""align"": ""MiddleCenter"",
                                    },
                                    {
                                        ""type"":""RectTransform"",
                                        ""anchormin"": ""0.98 0.97"",
                                        ""anchormax"": ""0.87 0.93""
                                    }
                                ]
                            }
                        ]
                        ";
            #endregion
            void LoadMsgGui(string Name, string Msg)
            {          
                string send = json.Replace("{from}", Name).Replace("{msg}", Msg);
                foreach (BasePlayer player in BasePlayer.activePlayerList)
                {
                    CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = player.net.connection }, null, "AddUI", send);
                }
                timer.Start();
            }
          
            void Loaded()
            {
                timer = new System.Timers.Timer(1000 * PmDisappearTime);
                timer.Interval = 1000 * PmDisappearTime;
                timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed);
            }
          
            void Unload()
            {
                timer.Stop();
            }
            BasePlayer TempPlayer;
          
            [ChatCommand("pm")]
            void cmdAnnounceTo(BasePlayer player, string command, string[] args)
            {
                if(!canRun)
                {
                    SendReply(player, "You have messages this person recently please wait " + PmDisappearTime + " seconds.");  
                    return;      
                }
                if(args.Length >= 2)
                {
                    string Player = args[0].ToLower(), Msg = "";
                    for(int i = 1; i < args.Length; i++)              
                        Msg = Msg + " " + args[i];
                    BasePlayer p;
                    if((p = BasePlayer.activePlayerList.Find(x => x.displayName.ToLower().EndsWith(Player))) != null) //used ends with due to clan tags
                    {
                        string send = json.Replace("{from}", player.displayName).Replace("{msg}", Msg);
                        CommunityEntity.ServerInstance.ClientRPCEx(new Network.SendInfo() { connection = p.net.connection }, null, "AddUI", send);
                        canRun = false;
                        timer.Start();
                        TempPlayer = p;
                    } else SendReply(player, Player+" is not online.");
                } else SendReply(player, "Incorrect Syntax use /pm <name> <msg>");
            }
        }
    }
     
    Last edited by a moderator: Aug 7, 2015