help with $messageSender->sendDealAddItem

Philippines

Moderators: waferbaron, Moderators

Forum rules
This server is currently not maintained and tables folder (including connection info) is outdated. Read the wiki for instructions on how to update those information. Please contribute your updated info. Contact Cozzie to join the team as a regular server supporter.
blue_crim
Noob
Noob
Posts: 12
Joined: 18 Sep 2012, 09:49
Noob?: Yes

help with $messageSender->sendDealAddItem

#1 Post by blue_crim »

Hi, can somebody please tell me what is wrong with the code below?

Basically, I am just trying to create a procedure that will override the autoSell - instead of selling the items (sell = 1 in items_control) to NPC, this will trade them to a defined player. I'm no perl programmer but I do understand some of the program flow, so it led me to the following lines of code. I believe everything's working out smooth except for sendDealAddItem - the problem is it doesn't remove the items from the player inventory after adding them to the deal... any input will be greatly appreciated, thanks :)

Code: Select all

			
$args->{nextItem} = 0 unless $args->{nextItem};
for (my $i = $args->{nextItem}; $i < @{$char->inventory->getItems()}; $i++) {
	my $item = $char->inventory->getItems()->[$i];
	next if $item->{equipped};

	my $control = items_control($item->{name});
	
	if ($control->{sell} && $item->{amount} > $control->{keep}) {
		if ($args->{lastIndex} == $item->{index} && timeOut($timeout{'ai_sellAuto_giveup'})) {
			return;
		} elsif ($args->{lastIndex} != $item->{index}) {
			$timeout{ai_sellAuto_giveup}{time} = time;
		}
						
		undef $args->{done};
		$args->{lastIndex} = $item->{index};
		$messageSender->sendDealAddItem($item->{index}, $item->{amount} - $control->{keep});
		$timeout{ai_dealAuto}{time} = time;
		$args->{nextItem} = $i;
		$args->{'dealAddItemCount'} += 1;
						
		if ($args->{'dealAddItemCount'} == 10) {
			$args->{'dealAddItemMore'} = 1 if ($i < @{$char->inventory->getItems()});
			last;
		}
		#return;
	}
}
EternalHarvest
Developers
Developers
Posts: 1798
Joined: 05 Dec 2008, 05:42
Noob?: Yes

Re: help with $messageSender->sendDealAddItem

#2 Post by EternalHarvest »

I think items are removed from inventory only when the server sends confirmation of the finished deal. Try setting $args->{nextItem} to the next index after adding item to deal, not the current one.
blue_crim
Noob
Noob
Posts: 12
Joined: 18 Sep 2012, 09:49
Noob?: Yes

Re: help with $messageSender->sendDealAddItem

#3 Post by blue_crim »

quick responce :shock: thanks :)

the thing is, the items that I supposedly added to the deal still remains in my inventory even after the final trade... client side I guess, cause they all disappear after relog.

what's weird is that the message when I add item to the deal is:
Image
blue_crim
Noob
Noob
Posts: 12
Joined: 18 Sep 2012, 09:49
Noob?: Yes

Re: help with $messageSender->sendDealAddItem

#4 Post by blue_crim »

ok, I have the answer to my own question :)

seems Misc::dealAddItem($item, $amount) works perfectly :lol: