How to use new Merchant Handlers?

Here you can post threads specific to the current release of the core (099)

Moderator: POL Developer

Post Reply
Terciob
Master Poster
Posts: 90
Joined: Fri Nov 07, 2008 3:47 am

How to use new Merchant Handlers?

Post by Terciob »

Hi all, i upgrade my svn to 346 and compiled new pol version with this handlers by Austin.
So i followed core-changes and inserted line ScriptedMerchantHandlers=1 on servspecopt.cfg and then bought something from a npc, but, nothing was changed, the item goes to my bag and ev.shoppinglist are <unitillized object>.
May i made something worng?
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Re: How to use new Merchant Handlers?

Post by Austin »

¬_¬

Try an SVN update.. and recompile...
Terciob
Master Poster
Posts: 90
Joined: Fri Nov 07, 2008 3:47 am

Re: How to use new Merchant Handlers?

Post by Terciob »

Thanks for the fast answer Austin, is working now.

SYSEVENT_MERCHANT_BOUGHT is passing nothing into shoppinglist.
Image

SYSEVENT_MERCHANT_SOLD is fine.
The only point to note, inside npc backpack items are into stacks even if item.stackable = 0 and item.splitstackinto not check this and create stack of non stackable item.
To solve this i used:

Code: Select all

if (item.stackable)
	if (amt == item.amount)
		moveitemtocontainer (item, who.backpack);
	else
		item.splitstackinto (who.backpack, amt);
	endif
else
	if (amt == 1)
		moveitemtocontainer (item, who.backpack);
	else
		for i := 1 to amt
			item.splitstackinto (who.backpack, 1);
		endfor
	endif
endif
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Re: How to use new Merchant Handlers?

Post by Austin »

Groovy...

That is correct and why I had to put in item.SplitStack()

Off the top of my head the scripted handler could work something like this (no promises itll compile, its more an idea)

This is if the player bought something from the merchant:

Code: Select all

foreach entry in ( event.shoppinglist )
     if ( entry.item.stackable )
          if ( entry.amount >= entry.item.amount ) // Player bought the whole thing
               MoveItemToContainer(entry.item, player.backpack);
          else
               var sold_item := entry.item.SplitStackInto(player.backpack, entry.amount);
               if ( sold_item.errortext )
                       SendSysMessage(player, "Error placing item in pack ->"+sold_item.errortext);
               endif
          endif
      else
           var i := entry.amount;
           for ( i; i > 0; i-=1 )
                var sold_item := entry.item.SplitStackInto(player.backpack, 1);
                if ( sold_item.errortext )
                       SendSysMessage(player, "Error placing item in pack ->"+sold_item.errortext);
               endif
               Sleepms(2);
           endfor
      endif
      Sleepms(20);
endforeach
Terciob
Master Poster
Posts: 90
Joined: Fri Nov 07, 2008 3:47 am

Re: How to use new Merchant Handlers?

Post by Terciob »

Overall, mine and yours script is pretty similar.
Can you see if MERCHANT_BOUGHT event is working properly for you? as i said, here pass no value in shoppinglist array.
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Re: How to use new Merchant Handlers?

Post by Austin »

Hahaha! I forgot to add one important line. Hold on. :angel: :blush: :oopssign:
Terciob
Master Poster
Posts: 90
Joined: Fri Nov 07, 2008 3:47 am

Re: How to use new Merchant Handlers?

Post by Terciob »

@348 solve the shoppinglist array problem.

A point to note is if npc have a stack with 5 items and i buy all stack at once, script bellow will give to me only 4 because last one return a error "Amount must be less than stack amount." So, to avoid put extra IFs and ELSEs into script, this could be if item.amount == SplitStackInto request amount -> the item is just moved to new container.

Code: Select all

  var i := entry.amount;
           for ( i; i > 0; i-=1 )
                var sold_item := entry.item.SplitStackInto(player.backpack, 1);
           endfor
Another thing i feel is missing a way to stack up itens non stackable because when npc buys items from player, those items will spread out into npc "items to sell" container.
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Re: How to use new Merchant Handlers?

Post by Austin »

Okay. Ill work on this tomorrow a bit.

If amount = stack amount - Return the original item as the new stack.
If amount > stack amount - Return an error
Terciob
Master Poster
Posts: 90
Joined: Fri Nov 07, 2008 3:47 am

Re: How to use new Merchant Handlers?

