|
Hoi, new content? Why yes!
To begin in with, conducting unattended trades with furbot, you first have to understand, it's a program, and what it does with a trading session is only as good as how well you take advantages of the available commands and construct a script which does what you expect it to do. Next thing to take into consideration is that a trade action from the server is an emit, and is handled by triggers, not actions. This gives you a bit more security in constructing a trade automation because you don't have to do extensive syntax checking and parsing, you just need to ensure that the emiticon is the one for trading, and test OTHER stuff for the bot to do it's thing.
Trigger Name: Trade Start Stop Action Search if TRUE An emit is seen AND: if variable {[emiticon]} is equal to {100} (numeric comparison) if variable {[message]} contains text _ {asks you to have a trading session} (case insensitive) THEN: Store {[word2]} to variable {[trade-name]} $LOG: Save entry {[message]} to file _ {[scriptdir]logs\trades-[year]-[month].log} _ under record {[trade-name]-[time]} Say {trade-start} Whisper {[trade-name]} the message {You have started a trading _ session with an automation, as such, the wording has to be exact for the _ script to follow through and there be a successful trade. This session is _ for the purpose of trading one GD to the bot for entry into the gaming _ session which is now open. Please add one GD to the trade session and _ follow the prompts which will be whispered to complete the trade.}
Well, that fairly much starts the ball rolling. The bot detected the fact that someone asked it to start a trading session, so it should then say "trade-start" itself, and whisper back instructions. Instructions are going to be a important part of this process, depending on what you are doing with the trade session. In this case, I'm using the trade to accept 1 GD from the player for the purpose of playing in a contest. Because it's a one way trade, that is, the bot puts nothing on the table for the player to accept, there needs to be steps taken to include a trade reason in the deal, otherwise the server rejects that. So, after the trade has started, the player needs to add trade-add gd 1 to the session to trigger the next event from the bot:
Trigger Name: Trade 1 GD Stop Action Search if TRUE An emit is seen AND: if variable {[emiticon]} is equal to {100} (numeric comparison) if variable {[trade-name]} is not the same as {NO FURRE} _ (text comparison) if variable {[message]} contains text _ {has added One golden dragonscale to their current offer} _ (case insensitive) THEN: Say {trade-reason Entry fee into the contest.} $LOG: Save entry {[message]} to file _ {[scriptdir]logs\trades-[year]-[month].log} _ under record {[trade-name]-[time]} Say {trade-accept} Whisper {[trade-name]} the message {Offer is valid, set your trade _ reason to 'Entry fee into the contest'
(Note the _ is not part of the commands, those are included to wrap the commands)
Remember all through this tutorial, the first thing you check is that it's a trade icon in the emit, then you're checking text in the message itself for key phrases to act on. This is a reason that the server capture command exists in the bot, so you can look at the capture log and get the exact phrasing used by the server for anything the server sends the bot. The server uses the word One instead of a number to indicate the amount being offered in the trade in this case.
The first thing the bot does is set the trade-reason to a specific reason in this instance. If you're using a bot to sell digos, and two of them are the same price, you'd perhaps want to have the player set the trade reason first to a specific phrase that include the name of the digo item you're selling.
After the bot updates the logfile with the trade status, it then also says trade-accept. The server responds to both those commands with text that needs to be phrase checked to ensure that an invalid command doesn't slip through all the cracks and land on the last item in the Trade Trigger Checking System, Trade Invalid, which is the catch-all that terminates the trade if something ain't kosher. We'll cover that last.
I'm presenting these triggers in the order from DMG, and it's the one which seems to work best, so the next trigger capture is this:
Trigger Name: Trade End Stop Action Search if TRUE An emit is seen AND: if variable {[emiticon]} is equal to {100} (numeric comparison) if variable {[message]} contains text _
{Your trading session has ended} (case insensitive) THEN: $LOG: Save entry {[message]} to file _
{[scriptdir]logs\trades-[year]-[month].log} _ under record {[trade-name]-[time]} Store {NO FURRE} to variable {[trade-name]}
Which could also be at the top, it's merely to keep the bot from over-processing commands.
There's also several trigger commands in the system to catch valid phrases from the server and need to be caught and stopped to prevent any trade action that's important in the server's trade system from triggering that Trade Invalid command. Which terminates the trade.
The following catches the trade-accept phrase from the server that
Trigger Name: Trade Valid Offer Stop Action Search if TRUE An emit is seen AND: if variable {[emiticon]} is equal to {100} (numeric comparison) if variable {[message]} contains text _ {You accept the current offer} (case insensitive) if variable {[trade-name]} is not the same as {NO FURRE} _ (text comparison) THEN: $LOG: Save entry {[message]} to file _ {[scriptdir]logs\trades-[year]-[month].log} _ under record {[trade-name]-[time]}
Now the next two triggers may seem redundantly the same, but there's specific reasons for each of them, see if you can spot them.
Trigger Name: Trade Reason Set Stop Action Search if TRUE An emit is seen AND: if variable {[emiticon]} is equal to {100} (numeric comparison) if variable {[message]} contains text _ {Entry fee into the contest} (case insensitive) if variable {[trade-name]} is the same as {[word2]} (text comparison) THEN: $LOG: Save entry {[message]} to file _ {[scriptdir]logs\trades-[year]-[month].log} _
under record {[trade-name]-[time]} Whisper {[trade-name]} the message {Trade reason has been recognized _ by this script, please use 'trade-accept' and click YES on the popup _ to successfully conclude this session.}
Trigger Name: Trade Valid Reason Stop Action Search if TRUE An emit is seen AND: if variable {[emiticon]} is equal to {100} (numeric comparison) if variable {[message]} contains text _ {Entry fee into the contest} (case insensitive) if variable {[trade-name]} is not the same as _ {NO FURRE} (text comparison) THEN: $LOG: Save entry {[message]} to file _ {[scriptdir]logs\trades-[year]-[month].log} _ under record {[trade-name]-[time]}
Give up?
Come on, it's easy.
If you guessed that the first one traps the trade-reason from the player because it's checking the contents of [word2] against [trade-name] and the second traps the same thing from when the bot sets the trade-reason, then give yourself a cookie. This is a very important reminder that everything dealing with a system like this must be trapped. The same goes for this:
Trigger Name: Trade Valid Start Stop Action Search if TRUE An emit is seen AND: if variable {[emiticon]} is equal to {100} (numeric comparison) if variable {[message]} contains text _ {have begun a trading session} (case insensitive) if variable {[trade-name]} is not the same as _ {NO FURRE} (text comparison) THEN: $LOG: Save entry {[message]} to file _ {[scriptdir]logs\trades-[year]-[month].log} _ under record {[trade-name]-[time]}
It's a Trap!
Finally, once the player does the trade-accept on their end, the server does it's stuff and sends messages to both parties involved, in this case, for the player, it delivers a pop-up which needs to be handled by them to get the server to send the final message of the session to the bot which can be processed and whatever wrap-up actions can be done. In the case of this script, it creates an entry into a table that can be used for other things, ...
Trigger Name: Trade Valid Trade Stop Action Search if TRUE An emit is seen AND: if variable {[emiticon]} is equal to {100} (numeric comparison) if variable {[message]} contains text _ {Your items have been traded and the trade session is now complete} _ (case insensitive) if variable {[trade-name]} is not the same as _ {NO FURRE} (text comparison) THEN: $LOG: Save entry {[message]} to file _ {[scriptdir]logs\trades-[year]-[month].log} _ under record {[trade-name]-[time]} Store {[trade-name]} to variable {[myshortname]} Execute Procedure {Create Shortname} Add {My Short Name = '[myshortname]'} to the connection log $ Begin Wolfscript: (5) // Create the entry into the gamers table if it doesn't exist // if the name exists, add time to the expires
&newvar #sql &sprintf({SELECT * FROM Gamers WHERE UserName='%1'} _ &strtodb(&getvar(trade-name)))
&dbopen 2 #sql &newvar #count &dbrecordcount(2) &ifn #count > 0 &newvar #expires &dbf(2 Expires) &newvar #distance &datediff({d} &date() #expires) &ifn #distance < 0 &set #expires &date() &endif &set #expires &dateadd({ww} 6 #expires) &dbedit 2 &dbset 2 Expires #expires &dbrsetupdate 2 // supposed I should whisper back that their time has been extended &exitwolf &endif
// name does not exist in the table, create the entry &dbaddnew 2 &dbset 2 UserName &strtodb(&getvar(trade-name)) &dbset 2 ShortName &getvar(myshortname) &dbset 2 JoinDate &date() &dbset 2 Expires &dateadd({ww} 6) &dbset 2 LastSeen &date() &dbset 2 ScoreA 0 &dbset 2 ScoreB 0 &dbset 2 ScoreC 0 &dbset 2 ScoreD 0 &dbset 2 BigScore 0 &dbset 2 Connects 0 &dbset 2 Battles 0 &dbset 2 Stomps 0 &dbset 2 TotalWins 0 &dbset 2 Tokens 25 &dbrsetupdate 2 &say &sprintf({ps set character.%1.tokens=25} &getvar(myshortname)) &whisper &getvar(myshortname) {Thank you for joining, _ 25 tokens has been put into your account}
$ End Wolfscript: (5) Store {NO FURRE} to variable {[trade-name]}
And that is how a successful trade is handled. Even if you DON'T do any wrap-up of what you're conducting the trade for, you still need this trigger trap to prevent the following from being acted on:
Trigger Name: Trade Invalid Stop Action Search if TRUE An emit is seen AND: if variable {[emiticon]} is equal to {100} (numeric comparison) if variable {[trade-name]} is not the same as _ {NO FURRE} (text comparison) THEN: $LOG: Save entry {[message]} to file _ {[scriptdir]logs\trades-[year]-[month].log} _
under record {[trade-name]-[time]} Whisper {[trade-name]} the message {Invalid Action, Trade Terminated} Say {trade-end} Store {NO FURRE} to variable {[trade-name]}
This handles any instances of something that would invalidate the trade.
Bonus!
Sharp eyes may have spotted a procedure call above, Create Shortname, that is called by the trade accept action before it calls on the WolfScript of the trigger. This is because there is not a valid [player] extracted from the emits used by the trade system from the server, and hence, there's no shortname either. So I had to either rebuild a chunk of furbot to extract [player] from the emit, along with the accompanying shortname. Bah. Maybe with the next major update.
Trigger Name: Create Shortname Procedure No Additional Conditions. THEN: $ Begin Wolfscript: (1) // create shortname from myshortname &newvar #shortname &lcase(&getvar(myshortname)) &newvar #length &len(#shortname) &newvar #newname &newvar #valid &newvar #testchar &for #index=1 to #length &set #testchar &mid(#shortname #index 1) &set #valid &instr(1 {0123456789abcdefghijklmnopqrstuvwxyz} #testchar) &ifn #valid > 0 &join #newname #testchar &endif &endfor &setvar myshortname #newname $ End Wolfscript: (1)
And that's a wrap folks.
Note: Shortname may not work in all instances, of that I'm fairly certain, certain unicodes will cause this to barf, so I will probably HAVE to build in player & shortname extraction for this script to work properly in the future. |