Server Uptime Command

Posts 15 of 5 · Page 1 of 1
Server Uptime Command


Creds to fab for guiding me a little on how to use variable from another file

Navigate to wServer>program.cs
Add this line near the top with the rest of the lines that look a bit similar
Code:
public static readonly DateTime StartTime = DateTime.Now;
Now navigate to your command file you want to put this in, which is probably wServer>realm>commands>WorldCommand.cs
Add this command, at the top, I guess, doesn't matter as long as you don't be a retard when placing it and interfere with a bracket or another command.
Code:
    internal class UptimeCommand : Command
    {
        public UptimeCommand() : base("uptime") { }
        protected override bool Process(Player player, RealmTime time, string[] args)
        {
            var uptime = DateTime.Now - Program.StartTime;
            var minutes = uptime.TotalMinutes;
            player.SendInfo("Server Uptime: " + uptime.ToString());
            return true;
        }
    }
Yeah Ik there is an unused variable, I was gonna make it show as a solid number of minutes, but I'd rather it show as hr:min:sec.

Gimme more command ideas, xD I have made a few commands from NR already, I am pretty sure they have uptime command and then the gift command except their version of /gift sends item to vault but I like mine how it sends to inv, can easily be done to send to vault tho, and then done a few more simple ones like /visit and the quake one he has and i wanna try /reboot soon.
Quote Originally Posted by R1S3 View Post
Creds to fab for guiding me a little on how to use variable from another file
"a little" :3

Code:
[04.02.2016 21:48:40] Chris: Hey, is there a way to get uptime of wServer lol
[04.02.2016 21:48:47] Chris: Wanna make an uptime command
[04.02.2016 21:48:49] Chris: I'm doing
[04.02.2016 21:48:58] Chris:              int uptime = Environment.TickCount / 60000 & Int32.MaxValue;
            player.SendInfo("Server Uptime (minutes): " + uptime);
[04.02.2016 21:49:31] Chris: but that spits out a number like 7,000 something so I think that it is showing uptime of my computer or something by default since I didn't define any program for it to do
[04.02.2016 21:49:48] Fabian: at the start
[04.02.2016 21:49:57 | Edited 21:49:48] Fabian: start = datetime.now
[04.02.2016 21:50:16] Fabian: uptime = datetime.now - start
[04.02.2016 21:50:23 | Edited 21:50:12] Fabian: uptime.tostring()
[04.02.2016 21:51:40] Chris: eliteeeeeeeeeeeeeeeee thanks xD
Quote Originally Posted by ossimc82 View Post
"a little" :3

Code:
[04.02.2016 21:48:40] Chris: Hey, is there a way to get uptime of wServer lol
[04.02.2016 21:48:47] Chris: Wanna make an uptime command
[04.02.2016 21:48:49] Chris: I'm doing
[04.02.2016 21:48:58] Chris:              int uptime = Environment.TickCount / 60000 & Int32.MaxValue;
            player.SendInfo("Server Uptime (minutes): " + uptime);
[04.02.2016 21:49:31] Chris: but that spits out a number like 7,000 something so I think that it is showing uptime of my computer or something by default since I didn't define any program for it to do
[04.02.2016 21:49:48] Fabian: at the start
[04.02.2016 21:49:57 | Edited 21:49:48] Fabian: start = datetime.now
[04.02.2016 21:50:16] Fabian: uptime = datetime.now - start
[04.02.2016 21:50:23 | Edited 21:50:12] Fabian: uptime.tostring()
[04.02.2016 21:51:40] Chris: eliteeeeeeeeeeeeeeeee thanks xD
yeah well u didnt tell me I had to put the start = datetime.now in programcs for wserver XD i was confused for like 10 mins i was like "if i put both in command how tf does it change since its both being called at same time" but still thanks XD i was confused the way you put it and i didnt feel like asking again cuz I hate being that annoying person, i was super confused as to how in the hell i was supposed to use a variable from another file, then eventually I added public static readonly datetime startime = datetime.now and eh it worked ;p but you always help me with my stupid questions xD
Quote Originally Posted by R1S3 View Post


Creds to fab for guiding me a little on how to use variable from another file

Navigate to wServer>program.cs
Add this line near the top with the rest of the lines that look a bit similar
Code:
public static readonly DateTime StartTime = DateTime.Now;
Now navigate to your command file you want to put this in, which is probably wServer>realm>commands>WorldCommand.cs
Add this command, at the top, I guess, doesn't matter as long as you don't be a retard when placing it and interfere with a bracket or another command.
Code:
    internal class UptimeCommand : Command
    {
        public UptimeCommand() : base("uptime") { }
        protected override bool Process(Player player, RealmTime time, string[] args)
        {
            var uptime = DateTime.Now - Program.StartTime;
            var minutes = uptime.TotalMinutes;
            player.SendInfo("Server Uptime: " + uptime.ToString());
            return true;
        }
    }
Yeah Ik there is an unused variable, I was gonna make it show as a solid number of minutes, but I'd rather it show as hr:min:sec.

Gimme more command ideas, xD I have made a few commands from NR already, I am pretty sure they have uptime command and then the gift command except their version of /gift sends item to vault but I like mine how it sends to inv, can easily be done to send to vault tho, and then done a few more simple ones like /visit and the quake one he has and i wanna try /reboot soon.
Danke m8/10th character
Quote Originally Posted by R1S3 View Post
Creds to fab for guiding me a little on how to use variable from another file
Oh boy.
Its a little to copy pasty for me but gj.
Posts 15 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?