Hello everyone, new member here!
I've recently fallen in love with ServUO, after having decided to play some UO after years, since i missed it.
I feel the freedom and mood are still the best around, even when compared to modern soulless themepark mmorpgs.
Long story short, i'm working on some scripts for a custom personal server, and already dug around quite a number of Server and Script files.
Even though i started scripting today (played around with Admin Commands, exploring Props, UOFiddler and other tools for a couple days though),
i think i kind of got the most basic stuff down, including the EventSink (didn't find any tutorials on that one, so i peeked into other scripts
to figure it out).
There is one thing that's giving me a hard time though.
Basically, i'm trying to create a simple script that every x amount of time will check a file, read from it and use this information inside the game.
Ideally, this script would check with real-time accuracy, accurate to the second sounds about right.
Since the script also executes some custom Python code, it takes about 2 seconds for it to finish, and while it's running it completely freezes the Game - very short amount of time, but running this with a one second accuracy with the Timer seems impossible at the moment.
I think the answer is in a separate thread, so i can run it in the background?
Having started today with c#, i'm very much a newbie, so even though i grasp the concept of background workers in c# and multi-threading, i still though it would be much better to ask here, since it's something that has to do with a game, and specifically ServUO.
You guys probably know how to handle a background process so that it doesn't block the Main Program execution and hence freezes it.
I already set up the Timer Checks and stuff, so all that's left is really just to figure out how to have this python code work in the background, most likely in a separate thread.
I'm also already running a separate process, a new instance of Process specifically.
Which is the reason i think the only answer could be setting up some kind of separate thread.
So, would you guys know how to best handle this situation, so that i can execute this custom code in the background without freezing the game?
Here is my current code:
As you can also see, there is some commented out code that i'm not using at the moment.
It was an attempt to read the stdoutput from the python process, but i wasn't able to make it work because in order to redirect the output i can't use a Shell, and when the same Shell ServUO uses is used, it completely freezes everything until i close it - as if it were waiting for the ServUO process to end to continue - but if it ends, well.. there is no continuing xD
Also, i already tried removing the WaitForExit(), to solve both the reading stdout problem and the background process problem, to no avail.
I ended up solving the reading stdout problem by simply making the python script dump the output in a txt file and then reading it with the aforementioned checks.
Thank you very much for your time!
I've recently fallen in love with ServUO, after having decided to play some UO after years, since i missed it.
I feel the freedom and mood are still the best around, even when compared to modern soulless themepark mmorpgs.
Long story short, i'm working on some scripts for a custom personal server, and already dug around quite a number of Server and Script files.
Even though i started scripting today (played around with Admin Commands, exploring Props, UOFiddler and other tools for a couple days though),
i think i kind of got the most basic stuff down, including the EventSink (didn't find any tutorials on that one, so i peeked into other scripts
to figure it out).
There is one thing that's giving me a hard time though.
Basically, i'm trying to create a simple script that every x amount of time will check a file, read from it and use this information inside the game.
Ideally, this script would check with real-time accuracy, accurate to the second sounds about right.
Since the script also executes some custom Python code, it takes about 2 seconds for it to finish, and while it's running it completely freezes the Game - very short amount of time, but running this with a one second accuracy with the Timer seems impossible at the moment.
I think the answer is in a separate thread, so i can run it in the background?
Having started today with c#, i'm very much a newbie, so even though i grasp the concept of background workers in c# and multi-threading, i still though it would be much better to ask here, since it's something that has to do with a game, and specifically ServUO.
You guys probably know how to handle a background process so that it doesn't block the Main Program execution and hence freezes it.
I already set up the Timer Checks and stuff, so all that's left is really just to figure out how to have this python code work in the background, most likely in a separate thread.
I'm also already running a separate process, a new instance of Process specifically.
Which is the reason i think the only answer could be setting up some kind of separate thread.
So, would you guys know how to best handle this situation, so that i can execute this custom code in the background without freezing the game?
Here is my current code:
Code:
using System;
using System.IO;
using System.Diagnostics;
namespace Scripts.Custom
{
class PythonBridge
{
public static void Main(string args)
{
// full path of python interpreter
string python = @"D:\Python\Python35\python.exe";
// python app to call
string myPythonApp = @"D:\Python\My_Script.py";
// dummy parameters to send Python script
string tag = args;
// Create new process start info
ProcessStartInfo myProcessStartInfo = new ProcessStartInfo(python);
// make sure we can read the output from stdout
myProcessStartInfo.UseShellExecute = true;
myProcessStartInfo.RedirectStandardOutput = false;
myProcessStartInfo.CreateNoWindow = true;
myProcessStartInfo.WindowStyle = ProcessWindowStyle.Hidden;
// start python app with 3 arguments
// 1st arguments is pointer to itself,
// 2nd and 3rd are actual arguments we want to send
myProcessStartInfo.Arguments = String.Format("\"{0}\" {1}", myPythonApp, tag);
Process myProcess = new Process();
// assign start information to the process
myProcess.StartInfo = myProcessStartInfo;
Console.WriteLine("Calling Python script with tag {0}", tag);
// start the process
myProcess.Start();
// Read the standard output of the app we called.
// in order to avoid deadlock we will read output first
// and then wait for process terminate:
//StreamReader myStreamReader = myProcess.StandardOutput;
//string myString = myStreamReader.ReadLine();
// wait exit signal from the app called and then close it.
myProcess.WaitForExit();
myProcess.Close();
// write the output we got from python app
//Console.WriteLine("Value received from script: " + myString);
//return myString;
}
}
}
As you can also see, there is some commented out code that i'm not using at the moment.
It was an attempt to read the stdoutput from the python process, but i wasn't able to make it work because in order to redirect the output i can't use a Shell, and when the same Shell ServUO uses is used, it completely freezes everything until i close it - as if it were waiting for the ServUO process to end to continue - but if it ends, well.. there is no continuing xD
Also, i already tried removing the WaitForExit(), to solve both the reading stdout problem and the background process problem, to no avail.
I ended up solving the reading stdout problem by simply making the python script dump the output in a txt file and then reading it with the aforementioned checks.
Thank you very much for your time!