Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save scottstamp/1d93326f85175a780c99d87555e637a8 to your computer and use it in GitHub Desktop.
Save scottstamp/1d93326f85175a780c99d87555e637a8 to your computer and use it in GitHub Desktop.
/// @name Auto accept trades
/// @group Trading
/// @desc
/// Automatically accepts trades.
/// The trade window won't be shown in-client,
/// and your inventory won't refresh until the script is canceled.
/// @author b7
/// @scripter 1.0.0-beta
OnIntercept((
In.TradeOpen, In.TradeCompleted,
In.TradeItems, In.TradeAccept,
In.TradeConfirmation,
In.InventoryAddOrUpdateFurni
), e => e.Block());
var exit = true;
var greetings = new string[] { "ty ||", "thanks ||", "thanks! |", "tysm!! |", "thanks ƒ", "ty! ||" };
OnTradeCompleted(e => {
ShowBubble(
$"Received {e.PartnerOffer.CreditCount}c, "
+ $"{e.PartnerOffer.FurniCount} furni "
+ $" from {e.Partner.Name}"
);
Log($"Received {e.PartnerOffer.CreditCount}c, "
+ $"{e.PartnerOffer.FurniCount} furni "
+ $" from {e.Partner.Name} at {DateTimeOffset.Now:HH:mm:ss tt}");
RunTask(() => {
if (exit && e.Partner.HasRights) {
Talk(Rand(greetings));
Delay(1000);
Whisper(Self.Name, "exit");
}
});
});
ShowBubble($"{EnsureInventory().Count()} items in inventory");
try {
while (Run) {
Log("Waiting for trade...");
var tradeOpened = Receive(In.TradeOpen);
while (Run) {
var participant1 = tradeOpened.ReadInt(0);
var participant2 = tradeOpened.ReadInt(8);
var partner = default(IRoomUser);
if (participant1 != Self.Id) {
partner = Users.FirstOrDefault(x => x.Id == participant1);
} else {
partner = Users.FirstOrDefault(x => x.Id == participant2);
}
if (partner != default) {
ShowBubble($"{partner.Name} has initiated a trade");
}
Log("Waiting for partner to accept trade...");
var packet = Receive((In.TradeAccept, In.TradeClose));
if (packet.Header != In.TradeAccept) break;
packet.ReadInt();
bool accepted = packet.ReadInt() == 1;
if (accepted) {
Log("Accepting trade...");
Delay(100);
Send(Out.TradeAccept);
Log("Waiting for trade confirmation...");
packet = Receive((
In.TradeConfirmation,
In.TradeItems,
In.TradeClose,
In.TradeCompleted
));
if (packet.Header == In.TradeItems) continue;
if (packet.Header != In.TradeConfirmation) break;
Log("Confirming trade...");
Delay(100);
Send(Out.TradeConfirmAccept);
Log("Waiting for trade completion...");
Receive(In.TradeClose);
break;
}
}
}
} finally { Send(In.InventoryInvalidate); }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment