Forum in READ ONLY mode! All questions and discussions on Discord official server, invite link: https://discord.gg/VxsGzJ7

Странный баг с торговлей

тут можно задать вопрос по скриптингу
Post Reply
sith_apprentice
Neophyte
Neophyte
Posts: 13
Joined: 18.12.2012 5:40

Странный баг с торговлей

Post by sith_apprentice »

Хочу написать простой скрипт, чтобы чар принимал вещи, которые ему дают друзья и клал в банк. Первую вещь он берет и кладет в банк, но в тот момент когда я кидаю на него вторую, Stealth зависает. Что не так?

(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.
Last edited by sith_apprentice on 27.12.2012 21:08, edited 3 times in total.
sith_apprentice
Neophyte
Neophyte
Posts: 13
Joined: 18.12.2012 5:40

Re: Странный баг с торговлей

Post by sith_apprentice »

Как оказалось стелс падал из за

Code: Select all

until ((abs(DateTimeToUnix(Now)-TradeWindowOpenedAt) > TradeTimeOut) or (not IsTrade) or not (GetTradeOpponent(j)>0));
части. Если Trade окно закрыто и вызвать GetTradeOpponent(TradeNum), то после этого стелс крешнется как только на чара перетащить предмет. (Т.е падает не сразу после GetTradeOpponent а только потом)


Если исправить на

Code: Select all

until ((abs(DateTimeToUnix(Now)-TradeWindowOpenedAt) > TradeTimeOut) or (not IsTrade) );


то все работает хорошо
User avatar
Vizit0r
Developer
Developer
Posts: 3958
Joined: 24.03.2005 17:05
Contact:

Re: Странный баг с торговлей

Post by Vizit0r »

занятный баг.
исправлено.
"Пишите код так, как будто сопровождать его будет склонный к насилию психопат, который знает, где вы живете". (с) Макконнелл, "Совершенный код".
sith_apprentice
Neophyte
Neophyte
Posts: 13
Joined: 18.12.2012 5:40

Re: Странный баг с торговлей

Post by sith_apprentice »

У меня еще один странный баг с торговлей -- в некоторых обстоятельствах можно получить флаг IsTrade=True и при этом TradeCount=0 :mrgreen:

Кмк, происходит это так: чар1 хочет дать чару2 вещь, кидает ее на чара2 и открывает трейд окно. Тем временем чар2 решает телепортироваться куда подальше. Вещь падает чару1 в бекпак и он с ней остается. У чара2 теперь этот странный баг (у чара1 вроде нет или я просто не заметила). Остановка скрипта и реконнект не помогают сброситьт IsTrade -- только перезапуск стелса :(
Post Reply