Странный баг с торговлей
Posted: 26.12.2012 5:24
Хочу написать простой скрипт, чтобы чар принимал вещи, которые ему дают друзья и клал в банк. Первую вещь он берет и кладет в банк, но в тот момент когда я кидаю на него вторую, Stealth зависает. Что не так?
(upd причина креша найдена, см след пост)
(upd причина креша найдена, см след пост)
Code: Select all
Program Tax_Collector;
const
LogType=$1BDD; // type of logs
GoldType = $0EED; // type of gold coins
DelayBankingInProgress = 3000; // wait for how long between putting different things into the bank box
TaxingLength = 30*60; // collect for 30 minutes
TaxCheckDelay = 5; // how often to check if we have the trade window opened
TradeTimeout = 25; // if the status of that window didn't change during that time interval then dismiss it
TradeDelay = 1000; // how often to check if the trade is confirmed
Mine = 1;
His = 2;
var
FriendList:array of string; // don't be afraid of these people; collect stuff from them
BankID,TakenObjID:cardinal;
TaxCollectingStarted,TradeWindowOpenedAt:Int64;
HisName:string; // name of the taxed char
i,j:integer;
begin
// people we are going to tax
FriendList := ['loser1','loser2','loser3'];
// open the bank box
UOSay('bank');
wait(DelayBankingInProgress);
BankID := ObjAtLayer(BankLayer);
// record the time when we started collecting
TaxCollectingStarted := DateTimeToUnix(Now);
// the colelcting process:
repeat
if IsTrade then
begin
j:=0;
// someone wants to give us something
//for j:=0 to TradeCount-1 do // check all the trade windows
//begin
//if ((not IsTrade) or (not GetTradeOpponent(j)>0)) then Break; // something bad happened, start over
HisName := GetTradeOpponentName(j);
for i:= Low(FriendList) to High(FriendList) do
if (BMSearch(1,Hisname,FriendList[i]) > 0) then
begin
//it's a friend, accept the items:
TradeWindowOpenedAt := DateTimeToUnix(Now);
repeat
if TradeCheck(j,His) then // he confirmed the trade
if not TradeCheck(j,Mine) then ConfirmTrade(j);
wait(TradeDelay);
until ((abs(DateTimeToUnix(Now)-TradeWindowOpenedAt) > TradeTimeOut) or (not IsTrade) or not (GetTradeOpponent(j)>0));
if (IsTrade) then CancelTrade(j);
Break;
end else begin
AddToSystemJournal(HisName+' wants to trade with me, I`ve no idea who it is');
if (IsTrade) then CancelTrade(j);
end;
// break;
//end;
end;
// check if we were given gold:
TakenObjID := FindType(GoldType, Backpack);
while ( TakenObjID > 0) do
begin
MoveItems(BackPack, GoldType, $FFFF, BankID, 0,0,0, DelayBankingInProgress);
TakenObjID := FindType(GoldType, Backpack);
end;
// check if we were given logs:
TakenObjID := FindType(LogType, Backpack);
while ( TakenObjID > 0) do
begin
MoveItems(BackPack, LogType, $FFFF, BankID, 0,0,0, DelayBankingInProgress);
TakenObjID := FindType(LogType, Backpack);
end;
wait(TaxCheckDelay);
until (abs(DateTimeToUnix(Now)-TaxCollectingStarted) > TaxingLength);
end.