Skip to content

Commit

Permalink
Add timeout to lift command
Browse files Browse the repository at this point in the history
  • Loading branch information
markdwags committed Jul 4, 2023
1 parent 7626016 commit 0aec971
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
17 changes: 17 additions & 0 deletions Razor/Core/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,23 @@ public static ushort ToUInt16(string str, ushort def)

return def;
}

public static long ToLong(string str, ushort def)
{
if (str == null)
return def;

long val;
if (str.StartsWith("0x"))
{
if (long.TryParse(str.Substring(2), NumberStyles.HexNumber, Engine.Culture, out val))
return val;
}
else if (long.TryParse(str, out val))
return val;

return def;
}

public static void LaunchBrowser(string url)
{
Expand Down
11 changes: 9 additions & 2 deletions Razor/Scripts/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1148,7 +1148,7 @@ private static bool LiftItem(string command, Variable[] vars, bool quiet, bool f
{
if (vars.Length < 1)
{
throw new RunTimeError("Usage: lift (serial) [amount]");
throw new RunTimeError("Usage: lift (serial) [amount] [timeout]");
}

Serial serial = vars[0].AsSerial();
Expand All @@ -1165,6 +1165,13 @@ private static bool LiftItem(string command, Variable[] vars, bool quiet, bool f
amount = Utility.ToUInt16(vars[1].AsString(), 1);
}

long timeout = 30000;

if (vars.Length == 3)
{
timeout = Utility.ToLong(vars[2].AsString(), 30000);
}

if (_lastLiftId > 0)
{
if (DragDropManager.LastIDLifted == _lastLiftId)
Expand All @@ -1174,7 +1181,7 @@ private static bool LiftItem(string command, Variable[] vars, bool quiet, bool f
return true;
}

Interpreter.Timeout(30000, () =>
Interpreter.Timeout(timeout, () =>
{
_lastLiftId = 0;
return true;
Expand Down
11 changes: 9 additions & 2 deletions help/docs/guide/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,9 +459,9 @@ Example:

## lift

**Syntax**: `lift ('serial') ['amount']`
**Syntax**: `lift ('serial') ['amount'] ['timeout']`

**Description**: This command will lift a specific item and amount. If no amount is provided, `1` is defaulted.
**Description**: This command will lift a specific item and amount. If no amount is provided, `1` is set as default. If no timeout is provided, `30000` (30 seconds) is set as default

!!! tip "dress command"
If you're looking to lift an item to wear, consider using the `dress` command instead.
Expand All @@ -476,6 +476,13 @@ Example:
droprelloc 1 1 0
```

=== "Lift item, timeout in 5 seconds if unable"
```razor
lift '0x400EED2A' 1 5000
droprelloc 1 1 0
```

## lifttype

**Syntax**: `lifttype ('gfx') ['amount'] ['hue']` or `lifttype ('name of item') ['amount'] ['hue']`
Expand Down

0 comments on commit 0aec971

Please sign in to comment.