Repository navigation
EN API UO PauseResumeScript
Українська · Русский · English · Deutsch · Français · Italiano · Español · 繁體中文 · 日本語 · 한국어
Home · C# · IDE · UO API · A–Z · Examples · Languages
void UO.PauseResumeScript(object? arg0);Toggles manual pause of one active run. Use to temporarily stop mining or another procedure without losing its current progress.
-
ScriptIndex- Mandatory ScriptIndex - current launch index: 0 means the first one, then 1, 2... Get it through GetScriptsList; it is not serial, the file name and not the result StartScript. A negative/missing index doesn't change anything.
void - no return value. Don't compare the call to true/1. Check the condition by separately reading GetScriptState; the result of such a reading is 0 (no start), 1 (running), 2 (pause).
- Works only with runs of the current session. An open tab without execution is not an active launch. Stopping does not delete the original file or disconnect the connection to the server.
- Indexes are dynamic: positions may shift after another run is completed. Multiple API calls are not an atomic operation. The examples are designed for the absence of parallel changes to the list; look for the desired launch again before the action and do not store the index via UO.Wait.
- This is a switch, not an "always continue" command. Manual and automatic pauses are independent: switching to manual does not remove the connection break pause. The code 2 does not explain the reason for the pause. If you stop your own launch in this way, it will not be able to make the next call to continue it; resume from IDE/manager or other script.
Each example can be saved as a separate file .csx and run in IDE. The UO object and wait functions provide the host of the current game session. Replace demo serial names, coordinates and addresses with your own.
Parameters and execution flow:
- MineOre is an example of the display name of an already running procedure. FindNamedRun returns the first matched index or -1. Call from another controller; calling again changes the manual pause back.
- Indexes are dynamic: positions may shift after another run is completed. Multiple API calls are not an atomic operation. The examples are designed for the absence of parallel changes to the list; look for the desired launch again before the action and do not store the index via UO.Wait.
var index = FindNamedRun("MineOre");
if (Truth(index >= 0))
{
UO.PauseResumeScript(index);
}
dynamic FindNamedRun(dynamic wanted)
{
var indices = UO.GetScriptsList();
foreach (var index in indices)
{
if (Truth(UO.GetScriptName(index) == wanted))
{
return index;
}
}
return -1;
}
bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;Parameters and execution flow:
- Check == 1 limits the action to a running trigger. The value 2 is not used as a "clear manual pause" indication because it may indicate no communication.
- Indexes are dynamic: positions may shift after another run is completed. Multiple API calls are not an atomic operation. The examples are designed for the absence of parallel changes to the list; look for the desired launch again before the action and do not store the index via UO.Wait.
return await RunScenarioAsync();
async Task<object?> RunScenarioAsync()
{
var index = FindNamedRun("MineOre");
if (Truth(index >= 0))
{
if (Truth(UO.GetScriptState(index) == 1))
{
UO.PauseResumeScript(index);
}
}
return null;
}
dynamic FindNamedRun(dynamic wanted)
{
var indices = UO.GetScriptsList();
foreach (var index in indices)
{
if (Truth(UO.GetScriptName(index) == wanted))
{
return index;
}
}
return -1;
}
bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;Parameters and execution flow:
- Replace the absolute path with yours. FindFileRun compares paths in a case-insensitive manner and returns the first run of this file; Several procedures can be executed in one file.
- Indexes are dynamic: positions may shift after another run is completed. Multiple API calls are not an atomic operation. The examples are designed for the absence of parallel changes to the list; look for the desired launch again before the action and do not store the index via UO.Wait.
return await new ScriptScenario(UO, WaitAsync, Args, Cancellation, Checkpoint).RunScenarioAsync();
class ScriptScenario
{
private readonly global::ClassicUO.CSharp.CSharpGameApi UO;
private readonly Func<int, Task> WaitAsync;
private readonly string[] Args;
private readonly CancellationToken Cancellation;
private readonly Action Checkpoint;
public ScriptScenario(global::ClassicUO.CSharp.CSharpGameApi api, Func<int, Task> wait, string[] args, CancellationToken cancellation, Action checkpoint)
{
UO = api;
WaitAsync = wait;
Args = args;
Cancellation = cancellation;
Checkpoint = checkpoint;
}
async public Task<object?> RunScenarioAsync()
{
var wantedPath = "D:/Game/AutoLoad/Scripts/Worker.csx";
var index = FindFileRun(wantedPath);
if (Truth(index >= 0))
{
UO.PauseResumeScript(index);
}
return null;
}
dynamic FindFileRun(dynamic wantedPath)
{
var indices = UO.GetScriptsList();
foreach (var index in indices)
{
if (Truth(Convert.ToString(ReplaceText(UO.GetScriptPath(index), Chr(92), "/")) == Convert.ToString(ReplaceText(wantedPath, Chr(92), "/"))))
{
return index;
}
}
return -1;
}
string Chr(object? value) => ((char)Convert.ToInt32(value)).ToString();
bool Truth(object? value) => value is bool flag ? flag : value is string text ? !string.IsNullOrEmpty(text) : value != null && Convert.ToDouble(value) != 0;
string ReplaceText(object? value, object? oldValue, object? newValue) => (Convert.ToString(value) ?? "").Replace(Convert.ToString(oldValue) ?? "", Convert.ToString(newValue) ?? "");
}ClassicUO — Bad Newbie & C# Scripts IDE