Post by Terciob »

Thanks, quality in @350 is the same as item.quality?
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Re: How to use new Merchant Handlers?

Post by Austin »

Yeap. Im working on a new crafting system ill release shortly - Really nifty stuff. I've been working on rewriting Mytharria.
351 will have your stack changes. I didn't test them though :P
User avatar
*Edwards
Forum Regular
Posts: 303
Joined: Fri Dec 28, 2007 11:19 pm
Location: Montreal, Canada

Re: How to use new Merchant Handlers?

Post by *Edwards »

Crafting system? Share it with me if you have any chances, I'd be glad to introduce it to the Distro as soon I get a chance, if you're not already doing it.
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Re: How to use new Merchant Handlers?

Post by Austin »

Ill start a new thread for the craft stuff here.
http://forums.polserver.com/viewtopic.p ... 196#p17196

Ive only been building this for about 3 days so far, its preliminary still.
Terciob
Master Poster
Posts: 90
Joined: Fri Nov 07, 2008 3:47 am

Re: How to use new Merchant Handlers?

Post by Terciob »

351 will have your stack changes. I didn't test them though :P
I've tested @351 and the object of original stack return correctly if amt == stack amt, but the stack is not moved to new container or to xyz.
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Re: How to use new Merchant Handlers?

Post by Austin »

352: Fixes further issues identified by TercioB on forums with splitting stacks.

Here is the script I just put together to test it.

Code: Select all

// $Id$
//
//

use uo;
use os;

Unload_Scripts("stacktests");

program TextCommand(user)
	SendSysMessage(user, "Starting with XYZ tests.");
	Sleep(1);
	XYZTests(user);
	
	Sleep(4);
	
	SendSysMessage(user, "Starting container tests.");
	Sleep(1);
	ContainerTests(user);
	
	return 1;
endprogram

function XYZTests(user)
	SendSysMessage(user, "Adding 100 gold to backpack.");
	var stack_a := CreateItemInContainer(user.backpack, "GoldCoin", 100);
	SendSysMessage(user, "Stack_A ->"+stack_a);
	SendSysMessage(user, "Sending 20 to a nearby position.");
	var stack_b := stack_a.SplitStackAt(user.x-1, user.y+1, user.z, user.realm, 20);
	SendSysMessage(user, "Stack_B ->"+stack_b);

	PrintTextAbove(stack_a, "Stack A");
	PrintTextAbove(stack_b, "Stack B");
	
	Sleep(2);
	
	SendSysMessage(user, "Moving remaining gold to another position.");
	var stack_c := stack_a.SplitStackAt(user.x+1, user.y-1, user.z, user.realm, stack_a.amount);
	SendSysMessage(user, "Stack_C ->"+stack_c);
	PrintTextAbove(stack_c, "Stack C");
	
	Sleep(4);
	SendSysMessage(user, "Cleaning up stacks.");
	DestroyItem(stack_a);
	DestroyItem(stack_b);
	DestroyItem(stack_c);
	
	return 1;
endfunction

function ContainerTests(user)
	SendSysMessage(user, "Creating 100 gold at feet.");
	var stack_a := CreateItemAtLocation(user.x, user.y, user.z, "GoldCoin", 100, user.realm);
	SendSysMessage(user, "Stack_A ->"+stack_a);
	SendSysMessage(user, "Sending 20 to your backpack.");
	var stack_b := stack_a.SplitStackInto(user.backpack, 20);
	SendSysMessage(user, "Stack_B ->"+stack_b);

	PrintTextAbove(stack_a, "Stack A");
	PrintTextAbove(stack_b, "Stack B");
	
	Sleep(2);
	
	SendSysMessage(user, "Moving remaining gold to backpack.");
	var stack_c := stack_a.SplitStackInto(user.backpack, stack_a.amount);
	SendSysMessage(user, "Stack_C ->"+stack_c);
	PrintTextAbove(stack_c, "Stack C");
	
	Sleep(4);
	SendSysMessage(user, "Cleaning up stacks.");
	DestroyItem(stack_a);
	DestroyItem(stack_b);
	DestroyItem(stack_c);
	
	return 1;
endfunction
Terciob
Master Poster
Posts: 90
Joined: Fri Nov 07, 2008 3:47 am

Re: How to use new Merchant Handlers?

Post by Terciob »

just reporting, @352 solved the problem :bacondance:.
Post Reply